Skip to content
Merged
Show file tree
Hide file tree
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
31 changes: 9 additions & 22 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ on:
tags:
- 'v*'

# Write access asked for here rather than a PAT. The organisation's default
# token is read-only, but a workflow may ask for more, and Fellowship's release
# job does exactly that. GitHub Packages accepts GITHUB_TOKEN with
# packages: write for a package owned by this repository, so freedom-sharp needs
# no PACKAGES_TOKEN secret — integrity-sharp's arrangement predates this.
permissions:
contents: read # enough for checkout; publishing does not use this token
contents: write # the GitHub Release
packages: write # the NuGet push

jobs:
release:
Expand All @@ -37,25 +43,6 @@ jobs:
*) echo "prerelease=false" >> "$GITHUB_OUTPUT" ;;
esac

# The org makes GITHUB_TOKEN read-only, so publishing needs a PAT. Checked
# up front so a missing or expired one fails in seconds, not after a build.
- name: Check publishing credentials
env:
PACKAGES_TOKEN: ${{ secrets.PACKAGES_TOKEN }}
run: |
if [ -z "$PACKAGES_TOKEN" ]; then
echo "::error::Secret PACKAGES_TOKEN is not set. Create a classic PAT with the 'repo' and 'write:packages' scopes and add it as a repository secret named PACKAGES_TOKEN."
exit 1
fi
code=$(curl -sS -o /dev/null -w '%{http_code}' \
-u "${{ github.repository_owner }}:$PACKAGES_TOKEN" \
https://nuget.pkg.github.com/${{ github.repository_owner }}/download/freedom.client/index.json)
case "$code" in
200|404) echo "PACKAGES_TOKEN authenticates OK (HTTP $code)" ;;
401|403) echo "::error::PACKAGES_TOKEN was rejected (HTTP $code) — expired, revoked, or missing the write:packages scope."; exit 1 ;;
*) echo "::warning::Unexpected HTTP $code probing GitHub Packages; continuing and letting the push report the outcome." ;;
esac

- name: Setup Java
uses: actions/setup-java@dd06d9cba3e5552c54d9f8ea23572deb30010f7c # v6.0.0
with:
Expand Down Expand Up @@ -92,12 +79,12 @@ jobs:
run: >
dotnet nuget push "artifacts/*.nupkg"
--source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
--api-key ${{ secrets.PACKAGES_TOKEN }}
--api-key ${{ secrets.GITHUB_TOKEN }}
--skip-duplicate

- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.PACKAGES_TOKEN }}
GH_TOKEN: ${{ github.token }}
run: >
gh release create "$GITHUB_REF_NAME"
artifacts/*.nupkg
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,10 @@ Releases are integrity-sharp's:
- The tag runs `release.yml`, which re-runs the gates and publishes
**Freedom.Client** and **Freedom.Client.Maui** to GitHub Packages and a
GitHub Release.
- It needs a `PACKAGES_TOKEN` secret: a classic PAT with `repo` and
`write:packages`. The organisation makes `GITHUB_TOKEN` read-only.
- It publishes with the workflow's own `GITHUB_TOKEN`, which asks for
`packages: write` and `contents: write`, so there is no PAT to keep
alive. integrity-sharp still uses a `PACKAGES_TOKEN` secret; that
arrangement predates this one.

To install, add the GitHub Packages feed to `nuget.config` with a token
that has `read:packages`, then reference `Freedom.Client.Maui` (it brings
Expand Down
Loading