Use pull request safe git_ref and git_commit in GitHub Actions examples - #3462
Merged
Merged
Conversation
On a pull_request event, github.ref is refs/pull/<number>/merge and github.sha is the merge commit GitHub creates for the pull request. That commit is not reachable from any branch or tag, so an Octopus release pinned to it can fail to deploy later. Switch the three create-release examples to github.head_ref and github.event.pull_request.head.sha, which fall back to the push values on every other event, and add a note explaining why. Also fix github.event.push.after on the build server plugin page. A push payload exposes the commit as github.event.after, so the old expression was always empty on a push.
|
Pull request environment is available at https://stoctodocspr3462.z22.web.core.windows.net/. You can view the ephemeral environment status in Octopus Deploy. This environment will be automatically deprovisioned when the pull request is closed, or after 7 days of inactivity. |
zentron
commented
Sep 15, 2026
zentron
left a comment
Contributor
Author
There was a problem hiding this comment.
Updating our docs around GitHub references to use for CaC projects
geofflamrock
approved these changes
Sep 15, 2026
MD060 requires table pipes to align with the header. The longer git_ref and git_commit descriptions pushed those two rows past the width of the rest of the table. The hint above the table already explains the pull request behavior, so revert the two cells.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
As noted in an old CaC document, the GitHub variables available during a GitHub Action differ between some of he events.
On a
pull_requestevent those two values arerefs/pull/<number>/mergeand the merge commit GitHub creates for the pull request. That commit is not reachable from any branch or tag, so the release is pinned to a commit that Octopus can later fail to resolve. It also disagrees with what the workflow actually built, because a build normally checks out the branch head.The Creating releases from a build server plugin page already warns about this but isn't completely accurate. The GitHub Actions page did not, and its examples are the ones people copy.
Without this specific configuration, a CaC deployment can fail as the branch specified with just
github.refmay reference the merge branch that is removed post-merge.E.g the error we see is along the lines of
GitHub Variables
Commit Sha
pull_request: A temporary
Ref
Results
github-actions.mdxgit_ref: ${{ github.head_ref || github.ref }}andgit_commit: ${{ github.event.pull_request.head.sha || github.sha }}. Both expressions fall back to the push values on every other event, so the examples still work unchanged forworkflow_dispatch,push, andschedule.git_refandgit_commitinput descriptions to say the same thing in the table.creating-release-from-a-build-server-plug-in.mdx${{ github.event.push.after || github.event.pull_request.head.sha }}, but a push payload exposes the commit asgithub.event.after, sogithub.event.push.afterwas always empty and a push fell through to the pull request value. It now reads${{ github.event.pull_request.head.sha || github.sha }}.Testing
Documentation only, no code changes. Both files render as MDX with existing syntax, and the hint uses the same
:::div{.hint}block already used on the TeamCity page.Verified the underlying claim against the live GitHub API for the pull request in the original report. The merge commit exists only on
refs/pull/282/merge, and the branch head is a different commit.🤖 Generated with Claude Code