Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/202403 deps cli #1520

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions starsky/build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ List<string> GetRuntimesWithoutGeneric()
/// <summary>
/// Link to GeoCli.csproj
/// </summary>
const string GeoCliCsproj = "starskygeocli/starskygeocli.csproj";
const string starskyDependenciesCliCsproj = "starskydependenciescli/starskydependenciescli.csproj";

/// <summary>
/// Npm and node are required for preflight checks and building frontend code
Expand Down Expand Up @@ -318,7 +318,8 @@ void ShowSettingsInfo()
Configuration);
DotnetTestHelper.TestNetCoreGenericCommand(Configuration,
IsUnitTestDisabled());
DotnetGenericHelper.DownloadDependencies(Configuration, GeoCliCsproj,
DotnetGenericHelper.DownloadDependencies(Configuration, starskyDependenciesCliCsproj,
GetRuntimesWithoutGeneric(),
NoDependencies, GenericRuntimeName);
MergeCoverageFiles.Merge(IsUnitTestDisabled());
SonarQube.SonarEnd(IsUnitTestDisabled(), NoSonar);
Expand All @@ -333,7 +334,8 @@ void ShowSettingsInfo()
.Executes(() =>
{
DotnetGenericHelper.DownloadDependencies(Configuration,
"starskygeocli/starskygeocli.csproj", NoDependencies,
"starskydependenciescli/starskydependenciescli.csproj",
GetRuntimesWithoutGeneric(), NoDependencies,
GenericRuntimeName);
DotnetRuntimeSpecificHelper.CopyDependenciesFiles(NoDependencies,
GenericRuntimeName, GetRuntimesWithoutGeneric());
Expand Down
22 changes: 13 additions & 9 deletions starsky/build/helpers/DotnetGenericHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Collections.Generic;
using System.IO;
using build;
using Nuke.Common.ProjectModel;
Expand All @@ -10,9 +10,6 @@

namespace helpers
{
[SuppressMessage("Sonar",
"S6664: Reduce the number of Information logging calls within this code block",
Justification = "Not production code.")]
public static class DotnetGenericHelper
{
/// <summary>
Expand Down Expand Up @@ -47,11 +44,12 @@ public static void BuildNetCoreGenericCommand(Solution solution,
/// Download Exiftool and geo deps
/// </summary>
/// <param name="configuration">is Release</param>
/// <param name="geoCliCsproj">geo.csproj file</param>
/// <param name="dependenciesCliCsproj">dependenciesCli.csproj file</param>
/// <param name="getRuntimesWithoutGeneric">which version are downloaded</param>
/// <param name="noDependencies">skip this step if true (external deps)</param>
/// <param name="genericNetcoreFolder">genericNetcoreFolder</param>
public static void DownloadDependencies(Configuration configuration,
string geoCliCsproj, bool noDependencies,
string dependenciesCliCsproj, List<string> getRuntimesWithoutGeneric, bool noDependencies,
string genericNetcoreFolder)
{
if ( noDependencies )
Expand All @@ -60,6 +58,12 @@ public static void DownloadDependencies(Configuration configuration,
return;
}

if ( getRuntimesWithoutGeneric.Count == 0 )
{
Log.Information("skip deps build due generic build");
return;
}

var genericDepsFullPath =
Path.Combine(BasePath(), genericNetcoreFolder, "dependencies");
Log.Information("genericDepsFullPath: {GenericDepsFullPath}", genericDepsFullPath);
Expand All @@ -69,16 +73,16 @@ public static void DownloadDependencies(Configuration configuration,
Environment.SetEnvironmentVariable("app__DependenciesFolder", genericDepsFullPath);
Log.Information("Next: DownloadDependencies");
Log.Information("Run: {Path}", Path.Combine(
WorkingDirectory.GetSolutionParentFolder(), geoCliCsproj)
WorkingDirectory.GetSolutionParentFolder(), dependenciesCliCsproj)
);

DotNetRun(p => p
.SetConfiguration(configuration)
.EnableNoRestore()
.EnableNoBuild()
.SetApplicationArguments("--runtime linux-x64,win-x64")
.SetApplicationArguments($"--runtime {string.Join(',', getRuntimesWithoutGeneric)}")
.SetProjectFile(Path.Combine(WorkingDirectory.GetSolutionParentFolder(),
geoCliCsproj)));
dependenciesCliCsproj)));
}
catch ( Exception exception )
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System.Runtime.InteropServices;
using starsky.feature.externaldependencies.Interfaces;
using starsky.feature.geolookup.Interfaces;
using starsky.foundation.database.Data;
using starsky.foundation.database.Helpers;
using starsky.foundation.injection;
using starsky.foundation.platform.Helpers;
using starsky.foundation.platform.Interfaces;
using starsky.foundation.platform.Models;
using starsky.foundation.writemeta.Interfaces;

namespace starsky.feature.externaldependencies;

[Service(typeof(IExternalDependenciesService), InjectionLifetime = InjectionLifetime.Scoped)]
public class ExternalDependenciesService : IExternalDependenciesService
{
private readonly IExifToolDownload _exifToolDownload;
private readonly ApplicationDbContext _dbContext;
private readonly IWebLogger _logger;
private readonly AppSettings _appSettings;
private readonly IGeoFileDownload _geoFileDownload;

public ExternalDependenciesService(IExifToolDownload exifToolDownload,
ApplicationDbContext dbContext, IWebLogger logger, AppSettings appSettings,
IGeoFileDownload geoFileDownload)
{
_exifToolDownload = exifToolDownload;
_dbContext = dbContext;
_logger = logger;
_appSettings = appSettings;
_geoFileDownload = geoFileDownload;
}

public async Task SetupAsync(string[] args)
{
await SetupAsync(ArgsHelper.GetRuntime(args));
}

public async Task SetupAsync(List<(OSPlatform?, Architecture?)> currentPlatforms)
{
await RunMigrations.Run(_dbContext, _logger, _appSettings);


if ( currentPlatforms.Count == 0 )
{
currentPlatforms =
[
( PlatformParser.GetCurrentOsPlatform(),
PlatformParser.GetCurrentArchitecture() )
];
}

foreach ( var (osPlatform, _) in currentPlatforms )
{
await _exifToolDownload.DownloadExifTool(osPlatform == OSPlatform.Windows);
}

await _geoFileDownload.DownloadAsync();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace starsky.feature.externaldependencies.Interfaces;

public interface IExternalDependenciesService
{
Task SetupAsync(string[] args);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ProjectGuid>{5783f81c-618c-4971-984e-0e405ab1b609}</ProjectGuid>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>starsky.feature.externaldependencies</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\starsky.feature.geolookup\starsky.feature.geolookup.csproj"/>
<ProjectReference Include="..\starsky.foundation.writemeta\starsky.foundation.writemeta.csproj"/>
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions starsky/starsky.feature.geolookup/Services/GeoFileDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task DownloadAsync()
RemoveFailedDownload();
CreateDependenciesFolder();
const string https = "https://";
const string admin1codesasciiTxt = "admin1CodesASCII.txt";
const string admin1CodesasciiTxt = "admin1CodesASCII.txt";

if ( !_hostStorage.ExistFile(
Path.Combine(_appSettings.DependenciesFolder, CountryName + ".txt")) )
Expand All @@ -59,18 +59,18 @@ await _httpClientHelper.Download(https + MirrorUrl + CountryName + ".zip",
}

if ( !_hostStorage.ExistFile(
Path.Combine(_appSettings.DependenciesFolder, admin1codesasciiTxt)) )
Path.Combine(_appSettings.DependenciesFolder, admin1CodesasciiTxt)) )
{
// code for the second administrative division,
// a county in the US, see file admin2Codes.txt; varchar(80)
var outputFile = Path.Combine(_appSettings.DependenciesFolder,
admin1codesasciiTxt);
admin1CodesasciiTxt);
var baseResult = await _httpClientHelper.Download(https +
BaseUrl + admin1codesasciiTxt, outputFile);
BaseUrl + admin1CodesasciiTxt, outputFile);
if ( !baseResult )
{
await _httpClientHelper.Download(https +
MirrorUrl + admin1codesasciiTxt, outputFile);
MirrorUrl + admin1CodesasciiTxt, outputFile);
}
}
}
Expand Down
Loading
Loading