|
| 1 | +name: Build Gems |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + release: |
| 6 | + types: [published] |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 10 | + cancel-in-progress: true |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + name: Build ${{ matrix.target }} gem |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + target: |
| 22 | + - default |
| 23 | + - aarch64-linux-gnu |
| 24 | + - aarch64-linux-musl |
| 25 | + - arm-linux-gnu |
| 26 | + - arm-linux-musl |
| 27 | + - arm64-darwin |
| 28 | + - x86-linux-gnu |
| 29 | + - x86-linux-musl |
| 30 | + - x86_64-darwin |
| 31 | + - x86_64-linux-gnu |
| 32 | + - x86_64-linux-musl |
| 33 | + |
| 34 | + runs-on: ubuntu-latest |
| 35 | + timeout-minutes: 20 |
| 36 | + |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@v4 |
| 39 | + |
| 40 | + - name: Setup Ruby |
| 41 | + uses: ruby/setup-ruby@v1 |
| 42 | + with: |
| 43 | + bundler-cache: true |
| 44 | + |
| 45 | + - name: Build gem |
| 46 | + run: | |
| 47 | + if [ "${{ matrix.target }}" = "default" ]; then |
| 48 | + bundle exec rake build |
| 49 | + else |
| 50 | + bundle exec rake gem:${{ matrix.target }} |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Upload gem artifacts |
| 54 | + if: github.event_name == 'release' |
| 55 | + uses: actions/upload-artifact@v4 |
| 56 | + with: |
| 57 | + name: gem-${{ matrix.target }} |
| 58 | + path: pkg/*.gem |
| 59 | + if-no-files-found: error |
| 60 | + retention-days: 7 |
| 61 | + |
| 62 | + push: |
| 63 | + name: Push gems with trusted publishing |
| 64 | + if: github.event_name == 'release' && github.repository_owner == 'marcoroth' |
| 65 | + needs: build |
| 66 | + timeout-minutes: 30 |
| 67 | + runs-on: ubuntu-latest |
| 68 | + permissions: |
| 69 | + contents: write |
| 70 | + id-token: write |
| 71 | + |
| 72 | + steps: |
| 73 | + - uses: actions/checkout@v4 |
| 74 | + with: |
| 75 | + fetch-depth: 0 |
| 76 | + |
| 77 | + - name: Vendor release-gem patch |
| 78 | + uses: actions/checkout@v4 |
| 79 | + with: |
| 80 | + repository: rubygems/release-gem |
| 81 | + ref: 1c162a739e8b4cb21a676e97b087e8268d8fc40b # v1.1.2 |
| 82 | + path: .github/_release-gem |
| 83 | + |
| 84 | + - name: Setup Ruby |
| 85 | + uses: ruby/setup-ruby@v1 |
| 86 | + with: |
| 87 | + ruby-version: "3.4" |
| 88 | + bundler-cache: false |
| 89 | + |
| 90 | + - name: Download gem artifacts |
| 91 | + uses: actions/download-artifact@v4 |
| 92 | + with: |
| 93 | + pattern: gem-* |
| 94 | + path: pkg/ |
| 95 | + merge-multiple: true |
| 96 | + |
| 97 | + - name: Configure trusted publishing credentials |
| 98 | + |
| 99 | + |
| 100 | + - name: Push gem with Sigstore attestation |
| 101 | + env: |
| 102 | + RUBYOPT: "-r${{ github.workspace }}/.github/_release-gem/rubygems-attestation-patch.rb" |
| 103 | + run: | |
| 104 | + cd pkg |
| 105 | + for gem_file in *.gem; do |
| 106 | + if [ -f "$gem_file" ]; then |
| 107 | + echo "Pushing $gem_file" |
| 108 | + gem push "$gem_file" |
| 109 | + fi |
| 110 | + done |
0 commit comments