|
1 | | -name: "Release" |
| 1 | +--- |
| 2 | +name: Gem Release |
2 | 3 |
|
3 | 4 | on: |
4 | | - workflow_dispatch: |
5 | | - inputs: |
6 | | - target: |
7 | | - description: "The target for the release. This can be a commit sha or a branch." |
8 | | - required: false |
9 | | - default: "main" |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - '*' |
10 | 8 |
|
11 | 9 | jobs: |
12 | | - release: |
13 | | - uses: "puppetlabs/cat-github-actions/.github/workflows/gem_release.yml@main" |
14 | | - with: |
15 | | - target: "${{ github.event.inputs.target }}" |
16 | | - secrets: "inherit" |
| 10 | + build-release: |
| 11 | + # Prevent releases from forked repositories |
| 12 | + if: github.repository_owner == 'voxpupuli' |
| 13 | + name: Build the gem |
| 14 | + runs-on: ubuntu-24.04 |
| 15 | + permissions: |
| 16 | + contents: write # clone repo and create release |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + - name: Install Ruby |
| 20 | + uses: ruby/setup-ruby@v1 |
| 21 | + with: |
| 22 | + ruby-version: 'ruby' |
| 23 | + - name: Build gem |
| 24 | + shell: bash |
| 25 | + run: gem build --verbose *.gemspec |
| 26 | + - name: Upload gem to GitHub cache |
| 27 | + uses: actions/upload-artifact@v4 |
| 28 | + with: |
| 29 | + name: gem-artifact |
| 30 | + path: '*.gem' |
| 31 | + retention-days: 1 |
| 32 | + compression-level: 0 |
| 33 | + - name: Create Release Page |
| 34 | + shell: bash |
| 35 | + env: |
| 36 | + GH_TOKEN: ${{ github.token }} |
| 37 | + run: gh release create ${{ github.ref_name }} --generate-notes |
| 38 | + - name: Attach gem to GitHub Release |
| 39 | + shell: bash |
| 40 | + env: |
| 41 | + GH_TOKEN: ${{ github.token }} |
| 42 | + run: gh release upload ${{ github.ref_name }} *.gem |
| 43 | + |
| 44 | + release-to-github: |
| 45 | + needs: build-release |
| 46 | + name: Release to GitHub |
| 47 | + runs-on: ubuntu-24.04 |
| 48 | + permissions: |
| 49 | + packages: write # publish to rubygems.pkg.github.com |
| 50 | + steps: |
| 51 | + - name: Download gem from GitHub cache |
| 52 | + uses: actions/download-artifact@v4 |
| 53 | + with: |
| 54 | + name: gem-artifact |
| 55 | + - name: Setup GitHub packages access |
| 56 | + run: | |
| 57 | + mkdir -p ~/.gem |
| 58 | + echo ":github: Bearer ${{ secrets.GITHUB_TOKEN }}" >> ~/.gem/credentials |
| 59 | + chmod 0600 ~/.gem/credentials |
| 60 | + - name: Publish gem to GitHub packages |
| 61 | + run: gem push --key github --host https://rubygems.pkg.github.com/${{ github.repository_owner }} *.gem |
| 62 | + |
| 63 | + release-to-rubygems: |
| 64 | + needs: build-release |
| 65 | + name: Release gem to rubygems.org |
| 66 | + runs-on: ubuntu-24.04 |
| 67 | + environment: release # recommended by rubygems.org |
| 68 | + permissions: |
| 69 | + id-token: write # rubygems.org authentication |
| 70 | + steps: |
| 71 | + - name: Download gem from GitHub cache |
| 72 | + uses: actions/download-artifact@v4 |
| 73 | + with: |
| 74 | + name: gem-artifact |
| 75 | + - uses: rubygems/[email protected] |
| 76 | + - name: Publish gem to rubygems.org |
| 77 | + shell: bash |
| 78 | + run: gem push *.gem |
| 79 | + |
| 80 | + release-verification: |
| 81 | + name: Check that all releases are done |
| 82 | + runs-on: ubuntu-24.04 |
| 83 | + permissions: |
| 84 | + contents: read # minimal permissions that we have to grant |
| 85 | + needs: |
| 86 | + - release-to-github |
| 87 | + - release-to-rubygems |
| 88 | + steps: |
| 89 | + - name: Download gem from GitHub cache |
| 90 | + uses: actions/download-artifact@v4 |
| 91 | + with: |
| 92 | + name: gem-artifact |
| 93 | + - name: Install Ruby |
| 94 | + uses: ruby/setup-ruby@v1 |
| 95 | + with: |
| 96 | + ruby-version: 'ruby' |
| 97 | + - name: Wait for release to propagate |
| 98 | + shell: bash |
| 99 | + run: | |
| 100 | + gem install rubygems-await |
| 101 | + gem await *.gem |
| 102 | +
|
0 commit comments