diff --git a/.github/workflows/build copy.yml.original b/.github/workflows/build copy.yml.original new file mode 100644 index 0000000..d6729e8 --- /dev/null +++ b/.github/workflows/build copy.yml.original @@ -0,0 +1,30 @@ +name: build +on: + push: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 # get entire git tree, required for nerdbank gitversioning + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push the Docker image + shell: pwsh + run: | + Push-Location src + $version = (nbgv get-version -f json | ConvertFrom-Json).SimpleVersion + Write-Host "Version $version" + Pop-Location + + docker build . --tag ghcr.io/g3rv4/getmoarfediverse:latest --tag "ghcr.io/g3rv4/getmoarfediverse:$version" + docker push ghcr.io/g3rv4/getmoarfediverse:latest + docker push "ghcr.io/g3rv4/getmoarfediverse:$version" diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index ae29174..5275efc 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -4,8 +4,11 @@ on: tags: - v* jobs: - create-windows-artifact: + create-artifact: runs-on: ubuntu-latest + strategy: + matrix: + runtime: [ win-x64, linux-x64 ] steps: - name: Checkout uses: actions/checkout@v3 @@ -13,38 +16,59 @@ jobs: shell: pwsh run: | mkdir output + mkdir artifact $outputPath = Join-Path (Pwd) output $srcPath = Join-Path (Pwd) src - docker run -v "$($outputPath):/var/output" -v "$($srcPath):/var/src" mcr.microsoft.com/dotnet/sdk:6.0.403-alpine3.16 dotnet publish -r win-x64 --self-contained -p:PublishTrimmed=true -c Release /var/src/GetMoarFediverse.csproj -o /var/output - - uses: actions/upload-artifact@v3 - with: - name: GetMoarFediverse.exe - path: output/GetMoarFediverse.exe - create-linux-artifact: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Build Windows artifact - shell: pwsh - run: | - mkdir output - $outputPath = Join-Path (Pwd) output - $srcPath = Join-Path (Pwd) src - docker run -v "$($outputPath):/var/output" -v "$($srcPath):/var/src" mcr.microsoft.com/dotnet/sdk:6.0.403-alpine3.16 dotnet publish -r linux-x64 --self-contained -p:PublishTrimmed=true -c Release /var/src/GetMoarFediverse.csproj -o /var/output + $uid = sh -c 'id -u' + $gid = sh -c 'id -g' + + docker run -v "$($outputPath):/var/output" -v "$($srcPath):/var/src" mcr.microsoft.com/dotnet/sdk:6.0.403-alpine3.16 ash -c "dotnet publish -r ${{ matrix.runtime }} --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -c Release /var/src/GetMoarFediverse.csproj -o /var/output && chown -R $($uid):$($gid) /var/output" + + $tag = '${{ github.event.ref }}'.Replace('refs/tags/', '') + + Push-Location output + chmod +r * + chmod +x GetMoarFediverse || true + + if ('${{ matrix.runtime }}'.StartsWith('win-')) { + Compress-Archive -Path * -DestinationPath "../artifact/GetMoarFediverse_$($tag)_${{ matrix.runtime }}.zip" + } else { + tar -czf ../artifact/GetMoarFediverse_$($tag)_${{ matrix.runtime }}.tgz * + } + - uses: actions/upload-artifact@v3 with: - name: GetMoarFediverse - path: output/GetMoarFediverse + name: ${{ matrix.runtime }} + path: artifact/* + + create-release: + runs-on: ubuntu-latest + needs: [ create-artifact ] + steps: + - uses: actions/download-artifact@master + with: + name: win-x64 + path: artifacts/win-x64 + - uses: actions/download-artifact@master + with: + name: linux-x64 + path: artifacts/linux-x64 + - name: Release + uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 + with: + generate_release_notes: true + fail_on_unmatched_files: true + files: | + artifacts/win-x64/*.zip + artifacts/linux-x64/*.tgz create-docker-image: runs-on: ubuntu-latest + needs: [ create-release ] steps: - name: Checkout uses: actions/checkout@v3 - with: - fetch-depth: 0 # get entire git tree, required for nerdbank gitversioning - name: Login to GitHub Container Registry uses: docker/login-action@v2 with: @@ -54,32 +78,8 @@ jobs: - name: Build and push the Docker image shell: pwsh run: | - Push-Location src - $version = (nbgv get-version -f json | ConvertFrom-Json).SimpleVersion - Write-Host "Version $version" - Pop-Location + $version = '${{ github.event.ref }}'.Replace('refs/tags/', '').Replace('v', '') docker build . --tag ghcr.io/g3rv4/getmoarfediverse:latest --tag "ghcr.io/g3rv4/getmoarfediverse:$version" docker push ghcr.io/g3rv4/getmoarfediverse:latest - docker push "ghcr.io/g3rv4/getmoarfediverse:$version" - - create-release: - runs-on: ubuntu-latest - needs: [ create-windows-artifact, create-linux-artifact ] - steps: - - uses: actions/download-artifact@master - with: - name: GetMoarFediverse - path: artifacts/GetMoarFediverse - - uses: actions/download-artifact@master - with: - name: GetMoarFediverse.exe - path: artifacts/GetMoarFediverse.exe - - name: Release - uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 - with: - generate_release_notes: true - fail_on_unmatched_files: true - files: | - artifacts/GetMoarFediverse - artifacts/GetMoarFediverse.exe \ No newline at end of file + docker push "ghcr.io/g3rv4/getmoarfediverse:$version" \ No newline at end of file diff --git a/.gitignore b/.gitignore index a46452c..dcd7bee 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ obj/ launchSettings.json .idea/ .DS_Store -data/ \ No newline at end of file +data/ +output/ \ No newline at end of file diff --git a/src/Config.cs b/src/Config.cs index c51a648..4ac1dcb 100644 --- a/src/Config.cs +++ b/src/Config.cs @@ -1,5 +1,5 @@ using System.Collections.Immutable; -using Jil; +using System.Text.Json; namespace GetMoarFediverse; @@ -30,8 +30,8 @@ public class Config return; } - var data = JSON.Deserialize(File.ReadAllText(path)); - + var data = JsonSerializer.Deserialize(File.ReadAllText(path), JsonContext.Default.ConfigData); + var importedPath = Path.Join(Path.GetDirectoryName(path), "imported.txt"); var apiKey = string.IsNullOrEmpty(data.FakeRelayApiKey) ? Environment.GetEnvironmentVariable("FAKERELAY_APIKEY") @@ -40,7 +40,7 @@ public class Config Instance = new Config(importedPath, data.FakeRelayUrl, apiKey, data.Tags.ToImmutableArray(), data.ImmutableSites); } - private class ConfigData + public class ConfigData { public string FakeRelayUrl { get; set; } public string? FakeRelayApiKey { get; set; } @@ -55,8 +55,8 @@ public class Config public class InternalSiteData { - public string Host { get; private set; } - public string[]? SiteSpecificTags { get; private set; } + public string Host { get; set; } + public string[]? SiteSpecificTags { get; set; } public SiteData ToSiteData() => new() diff --git a/src/GetMoarFediverse.csproj b/src/GetMoarFediverse.csproj index 0e4d787..40c60dd 100644 --- a/src/GetMoarFediverse.csproj +++ b/src/GetMoarFediverse.csproj @@ -7,8 +7,4 @@ enable - - - - diff --git a/src/JsonContexts.cs b/src/JsonContexts.cs new file mode 100644 index 0000000..ce9aaf3 --- /dev/null +++ b/src/JsonContexts.cs @@ -0,0 +1,14 @@ +using System.Text.Json.Serialization; + +namespace GetMoarFediverse; + +[JsonSerializable(typeof(Config.ConfigData))] +internal partial class JsonContext : JsonSerializerContext +{ +} + +[JsonSerializable(typeof(TagResponse))] +[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +internal partial class CamelCaseJsonContext : JsonSerializerContext +{ +} \ No newline at end of file diff --git a/src/Program.cs b/src/Program.cs index 70b4f5f..6325b72 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -1,8 +1,13 @@ using System.Collections.Concurrent; +using System.Text.Json; using GetMoarFediverse; -using Jil; -Config.Init(Environment.GetEnvironmentVariable("CONFIG_PATH")); +var configPath = Environment.GetEnvironmentVariable("CONFIG_PATH"); +if (args.Length == 1){ + configPath = args[0]; +} + +Config.Init(configPath); var client = new HttpClient(); var authClient = new HttpClient @@ -49,7 +54,7 @@ await Parallel.ForEachAsync(sitesTags, parallelOptions, async (st, _) => } var json = await response.Content.ReadAsStringAsync(); - var data = JSON.Deserialize(json, Options.CamelCase); + var data = JsonSerializer.Deserialize(json, CamelCaseJsonContext.Default.TagResponse); foreach (var statusLink in data.OrderedItems.Where(i=>!imported.Contains(i))) { @@ -87,5 +92,5 @@ File.WriteAllLines(importedPath, importedList); public class TagResponse { - public string[] OrderedItems { get; private set; } + public string[] OrderedItems { get; set; } } \ No newline at end of file