Skip to content

Commit f3e3a6c

Browse files
committed
chore: add GitHub Actions workflow for automated NuGet package release process
1 parent 8aa5a23 commit f3e3a6c

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Release
2+
3+
# Fires on any v*.*.* tag push (and prerelease suffixes -alpha/-beta/-rc).
4+
# Version comes from Directory.Build.props. Publishes via NuGet Trusted
5+
# Publishing (OIDC — no long-lived API key). Setup steps in docs/RELEASING.md.
6+
on:
7+
push:
8+
tags:
9+
- 'v[0-9]+.[0-9]+.[0-9]+*'
10+
workflow_dispatch:
11+
inputs:
12+
dry_run:
13+
description: "Pack and validate only — skip nuget push"
14+
type: boolean
15+
default: true
16+
17+
jobs:
18+
release:
19+
runs-on: ubuntu-latest
20+
environment: release
21+
permissions:
22+
contents: write # for creating the GitHub Release
23+
id-token: write # required for Trusted Publishing OIDC exchange
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- name: Setup .NET
28+
uses: actions/setup-dotnet@v4
29+
with:
30+
global-json-file: global.json
31+
32+
- name: Restore
33+
run: dotnet restore shelldocs.slnx
34+
35+
- name: Build
36+
run: dotnet build shelldocs.slnx --configuration Release --no-restore
37+
38+
- name: Test
39+
run: dotnet test shelldocs.slnx --configuration Release --no-build --verbosity normal
40+
41+
- name: Pack
42+
run: dotnet pack shelldocs.slnx --configuration Release --no-build --output nupkgs
43+
44+
- name: List produced packages
45+
run: ls -la nupkgs/
46+
47+
# Runs immediately before push — the temp API key is valid only 1 hour.
48+
# `user` is the nuget.org profile name (NOT email, NOT the GH org name),
49+
# kept as a secret so it never lives in the workflow file.
50+
- name: Login to NuGet via Trusted Publishing
51+
if: github.event_name == 'push' || inputs.dry_run == false
52+
id: nuget-login
53+
uses: NuGet/login@v1
54+
with:
55+
user: ${{ secrets.NUGET_USER }}
56+
57+
- name: Push to NuGet
58+
if: github.event_name == 'push' || inputs.dry_run == false
59+
env:
60+
NUGET_API_KEY: ${{ steps.nuget-login.outputs.NUGET_API_KEY }}
61+
run: |
62+
for pkg in nupkgs/*.nupkg; do
63+
echo "Publishing $pkg"
64+
dotnet nuget push "$pkg" \
65+
--api-key "$NUGET_API_KEY" \
66+
--source https://api.nuget.org/v3/index.json \
67+
--skip-duplicate
68+
done
69+
70+
- name: Create GitHub Release
71+
if: github.event_name == 'push'
72+
uses: softprops/action-gh-release@v2
73+
with:
74+
generate_release_notes: true
75+
files: nupkgs/*.nupkg

0 commit comments

Comments
 (0)