From a7d436ced66e2e9f895fbc7911a1f175fd4e2305 Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Fri, 20 Nov 2026 18:18:06 -0500 Subject: [PATCH] Pin actions to commit SHAs A caller pinning the reusable workflow by SHA froze the workflow file but not the actions it uses: `actions/checkout@v7`, `actions/upload-artifact@v7`, and `ruby/setup-ruby@v1`, which is a branch, all moved, and they run in the job that can request a RubyGems token. Pin every external action and reusable workflow in both interfaces and this repository's workflows to the commit of its latest release, with the version as a comment, and let Dependabot propose updates. A spec rejects unpinned references. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011Gr21j6KD4oksnhmZ5u3pr --- .github/dependabot.yml | 6 ++++++ .github/workflows/danger-comment.yml | 2 +- .github/workflows/danger.yml | 2 +- .github/workflows/lint.yml | 4 ++-- .github/workflows/package.yml | 4 ++-- .github/workflows/release-integration.yml | 4 ++-- .github/workflows/release.yml | 10 +++++----- .github/workflows/test.yml | 6 +++--- .spellcheck.txt | 2 ++ AGENTS.md | 2 +- CHANGELOG.md | 1 + DESIGN.md | 2 +- action.yml | 6 +++--- docs/actions/release.md | 2 ++ spec/workflow_interfaces_spec.rb | 16 +++++++++++++--- 15 files changed, 45 insertions(+), 24 deletions(-) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..ca79ca5 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly diff --git a/.github/workflows/danger-comment.yml b/.github/workflows/danger-comment.yml index 1ca5e8c..855da16 100644 --- a/.github/workflows/danger-comment.yml +++ b/.github/workflows/danger-comment.yml @@ -12,6 +12,6 @@ permissions: jobs: comment: - uses: danger/danger-pr-comment/.github/workflows/danger-comment.yml@v0.3.0 + uses: danger/danger-pr-comment/.github/workflows/danger-comment.yml@645e89bcc7be89ee7e8362166110b05cbced8e59 # v0.3.0 with: comment-empty: false diff --git a/.github/workflows/danger.yml b/.github/workflows/danger.yml index af7e68b..2ae564c 100644 --- a/.github/workflows/danger.yml +++ b/.github/workflows/danger.yml @@ -9,7 +9,7 @@ permissions: jobs: danger: - uses: danger/danger-pr-comment/.github/workflows/danger-run.yml@v0.3.0 + uses: danger/danger-pr-comment/.github/workflows/danger-run.yml@645e89bcc7be89ee7e8362166110b05cbced8e59 # v0.3.0 with: ruby-version: '4.0' bundler-cache: true diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 253e8cf..6e67af8 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,10 +12,10 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - - uses: ruby/setup-ruby@v1 + - uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1.343.0 with: ruby-version: '4.0' bundler-cache: true diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index e6c3446..54e7179 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -12,10 +12,10 @@ jobs: package: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - - uses: ruby/setup-ruby@v1 + - uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1.343.0 with: ruby-version: '4.0' bundler-cache: true diff --git a/.github/workflows/release-integration.yml b/.github/workflows/release-integration.yml index 5a16fda..afa0f82 100644 --- a/.github/workflows/release-integration.yml +++ b/.github/workflows/release-integration.yml @@ -20,10 +20,10 @@ jobs: - { ruby: '4.0', suite: workflow } - { ruby: '4.0', suite: consumer } steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - - uses: ruby/setup-ruby@v1 + - uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1.343.0 with: ruby-version: ${{ matrix.entry.ruby }} bundler-cache: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 70b4b29..7c27079 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -87,11 +87,11 @@ jobs: RUBYGEMS_OWNER_ID: ${{ inputs.rubygems-owner }} TZ: ${{ inputs.timezone }} steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 id: checkout with: fetch-depth: 0 - - uses: ruby/setup-ruby@v1 + - uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1.343.0 id: setup_ruby with: ruby-version: ${{ inputs.ruby-version }} @@ -120,11 +120,11 @@ jobs: RUBYGEMS_OWNER_ID: ${{ inputs.rubygems-owner }} TZ: ${{ inputs.timezone }} steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 id: checkout with: fetch-depth: 0 - - uses: ruby/setup-ruby@v1 + - uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1.343.0 id: setup_ruby with: ruby-version: ${{ inputs.ruby-version }} @@ -182,7 +182,7 @@ jobs: run: bundle exec rake release:workflow:checkpoint - name: Preserve Release Artifacts id: preserve_release_artifacts - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: release-gem-${{ env.RELEASE_VERSION }}-${{ github.run_id }}-${{ github.run_attempt }} path: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f55936f..8ef2867 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,10 +18,10 @@ jobs: - { ruby: '3.3' } - { ruby: '4.0' } steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - - uses: ruby/setup-ruby@v1 + - uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1.343.0 with: ruby-version: ${{ matrix.entry.ruby }} bundler-cache: true @@ -33,7 +33,7 @@ jobs: RELEASE_AUTH_MODE: rubygems - name: Send Coverage to Coveralls if: matrix.entry.ruby == '4.0' - uses: coverallsapp/github-action@v2 + uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8 with: github-token: ${{ secrets.GITHUB_TOKEN }} path-to-lcov: coverage/lcov.info diff --git a/.spellcheck.txt b/.spellcheck.txt index 7e3b6b9..68a43ff 100644 --- a/.spellcheck.txt +++ b/.spellcheck.txt @@ -7,6 +7,7 @@ Commonmarker codename customizations dblock +Dependabot ExecutionContext ExecutionProvider gemspec @@ -48,6 +49,7 @@ rulesets RSpec RuboCop RubyGems +SHA strftime subclasses subprocess diff --git a/AGENTS.md b/AGENTS.md index ea93ca6..f150e94 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -12,7 +12,7 @@ Keep orchestration permutations and YAML assertions in focused source specs (`bu Keep semantic releases opt-in. Calculate from reachable released tags, not development versions; persist one immutable decision across processes, preserve it when recording the next version, and never reanalyze during preparation or publication. Preserve manual workflow defaults and publication guards. Semantic consumer fixtures must verify success, publication failure, and empty-release rejection against the installed artifact without real publication. -The root `action.yml` exposes the same Ruby tasks as a composite action. Keep both interfaces consistent without making version-pinned workflows depend on moving action references. Action callers own job permissions, runner, environment, and concurrency. Preserve authentication selection and failure-aware artifact preservation; run installed-artifact consumer CI and `actionlint .github/workflows/*.yml examples/.github/workflows/*.yml` when changing YAML interfaces. +The root `action.yml` exposes the same Ruby tasks as a composite action. Keep both interfaces consistent without making version-pinned workflows depend on moving action references: pin every external action and reusable workflow to a full commit SHA with its version as a trailing comment, never a tag or branch. Action callers own job permissions, runner, environment, and concurrency. Preserve authentication selection and failure-aware artifact preservation; run installed-artifact consumer CI and `actionlint .github/workflows/*.yml examples/.github/workflows/*.yml` when changing YAML interfaces. Run `bundle exec rake` locally for specs and RuboCop before every push, and `bundle exec rake build` for package construction when applicable. Danger checks the changelog in PR CI, not as a routine local command. Document user-visible changes in `CHANGELOG.md`, listing entries within each release chronologically and keeping `- Your contribution here.` as the last entry in the next-release section; keep Markdown paragraphs on one source line. diff --git a/CHANGELOG.md b/CHANGELOG.md index a5e1a20..98ef10c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - [#83](https://github.com/dblock/ruby-gem-release/pull/83): Name Intridea subsections with `sections:`, dropping sections without notes from a release and starting every Next section with all of them - [@dblock](https://github.com/dblock). - [#85](https://github.com/dblock/ruby-gem-release/pull/85): Verify RubyGems Trusted Publishing before every release with a `release:workflow:preflight` task, add a `dry-run` workflow input that runs only that check, and name the token claims in rejected exchanges - [@dblock](https://github.com/dblock). - [#86](https://github.com/dblock/ruby-gem-release/pull/86): Check that the release token can push to the default branch and that no repository rules would reject the release commit or tag before every release - [@dblock](https://github.com/dblock). +- [#88](https://github.com/dblock/ruby-gem-release/pull/88): Pin every action used by the reusable workflow, the composite action, and this repository's workflows to a commit SHA, with Dependabot proposing updates - [@dblock](https://github.com/dblock). - Your contribution here. ## 0.7.0 (2026/11/20) diff --git a/DESIGN.md b/DESIGN.md index f593b4d..da3e00c 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -28,7 +28,7 @@ The checkpoint task commits prepared edits, builds reproducibly, tags locally, a Every release action must be idempotent for the same checkout and inputs, without recovery flags, artifact discovery, restored context, or a completion journal. Tasks reconcile their own outputs; a fresh workflow uses its current checkout and inputs rather than discovering an older unfinished release. Registry publication and Git pushes cannot be atomic together, so both interfaces preserve artifacts before publication for manual inspection. See [rerunning releases](RELEASING.md#verify-and-recover). -Keep both YAML interfaces thin and consistent. The reusable workflow does not depend on a moving composite-action reference: a pinned release must remain independent of later action versions. Composite callers own permissions, runner, environment protection, and concurrency. Commands run with release privileges and must be trusted. +Keep both YAML interfaces thin and consistent. The reusable workflow does not depend on a moving composite-action reference: a pinned release must remain independent of later action versions. Both interfaces, and this repository's own workflows, pin every external action and reusable workflow to a commit SHA with its version as a comment, so a caller that pins a release by SHA also fixes every action that runs with release credentials. Dependabot proposes updates to those pins. Composite callers own permissions, runner, environment protection, and concurrency. Commands run with release privileges and must be trusted. ## Preparation and Artifact Guards diff --git a/action.yml b/action.yml index 7154bf6..f73f854 100644 --- a/action.yml +++ b/action.yml @@ -58,11 +58,11 @@ inputs: runs: using: composite steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 id: checkout with: fetch-depth: 0 - - uses: ruby/setup-ruby@v1 + - uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1.343.0 id: setup_ruby with: ruby-version: ${{ inputs.ruby-version }} @@ -141,7 +141,7 @@ runs: run: bundle exec rake release:workflow:checkpoint - name: Preserve Release Artifacts id: preserve_release_artifacts - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: release-gem-${{ env.RELEASE_VERSION }}-${{ github.run_id }}-${{ github.run_attempt }} path: | diff --git a/docs/actions/release.md b/docs/actions/release.md index 1430956..81fcd7f 100644 --- a/docs/actions/release.md +++ b/docs/actions/release.md @@ -4,6 +4,8 @@ Reference for [`.github/workflows/release.yml`](../../.github/workflows/release. For a step-based interface with caller-owned job settings, see the [Composite Action](action.md). Both interfaces invoke the same Ruby release tasks; the reusable workflow keeps its own runner, environment, permissions contract, and concurrency group. +Every action the workflow uses is pinned to a commit SHA. RubyGems Trusted Publishing accepts any ref of this repository, so pin the `uses:` line in your caller to the commit of a release tag, with the tag in a trailing comment, such as `dblock/ruby-gem-release/.github/workflows/release.yml@ # v0.8.0`. That fixes both this workflow and the actions it runs with release credentials. + ## Inputs Set these under the calling job's `with:` mapping. Only `ruby-version` is required. diff --git a/spec/workflow_interfaces_spec.rb b/spec/workflow_interfaces_spec.rb index 2cb94ce..86f7816 100644 --- a/spec/workflow_interfaces_spec.rb +++ b/spec/workflow_interfaces_spec.rb @@ -8,7 +8,7 @@ RSpec.describe 'Release interface contracts' do shared_examples 'a release interface' do it 'captures after setup, validates before edits, and uses normal failure gating downstream' do - setup = steps.index { |step| step['uses'] == 'ruby/setup-ruby@v1' } + setup = steps.index { |step| step['uses'].to_s.start_with?('ruby/setup-ruby@') } capture = steps.index { |step| step['id'] == 'capture_release_context' } validation = steps.index { |step| step['id'] == 'validate_release' } expect(capture).to be > setup @@ -159,6 +159,16 @@ def run_step(id, directory:, command: '') end end + it 'pins every external action and reusable workflow to a commit with its version as a comment', :aggregate_failures do + references = Dir['.github/workflows/*.yml', 'action.yml'].flat_map do |path| + File.readlines(path).filter_map { |line| [path, line.strip] if line.match?(/\A\s*-?\s*uses:\s/) } + end + expect(references).not_to be_empty + references.reject { |_path, line| line.match?(%r{uses: \./}) }.each do |path, line| + expect(line).to match(%r{\A-?\s*uses: [\w.-]+/[\w./-]+@[0-9a-f]{40} # v\d+(\.\d+)*\z}), "#{path}: #{line}" + end + end + context 'with Danger reporting workflows' do let(:producer) { YAML.load_file('.github/workflows/danger.yml') } let(:commenter) { YAML.load_file('.github/workflows/danger-comment.yml') } @@ -167,7 +177,7 @@ def run_step(id, directory:, command: '') expect(producer.fetch(true).keys).to eq(['pull_request']) expect(producer.fetch('permissions')).to eq('contents' => 'read') job = producer.fetch('jobs').fetch('danger') - expect(job.fetch('uses')).to eq('danger/danger-pr-comment/.github/workflows/danger-run.yml@v0.3.0') + expect(job.fetch('uses')).to eq('danger/danger-pr-comment/.github/workflows/danger-run.yml@645e89bcc7be89ee7e8362166110b05cbced8e59') expect(job.fetch('with')).not_to have_key('danger-args') expect(job).not_to have_key('secrets') end @@ -176,7 +186,7 @@ def run_step(id, directory:, command: '') expect(commenter.fetch(true)).to eq('workflow_run' => { 'workflows' => ['Danger'], 'types' => ['completed'] }) expect(commenter.fetch('permissions')).to eq('actions' => 'read', 'issues' => 'write', 'pull-requests' => 'write') job = commenter.fetch('jobs').fetch('comment') - expect(job).to eq('uses' => 'danger/danger-pr-comment/.github/workflows/danger-comment.yml@v0.3.0', 'with' => { 'comment-empty' => false }) + expect(job).to eq('uses' => 'danger/danger-pr-comment/.github/workflows/danger-comment.yml@645e89bcc7be89ee7e8362166110b05cbced8e59', 'with' => { 'comment-empty' => false }) end end end