From 228f8e7390353517aa3cc4904754976fb8a7873a Mon Sep 17 00:00:00 2001 From: Ivan Pavlovic Date: Mon, 20 Nov 2023 14:34:20 +0100 Subject: [PATCH 1/2] Build and push nuget artifacts * Add push nuget workflow job. Refactor magefile to only pack nuget not pack&push Signed-off-by: Ivan Pavlovic --- .github/workflows/build.yml | 39 +++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 23 +++++++++++++++++++++ magefiles/dotnet.go | 30 +++++++-------------------- 3 files changed, 69 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5465d1ac1b0..890e06ee1bf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -54,3 +54,42 @@ jobs: with: name: armada-image-tarballs path: /tmp/imgs + + pack-nuget: + runs-on: ubuntu-latest + permissions: {} + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + fetch-tags: true + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + cache: false + + - name: Install Protoc + uses: arduino/setup-protoc@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: '23.3' + + - name: Create release tag + id: create-release-tag + run: echo "release_tag=$(git describe --tags --always --dirty --match='v*' 2> /dev/null | sed 's/^v//')" >> $GITHUB_OUTPUT + + - name: Pack dotnet clients + env: + RELEASE_TAG: ${{ steps.create-release-tag.outputs.release_tag }} + run: go run github.com/magefile/mage@v1.14.0 -v download packNuget + + - name: Save nupkg artifacts + uses: actions/upload-artifact@v3 + with: + name: nupkg-artifacts + path: | + ./bin/client/DotNet/G-Research.Armada.Client.${{ steps.create-release-tag.outputs.release_tag }}.nupkg + ./bin/client/DotNet/ArmadaProject.Io.Client.${{ steps.create-release-tag.outputs.release_tag }}.nupkg \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6ef293ac161..51abf6d4029 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -99,3 +99,26 @@ jobs: secrets: APP_ID: ${{ secrets.APP_ID }} APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }} + + push-nuget: + name: Push nuget clients + needs: validate + runs-on: ubuntu-22.04 + environment: nuget-release + steps: + - name: Setup the latest .NET 7 SDK + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 7.0.x + + - name: Download artifact + run: gh run download ${{ github.event.workflow_run.id }} --repo ${{ github.event.workflow_run.repository.full_name }} --name nupkg-artifacts --dir ./bin/client/DotNet + env: + GH_TOKEN: ${{ github.token }} + + - name: Push nuget clients + env: + TAG: ${{ github.event.workflow_run.head_branch }} + run: | + VERSION=${TAG#v} + dotnet nuget push ./bin/client/DotNet/G-Research.Armada.Client.$VERSION.nupkg ./bin/client/DotNet/ArmadaProject.Io.Client.$VERSION.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json \ No newline at end of file diff --git a/magefiles/dotnet.go b/magefiles/dotnet.go index f7d80b4b655..493a53043a0 100644 --- a/magefiles/dotnet.go +++ b/magefiles/dotnet.go @@ -13,13 +13,11 @@ import ( var ( defaultDotnetDockerImg = "mcr.microsoft.com/dotnet/sdk:3.1.417-buster" releaseTag string - nugetApiKey string useSystemCerts bool ) func initializeDotnetRequirements() { releaseTag = getEnvWithDefault("RELEASE_TAG", "UNKNOWN_TAG") - nugetApiKey = getEnvWithDefault("NUGET_API_KEY", "UNKNOWN_NUGET_API_KEY") } func sslCerts() error { @@ -96,35 +94,21 @@ func Dotnet() error { return nil } -// Pack and push dotnet clients to nuget. Requires RELEASE_TAG and NUGET_API_KEY env vars to be set -func PushNuget() error { +// Pack dotnet clients nuget. Requires RELEASE_TAG env var to be set +func PackNuget() error { mg.Deps(initializeDotnetRequirements, dotnetSetup, Proto) - fmt.Println("Pushing to Nuget...") + fmt.Println("Pack Nuget...") dotnetCmd := dotnetCmd() - push := append(dotnetCmd, "dotnet", "pack", "client/DotNet/Armada.Client/Armada.Client.csproj", "-c", "Release", "-p:PackageVersion="+releaseTag, "-o", "./bin/client/DotNet") - output, err := dockerOutput(push...) + build := append(dotnetCmd, "dotnet", "pack", "client/DotNet/Armada.Client/Armada.Client.csproj", "-c", "Release", "-p:PackageVersion="+releaseTag, "-o", "./bin/client/DotNet") + output, err := dockerOutput(build...) fmt.Println(output) if err != nil { return err } - push = append(dotnetCmd, "dotnet", "nuget", "push", "./bin/client/DotNet/G-Research.Armada.Client."+releaseTag+".nupkg", "-k", nugetApiKey, "-s", "https://api.nuget.org/v3/index.json") - output, err = dockerOutput(push...) - fmt.Println(output) - if err != nil { - return err - } - - push = append(dotnetCmd, "dotnet", "pack", "client/DotNet/ArmadaProject.Io.Client/ArmadaProject.Io.Client.csproj", "-c", "Release", "-p:PackageVersion="+releaseTag, "-o", "./bin/client/DotNet") - output, err = dockerOutput(push...) - fmt.Println(output) - if err != nil { - return err - } - - push = append(dotnetCmd, "dotnet", "nuget", "push", "./bin/client/DotNet/ArmadaProject.Io.Client."+releaseTag+".nupkg", "-k", nugetApiKey, "-s", "https://api.nuget.org/v3/index.json") - output, err = dockerOutput(push...) + build = append(dotnetCmd, "dotnet", "pack", "client/DotNet/ArmadaProject.Io.Client/ArmadaProject.Io.Client.csproj", "-c", "Release", "-p:PackageVersion="+releaseTag, "-o", "./bin/client/DotNet") + output, err = dockerOutput(build...) fmt.Println(output) if err != nil { return err From d4211750220a1a087000643ead23437ef0cfda22 Mon Sep 17 00:00:00 2001 From: Ivan Pavlovic Date: Mon, 20 Nov 2023 14:45:09 +0100 Subject: [PATCH 2/2] Add setup latest .NET 7 SDK step to pack nuget job Signed-off-by: Ivan Pavlovic --- .github/workflows/build.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 890e06ee1bf..60c88729b6d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -65,6 +65,11 @@ jobs: fetch-depth: 0 fetch-tags: true + - name: Setup the latest .NET 7 SDK + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 7.0.x + - name: Set up Go uses: actions/setup-go@v4 with: