|
1 | | -name: Publish Release |
| 1 | +name: "Release" |
2 | 2 |
|
3 | 3 | on: |
4 | | - workflow_dispatch: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
| 6 | + branches: [main] |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +# Concurrency control: only one release process can run at a time |
| 12 | +# This prevents race conditions if multiple PRs with 'release' label merge simultaneously |
| 13 | +concurrency: |
| 14 | + group: release |
| 15 | + cancel-in-progress: false |
5 | 16 |
|
6 | 17 | jobs: |
7 | | - publish: |
| 18 | + check-release-label: |
| 19 | + name: Check for release label |
8 | 20 | runs-on: ubuntu-latest |
| 21 | + # Run when PR with 'release' label is merged to main |
| 22 | + if: | |
| 23 | + github.event.pull_request.merged == true |
| 24 | + && contains(github.event.pull_request.labels.*.name, 'release') |
| 25 | + outputs: |
| 26 | + should-release: ${{ steps.check.outputs.should-release }} |
| 27 | + version: ${{ steps.check.outputs.version }} |
| 28 | + steps: |
| 29 | + - name: Checkout repository |
| 30 | + uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + ref: main |
| 33 | + |
| 34 | + - name: Check version is new |
| 35 | + id: check |
| 36 | + run: | |
| 37 | + # Extract version from source |
| 38 | + version=$(grep "VERSION = '" lib/posthog/version.rb | grep -o "'[0-9]\+\.[0-9]\+\.[0-9]\+'" | tr -d "'") |
| 39 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 40 | +
|
| 41 | + # Get currently published version from RubyGems |
| 42 | + published=$(gem info posthog-ruby --remote 2>/dev/null | grep -o 'posthog-ruby ([0-9.]*' | grep -o '[0-9].*' || echo "none") |
| 43 | +
|
| 44 | + echo "Local version: $version" |
| 45 | + echo "Published version: $published" |
| 46 | +
|
| 47 | + if [ "$version" = "$published" ]; then |
| 48 | + echo "Version $version is already published, skipping release" |
| 49 | + echo "should-release=false" >> "$GITHUB_OUTPUT" |
| 50 | + else |
| 51 | + echo "Ready to release version $version" |
| 52 | + echo "should-release=true" >> "$GITHUB_OUTPUT" |
| 53 | + fi |
| 54 | +
|
| 55 | + notify-approval-needed: |
| 56 | + name: Notify Slack - Approval Needed |
| 57 | + needs: check-release-label |
| 58 | + if: needs.check-release-label.outputs.should-release == 'true' |
| 59 | + uses: posthog/.github/.github/workflows/notify-approval-needed.yml@main |
| 60 | + with: |
| 61 | + slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }} |
| 62 | + slack_user_group_id: ${{ vars.GROUP_CLIENT_LIBRARIES_SLACK_GROUP_ID }} |
| 63 | + secrets: |
| 64 | + slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }} |
| 65 | + posthog_project_api_key: ${{ secrets.POSTHOG_PROJECT_API_KEY }} |
| 66 | + |
| 67 | + release: |
| 68 | + name: Release and publish |
| 69 | + needs: [check-release-label, notify-approval-needed] |
| 70 | + runs-on: ubuntu-latest |
| 71 | + if: always() && needs.check-release-label.outputs.should-release == 'true' |
| 72 | + environment: "Release" # This will require an approval from a maintainer, they are notified in Slack above |
9 | 73 | permissions: |
10 | | - contents: read |
| 74 | + contents: write |
11 | 75 | id-token: write |
12 | 76 | steps: |
13 | | - - name: Checkout |
14 | | - uses: actions/checkout@v5 |
| 77 | + - name: Notify Slack - Approved |
| 78 | + if: needs.notify-approval-needed.outputs.slack_ts != '' |
| 79 | + uses: posthog/.github/.github/actions/slack-thread-reply@main |
| 80 | + with: |
| 81 | + slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }} |
| 82 | + slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }} |
| 83 | + thread_ts: ${{ needs.notify-approval-needed.outputs.slack_ts }} |
| 84 | + message: "✅ Release approved! Publishing v${{ needs.check-release-label.outputs.version }}..." |
| 85 | + emoji_reaction: "white_check_mark" |
| 86 | + |
| 87 | + - name: Checkout repository |
| 88 | + uses: actions/checkout@v4 |
15 | 89 | with: |
16 | 90 | ref: main |
17 | 91 | fetch-depth: 0 |
|
22 | 96 | bundler-cache: true |
23 | 97 | ruby-version: ruby |
24 | 98 |
|
25 | | - - uses: rubygems/release-gem@v1 |
| 99 | + - name: Configure trusted publishing credentials |
| 100 | + uses: rubygems/configure-rubygems-credentials@v1.0.0 |
| 101 | + |
| 102 | + # Build and publish posthog-ruby first (posthog-rails depends on it) |
| 103 | + - name: Build posthog-ruby |
| 104 | + run: gem build posthog-ruby.gemspec |
| 105 | + |
| 106 | + - name: Publish posthog-ruby |
| 107 | + run: gem push posthog-ruby-*.gem |
| 108 | + |
| 109 | + - name: Wait for posthog-ruby to be available |
| 110 | + run: gem exec rubygems-await posthog-ruby-*.gem |
| 111 | + |
| 112 | + # Build and publish posthog-rails |
| 113 | + - name: Build posthog-rails |
| 114 | + run: gem build posthog-rails/posthog-rails.gemspec |
| 115 | + |
| 116 | + - name: Publish posthog-rails |
| 117 | + run: gem push posthog-rails-*.gem |
| 118 | + |
| 119 | + - name: Wait for posthog-rails to be available |
| 120 | + run: gem exec rubygems-await posthog-rails-*.gem |
| 121 | + |
| 122 | + # Create and push git tag |
| 123 | + - name: Create git tag |
| 124 | + run: | |
| 125 | + git config user.name "github-actions[bot]" |
| 126 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 127 | + git tag -a "v${{ needs.check-release-label.outputs.version }}" -m "Release v${{ needs.check-release-label.outputs.version }}" |
| 128 | + git push origin "v${{ needs.check-release-label.outputs.version }}" |
| 129 | +
|
| 130 | + # Notify in case of a failure |
| 131 | + - name: Send failure event to PostHog |
| 132 | + if: ${{ failure() }} |
| 133 | + uses: PostHog/posthog-github-action@v0.1 |
| 134 | + with: |
| 135 | + posthog-token: "${{ secrets.POSTHOG_PROJECT_API_KEY }}" |
| 136 | + event: "posthog-ruby-github-release-workflow-failure" |
| 137 | + properties: >- |
| 138 | + { |
| 139 | + "commitSha": "${{ github.sha }}", |
| 140 | + "jobStatus": "${{ job.status }}", |
| 141 | + "ref": "${{ github.ref }}", |
| 142 | + "version": "v${{ needs.check-release-label.outputs.version }}" |
| 143 | + } |
| 144 | +
|
| 145 | + - name: Notify Slack - Failed |
| 146 | + if: ${{ failure() && needs.notify-approval-needed.outputs.slack_ts != '' }} |
| 147 | + uses: posthog/.github/.github/actions/slack-thread-reply@main |
| 148 | + with: |
| 149 | + slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }} |
| 150 | + slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }} |
| 151 | + thread_ts: ${{ needs.notify-approval-needed.outputs.slack_ts }} |
| 152 | + message: "❌ Failed to release `posthog-ruby@v${{ needs.check-release-label.outputs.version }}`! <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|View logs>" |
| 153 | + emoji_reaction: "x" |
| 154 | + |
| 155 | + notify-released: |
| 156 | + name: Notify Slack - Released |
| 157 | + needs: [check-release-label, notify-approval-needed, release] |
| 158 | + runs-on: ubuntu-latest |
| 159 | + if: always() && needs.release.result == 'success' && needs.notify-approval-needed.outputs.slack_ts != '' |
| 160 | + steps: |
| 161 | + - name: Notify Slack - Released |
| 162 | + uses: posthog/.github/.github/actions/slack-thread-reply@main |
| 163 | + with: |
| 164 | + slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }} |
| 165 | + slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }} |
| 166 | + thread_ts: ${{ needs.notify-approval-needed.outputs.slack_ts }} |
| 167 | + message: "🚀 posthog-ruby and posthog-rails v${{ needs.check-release-label.outputs.version }} released successfully!" |
| 168 | + emoji_reaction: "rocket" |
0 commit comments