|
| 1 | +name: Publish Gem |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + tag_name: |
| 9 | + description: 'Tag name to publish (e.g., v1.0.0)' |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + |
| 13 | +jobs: |
| 14 | + publish: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Set up Ruby |
| 20 | + uses: ruby/setup-ruby@v1 |
| 21 | + with: |
| 22 | + ruby-version: '3.2' |
| 23 | + bundler-cache: true |
| 24 | + |
| 25 | + - name: Extract version from tag |
| 26 | + id: version |
| 27 | + run: | |
| 28 | + # Get tag from either release event or manual input |
| 29 | + if [ "${{ github.event_name }}" = "release" ]; then |
| 30 | + TAG_NAME="${{ github.event.release.tag_name }}" |
| 31 | + else |
| 32 | + TAG_NAME="${{ inputs.tag_name }}" |
| 33 | + fi |
| 34 | + VERSION=${TAG_NAME#v} # Remove 'v' prefix |
| 35 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 36 | + echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT |
| 37 | +
|
| 38 | + - name: Verify version matches |
| 39 | + run: | |
| 40 | + GEMSPEC_VERSION=$(ruby -r ./lib/activejob/compressible/version.rb -e "puts ActiveJob::Compressible::VERSION") |
| 41 | + RELEASE_VERSION="${{ steps.version.outputs.version }}" |
| 42 | +
|
| 43 | + if [ "$GEMSPEC_VERSION" != "$RELEASE_VERSION" ]; then |
| 44 | + echo "Error: Version mismatch!" |
| 45 | + echo "Gemspec version: $GEMSPEC_VERSION" |
| 46 | + echo "Release version: $RELEASE_VERSION" |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | +
|
| 50 | + echo "✅ Version verified: $GEMSPEC_VERSION" |
| 51 | +
|
| 52 | + - name: Build gem with checksum |
| 53 | + run: bundle exec rake build:checksum |
| 54 | + |
| 55 | + - name: Set up RubyGems credentials |
| 56 | + run: | |
| 57 | + mkdir -p ~/.gem |
| 58 | + echo ":rubygems_api_key: ${{ secrets.RUBYGEMS_API_KEY }}" > ~/.gem/credentials |
| 59 | + chmod 0600 ~/.gem/credentials |
| 60 | +
|
| 61 | + - name: Publish to RubyGems |
| 62 | + run: gem push pkg/activejob-compressible-*.gem |
| 63 | + |
| 64 | + - name: Annotate publication success |
| 65 | + id: publish_info |
| 66 | + run: | |
| 67 | + VERSION="${{ steps.version.outputs.version }}" |
| 68 | + TAG="${{ steps.version.outputs.tag }}" |
| 69 | + RUBYGEMS_URL="https://rubygems.org/gems/activejob-compressible/versions/$VERSION" |
| 70 | + INSTALL_CMD="gem install activejob-compressible -v $VERSION" |
| 71 | +
|
| 72 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 73 | + echo "tag=$TAG" >> $GITHUB_OUTPUT |
| 74 | + echo "rubygems_url=$RUBYGEMS_URL" >> $GITHUB_OUTPUT |
| 75 | + echo "install_cmd=$INSTALL_CMD" >> $GITHUB_OUTPUT |
| 76 | +
|
| 77 | + cat >> $GITHUB_STEP_SUMMARY << EOF |
| 78 | + # 🎉 Gem Published Successfully! |
| 79 | +
|
| 80 | + `activejob-compressible` version `$VERSION` has been published to RubyGems. |
| 81 | +
|
| 82 | + ## 📦 Installation |
| 83 | + \`\`\`bash |
| 84 | + $INSTALL_CMD |
| 85 | + \`\`\` |
| 86 | +
|
| 87 | + ## 🔗 Links |
| 88 | + - **RubyGems:** [$RUBYGEMS_URL]($RUBYGEMS_URL) |
| 89 | + - **Git Tag:** \`$TAG\` |
| 90 | + - **GitHub Release:** [View Release](https://github.com/Archetypically/activejob-compressible/releases/tag/$TAG) |
| 91 | + EOF |
0 commit comments