Skip to content

Commit 10503e5

Browse files
committed
ci: trigger NuGet release from GitHub Release event
Previously the release workflow ran on every push to main and auto-published whenever version.txt changed. This meant any merged PR that bumped the version would immediately push a NuGet package with no human gate. Switch the trigger to the GitHub Release published event so publishing requires an explicit action: creating and publishing a GitHub Release (which also creates the tag). A validation step ensures the tag matches version.txt before anything is pushed to NuGet. Drop contents:write permission since the workflow no longer creates tags.
1 parent 5004fc2 commit 10503e5

1 file changed

Lines changed: 14 additions & 29 deletions

File tree

.github/workflows/release.yml

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
name: Release
22

33
on:
4-
push:
5-
branches:
6-
- main
4+
release:
5+
types:
6+
- published
77

8-
permissions:
9-
contents: write
8+
permissions: {}
109

1110
jobs:
1211
nuget:
@@ -16,42 +15,28 @@ jobs:
1615
- name: Checkout
1716
uses: actions/checkout@v4
1817

19-
- id: tag
20-
name: Determine tag
18+
- name: Validate tag
2119
run: |
22-
version="$(head -n 1 version.txt)"
23-
ref_name="v$version"
24-
create=true
25-
if [ "$(git ls-remote origin "refs/tags/$ref_name" | wc -l)" = "1" ]; then
26-
create=false
20+
tag="${GITHUB_REF_NAME}"
21+
version="${tag#v}"
22+
file_version="$(head -n 1 version.txt)"
23+
if [ "$version" != "$file_version" ]; then
24+
echo "::error::Tag version ($version) does not match version.txt ($file_version)"
25+
exit 1
2726
fi
2827
29-
echo "version=$version" | tee -a "$GITHUB_OUTPUT"
30-
echo "ref-name=$ref_name" | tee -a "$GITHUB_OUTPUT"
31-
echo "create=$create" | tee -a "$GITHUB_OUTPUT"
32-
33-
- if: ${{ fromJSON(steps.tag.outputs.create) }}
34-
name: Setup dotnet
28+
- name: Setup dotnet
3529
uses: actions/setup-dotnet@v4
3630
with:
3731
dotnet-version: '10.x'
3832

39-
- if: ${{ fromJSON(steps.tag.outputs.create) }}
40-
name: Pack
33+
- name: Pack
4134
# https://learn.microsoft.com/en-us/nuget/create-packages/symbol-packages-snupkg
4235
# https://devblogs.microsoft.com/dotnet/producing-packages-with-source-link/
4336
run: dotnet pack -c Release -o dist -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg -p:ContinuousIntegrationBuild=true
4437

45-
- if: ${{ fromJSON(steps.tag.outputs.create) }}
46-
name: Push
38+
- name: Push
4739
run: |
4840
cd dist
4941
ls -lh
50-
# this should upload snupkgs in the same folder
5142
dotnet nuget push *.nupkg -s https://api.nuget.org/v3/index.json -k "${{ secrets.NUGET_API_KEY }}" --skip-duplicate
52-
53-
- if: ${{ fromJSON(steps.tag.outputs.create) }}
54-
name: Tag
55-
run: |
56-
git tag "${{ steps.tag.outputs.ref-name }}"
57-
git push origin "${{ steps.tag.outputs.ref-name }}"

0 commit comments

Comments
 (0)