Sub topic 2
Keeping GitHub Actions Pins Readable and Enforced
Assume you know basic workflow syntax, Git commits and tags, and the difference between a version tag and a commit SHA. A full-length SHA gives a workflow an exact commit, but it is difficult to recognize later. A version comment keeps the reference readable without changing what GitHub executes.
Add a version comment
Put the human-readable release after the SHA:
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-node@1e60f620b9541dca9c8c0f3c6d3c4b3e4e1b8f70 # v4.0.3The SHA is the security-relevant value. The comment is documentation for reviewers and update tools. Review the SHA when changing the comment. A comment that says # v4.2.2 does not prove that the SHA belongs to that release.
Update pins with Dependabot
Dependabot can inspect GitHub Actions references and open pull requests for newer releases. Add this file at .github/dependabot.yml:
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"A pull request should show both the new SHA and its version comment. Review the action's release and changes before merging. Dependabot keeps pins current, but it does not replace release review.
Require full-length SHAs by policy
Repository administrators can open Settings > Actions > General and configure the action policy to require actions to use full-length commit SHAs. An organization administrator can apply the same restriction at the organization level, limiting what repositories may allow.
Policy enforcement prevents new workflow changes from using tags or branches, but it does not decide whether a commit is trustworthy. Review the repository, release, and requested permissions separately.
Nested actions remain a separate risk
Pinning a top-level action does not pin actions that it calls internally. A composite action can contain its own uses: steps. A reusable workflow can call other actions or reusable workflows. Those references may still use mutable tags.
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: ./.github/actions/setup-toolsInspect trusted composite actions and reusable workflows, or use a lockfile tool that records direct and transitive references.
Exercise
What does the version comment change, and what does it not change?
Show answer
It improves readability for humans. GitHub still runs the commit identified by the full SHA, regardless of the comment.