Skip to content
Merged
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
45 changes: 33 additions & 12 deletions .github/workflows/ci-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ name: CI / Build and Publish

on:
push:
branches: [ master ]
tags: # publishing will only occur for version tags like v1.2.3
branches:
- master
tags:
- 'v*'

pull_request:
branches: [ master ]
branches:
- master

jobs:
build-and-publish:
runs-on: ubuntu-latest

permissions:
contents: read
id-token: write
Expand All @@ -22,7 +26,7 @@ jobs:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

Expand All @@ -35,22 +39,39 @@ jobs:
- name: Test
run: dotnet test --configuration Release --no-build --verbosity normal

# Only create the NuGet package when a version tag is pushed
- name: Pack SlaCore
if: startsWith(github.ref, 'refs/tags/v')
shell: bash
run: |
VERSION="${GITHUB_REF_NAME#v}"

echo "Packing SlaCore version $VERSION"

mkdir -p artifacts
dotnet pack src/SlaCore/SlaCore.csproj -c Release -o ./artifacts /p:PackageVersion=1.0.${{ github.run_number }}

# Publish to NuGet when a tag is pushed (e.g. v1.0.0)
- name: NuGet login (OIDC 10 temp API key)
if: startsWith(github.ref, 'refs/tags/')
dotnet pack src/SlaCore/SlaCore.csproj \
--configuration Release \
--no-build \
--output ./artifacts \
/p:PackageVersion=$VERSION

# Exchange GitHub OIDC token for a temporary NuGet API key
- name: NuGet login
if: startsWith(github.ref, 'refs/tags/v')
uses: NuGet/login@v1
id: login
with:
user: ${{ secrets.NUGET_USER }}

- name: NuGet push
if: startsWith(github.ref, 'refs/tags/')
# Publish to NuGet.org
- name: Publish to NuGet.org
if: startsWith(github.ref, 'refs/tags/v')
run: |
echo "Packages in artifacts:"
echo "Publishing packages:"
ls -la artifacts
dotnet nuget push "artifacts/*.nupkg" --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate

dotnet nuget push "artifacts/*.nupkg" \
--api-key "${{ steps.login.outputs.NUGET_API_KEY }}" \
--source "https://api.nuget.org/v3/index.json" \
--skip-duplicate
Loading