Skip to content

Commit

Permalink
Build and push nuget artifacts (#3110)
Browse files Browse the repository at this point in the history
* Build and push nuget artifacts

* Add push nuget workflow job. Refactor magefile to only pack nuget not pack&push

Signed-off-by: Ivan Pavlovic <[email protected]>

* Add setup latest .NET 7 SDK step to pack nuget job

Signed-off-by: Ivan Pavlovic <[email protected]>

---------

Signed-off-by: Ivan Pavlovic <[email protected]>
  • Loading branch information
pavlovic-ivan authored Nov 20, 2023
1 parent e1c7950 commit c7681fb
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 23 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,47 @@ 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: 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:
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/[email protected] -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
23 changes: 23 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 7 additions & 23 deletions magefiles/dotnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c7681fb

Please sign in to comment.