|
| 1 | +name: Publish release |
| 2 | + |
| 3 | +# Only merged source is executed. Validation of unmerged PRs lives in its own |
| 4 | +# read-only pull_request workflow. This trigger also supports reviewed fork PRs. |
| 5 | +on: |
| 6 | + pull_request_target: |
| 7 | + types: [closed] |
| 8 | + branches: ["main"] |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + pull-requests: read |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: release-publish |
| 16 | + cancel-in-progress: false |
| 17 | + |
| 18 | +env: |
| 19 | + BUNDLE_WITH: maintenance |
| 20 | + RELEASE_PR: ${{ github.event.pull_request.number }} |
| 21 | + |
| 22 | +jobs: |
| 23 | + inspect: |
| 24 | + if: github.event.pull_request.merged == true |
| 25 | + runs-on: ubuntu-latest |
| 26 | + outputs: |
| 27 | + release: ${{ steps.inspect.outputs.release }} |
| 28 | + commit: ${{ steps.inspect.outputs.commit }} |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 |
| 31 | + with: |
| 32 | + fetch-depth: 0 |
| 33 | + persist-credentials: false |
| 34 | + - uses: ruby/setup-ruby@a0102e0972be65f351c307e2d64b9314a57c8073 # v1 |
| 35 | + with: |
| 36 | + ruby-version: "3.4" |
| 37 | + bundler-cache: true |
| 38 | + - id: inspect |
| 39 | + env: |
| 40 | + GH_TOKEN: ${{ github.token }} |
| 41 | + run: bundle exec bake gem:github:release:resolve |
| 42 | + |
| 43 | + publish: |
| 44 | + needs: inspect |
| 45 | + if: needs.inspect.outputs.release == 'true' |
| 46 | + runs-on: ubuntu-latest |
| 47 | + environment: rubygems |
| 48 | + permissions: |
| 49 | + contents: write |
| 50 | + pull-requests: read |
| 51 | + actions: read |
| 52 | + id-token: write |
| 53 | + attestations: write |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 |
| 56 | + with: |
| 57 | + ref: ${{ needs.inspect.outputs.commit }} |
| 58 | + fetch-depth: 0 |
| 59 | + persist-credentials: false |
| 60 | + - uses: ruby/setup-ruby@a0102e0972be65f351c307e2d64b9314a57c8073 # v1 |
| 61 | + with: |
| 62 | + ruby-version: "3.4" |
| 63 | + rubygems: '4.0.21' |
| 64 | + bundler-cache: true |
| 65 | + - name: Build or restore artifact |
| 66 | + id: build |
| 67 | + env: |
| 68 | + GH_TOKEN: ${{ github.token }} |
| 69 | + GEM_SIGNING_KEY: ${{ secrets.GEM_SIGNING_KEY }} |
| 70 | + run: bundle exec bake gem:github:release:build |
| 71 | + - name: Sign RubyGems attestation |
| 72 | + if: steps.build.outputs.restored != 'true' |
| 73 | + env: |
| 74 | + PACKAGE: ${{ steps.build.outputs.package }} |
| 75 | + run: gem exec sigstore-cli:0.2.3 sign "$PACKAGE" --bundle "$PACKAGE.sigstore.json" |
| 76 | + - name: Attest exact source and artifact |
| 77 | + if: steps.build.outputs.restored != 'true' |
| 78 | + id: attest |
| 79 | + uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4 |
| 80 | + with: |
| 81 | + subject-path: ${{ steps.build.outputs.package }} |
| 82 | + predicate-type: https://slsa.dev/provenance/v1 |
| 83 | + predicate-path: pkg/provenance.json |
| 84 | + - name: Retain provenance bundle |
| 85 | + if: steps.build.outputs.restored != 'true' |
| 86 | + env: |
| 87 | + ATTESTATION_BUNDLE: ${{ steps.attest.outputs.bundle-path }} |
| 88 | + run: cp "$ATTESTATION_BUNDLE" pkg/provenance.sigstore.json |
| 89 | + - name: Preserve release before upload |
| 90 | + if: steps.build.outputs.restored != 'true' |
| 91 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 |
| 92 | + with: |
| 93 | + name: ${{ steps.build.outputs.artifact }} |
| 94 | + path: pkg/ |
| 95 | + if-no-files-found: error |
| 96 | + retention-days: 90 |
| 97 | + - uses: rubygems/configure-rubygems-credentials@2a7221c7c44c30ebc68eda38fa25c60b918245c7 |
| 98 | + - name: Verify, publish, and finalize |
| 99 | + env: |
| 100 | + GH_TOKEN: ${{ github.token }} |
| 101 | + run: bundle exec bake gem:github:release:publish |
0 commit comments