|
| 1 | +name: Publish release |
| 2 | + |
| 3 | +# Inspect the exact pushed commit and publish only a validated, merged release PR. |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: ["main"] |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + pull-requests: read |
| 11 | + |
| 12 | +env: |
| 13 | + BUNDLE_WITH: maintenance |
| 14 | + |
| 15 | +jobs: |
| 16 | + inspect: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + release: ${{ steps.inspect.outputs.release }} |
| 20 | + commit: ${{ steps.inspect.outputs.commit }} |
| 21 | + pull_request: ${{ steps.inspect.outputs.pull_request }} |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v7 |
| 24 | + with: |
| 25 | + ref: ${{ github.sha }} |
| 26 | + fetch-depth: 0 |
| 27 | + persist-credentials: false |
| 28 | + - uses: ruby/setup-ruby@v1 |
| 29 | + with: |
| 30 | + ruby-version: "3.4" |
| 31 | + bundler-cache: true |
| 32 | + - id: inspect |
| 33 | + env: |
| 34 | + GITHUB_TOKEN: ${{ github.token }} |
| 35 | + RELEASE_COMMIT: ${{ github.sha }} |
| 36 | + run: bundle exec bake gem:github:release:resolve |
| 37 | + |
| 38 | + publish: |
| 39 | + needs: inspect |
| 40 | + if: needs.inspect.outputs.release == 'true' |
| 41 | + runs-on: ubuntu-latest |
| 42 | + environment: rubygems |
| 43 | + concurrency: |
| 44 | + group: release-publish |
| 45 | + cancel-in-progress: false |
| 46 | + queue: max |
| 47 | + env: |
| 48 | + RELEASE_PR: ${{ needs.inspect.outputs.pull_request }} |
| 49 | + permissions: |
| 50 | + contents: write |
| 51 | + pull-requests: read |
| 52 | + actions: read |
| 53 | + id-token: write |
| 54 | + attestations: write |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@v7 |
| 57 | + with: |
| 58 | + # Inspection verified this merged commit belongs to the default branch. |
| 59 | + ref: ${{ needs.inspect.outputs.commit }} |
| 60 | + fetch-depth: 0 |
| 61 | + persist-credentials: false |
| 62 | + - uses: ruby/setup-ruby@v1 |
| 63 | + with: |
| 64 | + ruby-version: "3.4" |
| 65 | + rubygems: '4.0.21' |
| 66 | + bundler-cache: true |
| 67 | + - name: Build or restore artifact |
| 68 | + id: build |
| 69 | + env: |
| 70 | + GITHUB_TOKEN: ${{ github.token }} |
| 71 | + run: bundle exec bake gem:github:release:build |
| 72 | + - name: Sign RubyGems attestation |
| 73 | + if: steps.build.outputs.restored != 'true' |
| 74 | + env: |
| 75 | + PACKAGE: ${{ steps.build.outputs.package }} |
| 76 | + run: gem exec sigstore-cli:0.2.3 sign "$PACKAGE" --bundle "$PACKAGE.sigstore.json" |
| 77 | + - name: Attest gem and release receipt |
| 78 | + if: steps.build.outputs.restored != 'true' |
| 79 | + id: attest |
| 80 | + uses: actions/attest@v4 |
| 81 | + with: |
| 82 | + subject-path: | |
| 83 | + ${{ steps.build.outputs.package }} |
| 84 | + pkg/release.json |
| 85 | + - name: Retain provenance bundle |
| 86 | + if: steps.build.outputs.restored != 'true' |
| 87 | + env: |
| 88 | + ATTESTATION_BUNDLE: ${{ steps.attest.outputs.bundle-path }} |
| 89 | + run: cp "$ATTESTATION_BUNDLE" pkg/provenance.sigstore.json |
| 90 | + - name: Preserve release before upload |
| 91 | + if: steps.build.outputs.restored != 'true' |
| 92 | + uses: actions/upload-artifact@v7 |
| 93 | + with: |
| 94 | + name: ${{ steps.build.outputs.artifact }} |
| 95 | + path: pkg/ |
| 96 | + if-no-files-found: error |
| 97 | + retention-days: 90 |
| 98 | + - uses: rubygems/configure-rubygems-credentials@main |
| 99 | + - name: Verify, publish, and finalize |
| 100 | + env: |
| 101 | + GITHUB_TOKEN: ${{ github.token }} |
| 102 | + run: bundle exec bake gem:github:release:publish |
0 commit comments