|
62 | 62 | name: Release and publish |
63 | 63 | needs: [check-release-label, notify-approval-needed] |
64 | 64 | runs-on: ubuntu-latest |
| 65 | + outputs: |
| 66 | + new-version: ${{ steps.sampo-release.outputs.new_version }} |
65 | 67 | # Use `always()` to ensure the job runs even if notify-approval-needed is skipped, |
66 | 68 | # but still depend on it to access `needs.notify-approval-needed.outputs.slack_ts` |
67 | 69 | if: always() && needs.check-release-label.outputs.should-release == 'true' |
@@ -201,29 +203,56 @@ jobs: |
201 | 203 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
202 | 204 | run: gh workflow run generate-references.yml --ref main |
203 | 205 |
|
204 | | - # Notify in case of a failure |
| 206 | + notify-failed: |
| 207 | + name: Notify release failure |
| 208 | + needs: [check-release-label, notify-approval-needed, release] |
| 209 | + runs-on: ubuntu-latest |
| 210 | + # Keep failure reporting in a separate job so it still runs when `release` |
| 211 | + # fails during job setup, before any of that job's steps can execute. |
| 212 | + if: always() && needs.check-release-label.outputs.should-release == 'true' && needs.release.result == 'failure' |
| 213 | + steps: |
205 | 214 | - name: Send failure event to PostHog |
206 | | - if: ${{ failure() }} |
207 | | - uses: PostHog/posthog-github-action@v0.1 |
| 215 | + uses: PostHog/posthog-github-action@v1 |
208 | 216 | with: |
209 | 217 | posthog-token: "${{ secrets.POSTHOG_PROJECT_API_KEY }}" |
210 | 218 | event: "posthog-python-github-release-workflow-failure" |
| 219 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 220 | + status-job: "Release and publish" |
| 221 | + capture-run-duration: true |
211 | 222 | properties: >- |
212 | 223 | { |
213 | 224 | "commitSha": "${{ github.sha }}", |
214 | | - "jobStatus": "${{ job.status }}", |
| 225 | + "jobStatus": "${{ needs.release.result }}", |
215 | 226 | "ref": "${{ github.ref }}", |
216 | | - "version": "${{ steps.sampo-release.outputs.new_version }}" |
| 227 | + "version": "${{ needs.release.outputs.new-version }}" |
217 | 228 | } |
218 | 229 |
|
| 230 | + - name: Build Slack failure message |
| 231 | + if: needs.notify-approval-needed.outputs.slack_ts != '' |
| 232 | + id: failure-message |
| 233 | + env: |
| 234 | + RELEASE_VERSION: ${{ needs.release.outputs.new-version }} |
| 235 | + run: | |
| 236 | + if [ -n "$RELEASE_VERSION" ]; then |
| 237 | + message="❌ Failed to release \`posthog-python@$RELEASE_VERSION\`! <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|View logs>" |
| 238 | + else |
| 239 | + message="❌ Failed to release \`posthog-python\`! <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|View logs>" |
| 240 | + fi |
| 241 | +
|
| 242 | + { |
| 243 | + echo 'message<<EOF' |
| 244 | + echo "$message" |
| 245 | + echo EOF |
| 246 | + } >> "$GITHUB_OUTPUT" |
| 247 | +
|
219 | 248 | - name: Notify Slack - Failed |
220 | | - if: ${{ failure() && needs.notify-approval-needed.outputs.slack_ts != '' }} |
| 249 | + if: needs.notify-approval-needed.outputs.slack_ts != '' |
221 | 250 | uses: posthog/.github/.github/actions/slack-thread-reply@main |
222 | 251 | with: |
223 | 252 | slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }} |
224 | 253 | slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }} |
225 | 254 | thread_ts: ${{ needs.notify-approval-needed.outputs.slack_ts }} |
226 | | - message: "❌ Failed to release `posthog-python@${{ steps.sampo-release.outputs.new_version }}`! <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|View logs>" |
| 255 | + message: ${{ steps.failure-message.outputs.message }} |
227 | 256 | emoji_reaction: "x" |
228 | 257 |
|
229 | 258 | notify-released: |
|
0 commit comments