|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + paths: |
| 9 | + - lib/hooks/version.rb |
| 10 | + |
| 11 | +permissions: {} |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + if: github.repository == 'github/hooks' |
| 16 | + permissions: |
| 17 | + contents: read |
| 18 | + runs-on: ubuntu-latest |
| 19 | + outputs: |
| 20 | + artifact-id: ${{ steps.upload-artifact.outputs.artifact-id }} |
| 21 | + gem_name: ${{ steps.build.outputs.gem_name }} |
| 22 | + gem_version: ${{ steps.build.outputs.gem_version }} |
| 23 | + gem_path: ${{ steps.build.outputs.gem_path }} |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: checkout |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + persist-credentials: false |
| 30 | + |
| 31 | + - uses: ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # [email protected] |
| 32 | + with: |
| 33 | + bundler-cache: false |
| 34 | + |
| 35 | + - name: bootstrap |
| 36 | + run: script/bootstrap |
| 37 | + |
| 38 | + # IMPORTANT: this step MUST export for the following outputs: |
| 39 | + # gem_name: the name of the gem - ex: "my-cool-gem" |
| 40 | + # gem_version: the version of the gem - ex: "1.0.0" |
| 41 | + # gem_path: the path/filename of the gem - ex: "my-cool-gem-1.0.0.gem" |
| 42 | + - name: build |
| 43 | + id: build |
| 44 | + run: script/build |
| 45 | + |
| 46 | + - name: upload artifact |
| 47 | + |
| 48 | + id: upload-artifact |
| 49 | + with: |
| 50 | + path: "${{ steps.build.outputs.gem_path }}" |
| 51 | + |
| 52 | + release: |
| 53 | + needs: build |
| 54 | + environment: release |
| 55 | + runs-on: ubuntu-latest |
| 56 | + permissions: |
| 57 | + contents: write |
| 58 | + packages: write |
| 59 | + id-token: write |
| 60 | + steps: |
| 61 | + - uses: actions/checkout@v4 |
| 62 | + with: |
| 63 | + persist-credentials: false |
| 64 | + |
| 65 | + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 |
| 66 | + with: |
| 67 | + artifact-ids: ${{ needs.build.outputs.artifact-id }} |
| 68 | + |
| 69 | + - name: Publish to GitHub Packages |
| 70 | + env: |
| 71 | + OWNER: ${{ github.repository_owner }} |
| 72 | + GEM_NAME: ${{ needs.build.outputs.gem_name }} |
| 73 | + GEM_VERSION: ${{ needs.build.outputs.gem_version }} |
| 74 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + ARTIFACT_PATH: "artifact" |
| 76 | + run: | |
| 77 | + GEM_HOST_API_KEY=${GITHUB_TOKEN} gem push --key github --host https://rubygems.pkg.github.com/${OWNER} $ARTIFACT_PATH/${GEM_NAME}-${GEM_VERSION}.gem |
| 78 | +
|
| 79 | + - uses: ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # [email protected] |
| 80 | + with: |
| 81 | + bundler-cache: false |
| 82 | + |
| 83 | + - name: bootstrap |
| 84 | + run: script/bootstrap |
| 85 | + |
| 86 | + - name: Configure RubyGems Credentials |
| 87 | + uses: rubygems/configure-rubygems-credentials@e3f5097339179e0d4c7321ab44209e7e02446746 # pin@main |
| 88 | + |
| 89 | + - name: sign ruby gem |
| 90 | + env: |
| 91 | + GEM_NAME: ${{ needs.build.outputs.gem_name }} |
| 92 | + GEM_VERSION: ${{ needs.build.outputs.gem_version }} |
| 93 | + ARTIFACT_PATH: "artifact" |
| 94 | + run: bundle exec sigstore-cli sign ${ARTIFACT_PATH}/${GEM_NAME}-${GEM_VERSION}.gem --bundle ${GEM_NAME}-${GEM_VERSION}.sigstore.json |
| 95 | + |
| 96 | + - name: Publish to RubyGems |
| 97 | + env: |
| 98 | + GEM_NAME: ${{ needs.build.outputs.gem_name }} |
| 99 | + GEM_VERSION: ${{ needs.build.outputs.gem_version }} |
| 100 | + ARTIFACT_PATH: "artifact" |
| 101 | + run: gem push ${ARTIFACT_PATH}/${GEM_NAME}-${GEM_VERSION}.gem --attestation ${GEM_NAME}-${GEM_VERSION}.sigstore.json |
| 102 | + |
| 103 | + - name: await gem |
| 104 | + env: |
| 105 | + GEM_NAME: ${{ needs.build.outputs.gem_name }} |
| 106 | + GEM_VERSION: ${{ needs.build.outputs.gem_version }} |
| 107 | + run: bundle exec rubygems-await "${GEM_NAME}:${GEM_VERSION}" --timeout 120 |
| 108 | + |
| 109 | + - name: GitHub Release |
| 110 | + env: |
| 111 | + GEM_NAME: ${{ needs.build.outputs.gem_name }} |
| 112 | + GEM_VERSION: ${{ needs.build.outputs.gem_version }} |
| 113 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 114 | + ARTIFACT_PATH: "artifact" |
| 115 | + run: | |
| 116 | + gh release create "v${GEM_VERSION}" \ |
| 117 | + "${ARTIFACT_PATH}/${GEM_NAME}-${GEM_VERSION}.gem" \ |
| 118 | + "${GEM_NAME}-${GEM_VERSION}.sigstore.json" \ |
| 119 | + --title "v${GEM_VERSION}" \ |
| 120 | + --generate-notes |
| 121 | +
|
| 122 | + sign: |
| 123 | + needs: [build, release] |
| 124 | + runs-on: ubuntu-latest |
| 125 | + permissions: |
| 126 | + id-token: write |
| 127 | + attestations: write |
| 128 | + contents: read |
| 129 | + |
| 130 | + steps: |
| 131 | + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 |
| 132 | + with: |
| 133 | + artifact-ids: ${{ needs.build.outputs.artifact-id }} |
| 134 | + |
| 135 | + - name: attest build provenance |
| 136 | + |
| 137 | + with: |
| 138 | + subject-path: "artifact/${{ needs.build.outputs.gem_path }}" |
| 139 | + |
| 140 | + verify: |
| 141 | + permissions: {} |
| 142 | + needs: [build, release, sign] |
| 143 | + runs-on: ubuntu-latest |
| 144 | + |
| 145 | + steps: |
| 146 | + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 |
| 147 | + with: |
| 148 | + artifact-ids: ${{ needs.build.outputs.artifact-id }} |
| 149 | + |
| 150 | + - name: verify |
| 151 | + env: |
| 152 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 153 | + OWNER: ${{ github.repository_owner }} |
| 154 | + REPO: ${{ github.event.repository.name }} |
| 155 | + ARTIFACT_PATH: "artifact/${{ needs.build.outputs.gem_path }}" |
| 156 | + run: gh attestation verify "$ARTIFACT_PATH" --repo ${OWNER}/${REPO} --signer-workflow ${OWNER}/${REPO}/.github/workflows/release.yml |
0 commit comments