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
36 changes: 35 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ jobs:
(inputs.publish_tag != '' || needs.release.outputs.release_created == 'true')
runs-on: { group: github-public-amd64 }
timeout-minutes: 20
# The NuGet Trusted Publishing token is minted in this job. The environment is where its
# reviewers and deployment branches are enforced, and the Trusted Publishing policy on
# nuget.org can pin it, so a workflow on any other branch cannot mint a usable token.
environment: nuget
permissions:
contents: write
id-token: write
Expand All @@ -229,11 +233,41 @@ jobs:

- uses: actions/checkout@v4
with:
ref: ${{ steps.target.outputs.tag }}
# refs/tags/ so that a publish_tag naming a branch or a SHA is not checked out.
ref: refs/tags/${{ steps.target.outputs.tag }}
# Full history, for the ancestry check below.
fetch-depth: 0
# dotnet pack runs project code, and nothing here writes to the repository,
# so do not leave GITHUB_TOKEN in .git/config.
persist-credentials: false

# publish_tag is free text, so without this any tag, including one pushed on a commit
# that was never reviewed, could be published. Only publish a tag whose commit is
# already on the release branch this run belongs to.
- name: Verify the tag is on this release branch
env:
TAG: ${{ steps.target.outputs.tag }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
# The environment's deployment branches are what enforce this; the check here only
# gives a clear error before they are configured.
if [ "$GITHUB_REF" != "refs/heads/${DEFAULT_BRANCH}" ] && [[ ! "$GITHUB_REF" =~ ^refs/heads/[0-9]+(\.[0-9]+)*\.x$ ]]; then
echo "::error::Publishing runs only from ${DEFAULT_BRANCH} or an N.x release branch, not ${GITHUB_REF}."
exit 1
fi
# Exactly a tag. Revision syntax such as v1.2.3~1 would otherwise resolve to a commit
# that was never tagged.
if ! git show-ref --verify --quiet "refs/tags/${TAG}"; then
echo "::error::${TAG} is not a tag of this repository."
exit 1
fi
commit="$(git rev-parse "refs/tags/${TAG}^{commit}")"
if ! git merge-base --is-ancestor "$commit" "$GITHUB_SHA"; then
echo "::error::Tag ${TAG} points at ${commit}, which is not on ${GITHUB_REF_NAME}. Dispatch the workflow from the branch that release was cut from."
exit 1
fi
echo "Tag ${TAG} (${commit}) is on ${GITHUB_REF_NAME}."

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
Expand Down
Loading