|
| 1 | +--- |
| 2 | + |
| 3 | +name: Publish Release |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + paths: |
| 10 | + - lib/semian/version.rb |
| 11 | + |
| 12 | +jobs: |
| 13 | + check-version-bump: |
| 14 | + name: Check if this is a version bump |
| 15 | + runs-on: ubuntu-latest |
| 16 | + outputs: |
| 17 | + is_release: ${{ steps.check.outputs.is_release }} |
| 18 | + version: ${{ steps.version.outputs.version }} |
| 19 | + steps: |
| 20 | + - |
| 21 | + name: Checkout |
| 22 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 23 | + with: |
| 24 | + fetch-depth: 2 |
| 25 | + - |
| 26 | + name: Check if commit is version bump |
| 27 | + id: check |
| 28 | + run: | |
| 29 | + # Check if the commit message indicates a version bump |
| 30 | + commit_msg=$(git log -1 --pretty=%s) |
| 31 | + if [[ "$commit_msg" =~ ^"Bump version to" ]]; then |
| 32 | + echo "is_release=true" >> $GITHUB_OUTPUT |
| 33 | + echo "✅ Detected version bump commit: $commit_msg" |
| 34 | + else |
| 35 | + echo "is_release=false" >> $GITHUB_OUTPUT |
| 36 | + echo "❌ Not a version bump commit: $commit_msg" |
| 37 | + fi |
| 38 | + - |
| 39 | + name: Set up Ruby |
| 40 | + if: steps.check.outputs.is_release == 'true' |
| 41 | + uses: ruby/setup-ruby@v1.263.0 |
| 42 | + with: |
| 43 | + ruby-version: "3.4" |
| 44 | + bundler-cache: true |
| 45 | + - |
| 46 | + name: Read version |
| 47 | + if: steps.check.outputs.is_release == 'true' |
| 48 | + id: version |
| 49 | + run: | |
| 50 | + version=$(ruby -e "require './lib/semian/version'; puts Semian::VERSION") |
| 51 | + echo "version=$version" >> $GITHUB_OUTPUT |
| 52 | + echo "Current version: $version" |
| 53 | +
|
| 54 | + build-and-release: |
| 55 | + name: Build gem and create GitHub release |
| 56 | + runs-on: ubuntu-latest |
| 57 | + needs: [check-version-bump] |
| 58 | + if: needs.check-version-bump.outputs.is_release == 'true' |
| 59 | + permissions: |
| 60 | + contents: write |
| 61 | + steps: |
| 62 | + - |
| 63 | + name: Checkout |
| 64 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 65 | + - |
| 66 | + name: Set up Ruby |
| 67 | + uses: ruby/setup-ruby@v1.263.0 |
| 68 | + with: |
| 69 | + ruby-version: "3.4" |
| 70 | + bundler-cache: true |
| 71 | + - |
| 72 | + name: Create and push tag |
| 73 | + env: |
| 74 | + VERSION: ${{ needs.check-version-bump.outputs.version }} |
| 75 | + run: | |
| 76 | + git config --local user.email "action@github.com" |
| 77 | + git config --local user.name "GitHub Action" |
| 78 | + git tag "v$VERSION" |
| 79 | + git push origin "v$VERSION" |
| 80 | + echo "✅ Created and pushed tag v$VERSION" |
| 81 | + - |
| 82 | + name: Build C extension |
| 83 | + run: bundle exec rake build |
| 84 | + - |
| 85 | + name: Build gem |
| 86 | + run: | |
| 87 | + gem build semian.gemspec |
| 88 | + - |
| 89 | + name: Generate SHA512 checksum |
| 90 | + run: | |
| 91 | + for gem in semian-*.gem; do |
| 92 | + sha512sum "$gem" > "${gem}.sha512" |
| 93 | + done |
| 94 | + - |
| 95 | + name: Draft GitHub release |
| 96 | + env: |
| 97 | + GH_TOKEN: ${{ github.token }} |
| 98 | + VERSION: ${{ needs.check-version-bump.outputs.version }} |
| 99 | + run: | |
| 100 | + tag="v$VERSION" |
| 101 | + gh release create "$tag" \ |
| 102 | + --title "$tag" \ |
| 103 | + --generate-notes \ |
| 104 | + --draft \ |
| 105 | + semian-*.gem \ |
| 106 | + semian-*.gem.sha512 |
| 107 | + - |
| 108 | + name: Filter release PR commits |
| 109 | + env: |
| 110 | + GH_TOKEN: ${{ github.token }} |
| 111 | + VERSION: ${{ needs.check-version-bump.outputs.version }} |
| 112 | + run: | |
| 113 | + tag="v$VERSION" |
| 114 | + gh release view "$tag" --json body -q '.body' > temp_notes.md |
| 115 | +
|
| 116 | + # Filter out dependabot commits and the release PR itself |
| 117 | + grep -v -i "bump.*by.*dependabot" temp_notes.md | \ |
| 118 | + grep -v -i "release v.*by.*@github-actions" > filtered_notes.md || true |
| 119 | +
|
| 120 | + echo "Filtered release notes:" |
| 121 | + cat filtered_notes.md |
| 122 | + - |
| 123 | + name: Publish release |
| 124 | + env: |
| 125 | + GH_TOKEN: ${{ github.token }} |
| 126 | + VERSION: ${{ needs.check-version-bump.outputs.version }} |
| 127 | + run: | |
| 128 | + tag="v$VERSION" |
| 129 | + gh release edit "$tag" \ |
| 130 | + --notes-file filtered_notes.md \ |
| 131 | + --draft=false |
| 132 | + echo "🚀 Published release $tag" |
0 commit comments