-
Notifications
You must be signed in to change notification settings - Fork 17
Add label-driven release workflow #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,232 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [closed] | ||
| branches: [main] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: release | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| check-release-label: | ||
| name: Check for release label | ||
| if: | | ||
| github.event.pull_request.merged == true | ||
| && contains(github.event.pull_request.labels.*.name, 'release') | ||
|
haacked marked this conversation as resolved.
|
||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| should-release: ${{ steps.check.outputs.should-release }} | ||
| bump-type: ${{ steps.check.outputs.bump-type }} | ||
| steps: | ||
| - name: Check release conditions | ||
| id: check | ||
| run: | | ||
| if ${{ contains(github.event.pull_request.labels.*.name, 'bump-major') }}; then | ||
| echo "bump-type=major" >> "$GITHUB_OUTPUT" | ||
| echo "should-release=true" >> "$GITHUB_OUTPUT" | ||
| elif ${{ contains(github.event.pull_request.labels.*.name, 'bump-minor') }}; then | ||
| echo "bump-type=minor" >> "$GITHUB_OUTPUT" | ||
| echo "should-release=true" >> "$GITHUB_OUTPUT" | ||
| elif ${{ contains(github.event.pull_request.labels.*.name, 'bump-patch') }}; then | ||
|
haacked marked this conversation as resolved.
|
||
| echo "bump-type=patch" >> "$GITHUB_OUTPUT" | ||
| echo "should-release=true" >> "$GITHUB_OUTPUT" | ||
|
haacked marked this conversation as resolved.
|
||
| else | ||
| echo "should-release=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| notify-approval-needed: | ||
| name: Notify Slack - Approval Needed | ||
| needs: check-release-label | ||
| if: needs.check-release-label.outputs.should-release == 'true' | ||
| uses: posthog/.github/.github/workflows/notify-approval-needed.yml@main | ||
| with: | ||
| slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }} | ||
| slack_user_group_id: ${{ vars.GROUP_CLIENT_LIBRARIES_SLACK_GROUP_ID }} | ||
| secrets: | ||
| slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }} | ||
| posthog_project_api_key: ${{ secrets.POSTHOG_PROJECT_API_KEY }} | ||
|
|
||
| release: | ||
| name: Bump version and release | ||
| needs: [check-release-label, notify-approval-needed] | ||
| runs-on: ubuntu-latest | ||
| # Use `always()` so the release proceeds even if the Slack notification fails — | ||
| # a Slack outage shouldn't block releases. | ||
| if: always() && needs.check-release-label.outputs.should-release == 'true' | ||
| environment: Release | ||
| permissions: | ||
| contents: write | ||
| actions: write | ||
|
haacked marked this conversation as resolved.
|
||
| env: | ||
| DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 | ||
| DOTNET_NOLOGO: true | ||
| DOTNET_VERSION: "9.0.102" | ||
| steps: | ||
| - name: Notify Slack - Approved | ||
| if: needs.notify-approval-needed.outputs.slack_ts != '' | ||
| uses: posthog/.github/.github/actions/slack-thread-reply@main | ||
| with: | ||
| slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }} | ||
| slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }} | ||
| thread_ts: ${{ needs.notify-approval-needed.outputs.slack_ts }} | ||
| message: "✅ Release approved! Version bump in progress..." | ||
| emoji_reaction: "white_check_mark" | ||
|
|
||
| - name: Get GitHub App token | ||
| id: releaser | ||
| uses: actions/create-github-app-token@v2 | ||
| with: | ||
| app-id: ${{ secrets.GH_APP_POSTHOG_DOTNET_RELEASER_APP_ID }} | ||
| private-key: ${{ secrets.GH_APP_POSTHOG_DOTNET_RELEASER_PRIVATE_KEY }} | ||
|
|
||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: main | ||
| fetch-depth: 0 | ||
| token: ${{ steps.releaser.outputs.token }} | ||
|
|
||
| - name: Configure Git | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@v4 | ||
| with: | ||
| dotnet-version: ${{ env.DOTNET_VERSION }} | ||
|
haacked marked this conversation as resolved.
|
||
|
|
||
| - name: Calculate new version | ||
| id: version | ||
| run: | | ||
| current=$(grep -o '<Version>[^<]*' Directory.Build.props | head -n 1 | sed 's/<Version>//') | ||
| IFS='.' read -r major minor patch <<< "$current" | ||
| patch=$(echo "$patch" | cut -d- -f1) | ||
| case "${{ needs.check-release-label.outputs.bump-type }}" in | ||
| major) major=$((major + 1)); minor=0; patch=0 ;; | ||
| minor) minor=$((minor + 1)); patch=0 ;; | ||
| patch) patch=$((patch + 1)) ;; | ||
| esac | ||
|
haacked marked this conversation as resolved.
|
||
| new_version="$major.$minor.$patch" | ||
| echo "current=$current" >> "$GITHUB_OUTPUT" | ||
| echo "new=$new_version" >> "$GITHUB_OUTPUT" | ||
| echo "Bumping $current → $new_version" | ||
|
|
||
| - name: Update version | ||
| run: | | ||
| sed -i "s|<Version>${{ steps.version.outputs.current }}</Version>|<Version>${{ steps.version.outputs.new }}</Version>|" Directory.Build.props | ||
|
haacked marked this conversation as resolved.
|
||
|
|
||
| - name: Build | ||
| run: dotnet build --configuration Release | ||
|
|
||
| - name: Test | ||
| run: dotnet test --configuration Release --no-build | ||
|
haacked marked this conversation as resolved.
|
||
|
|
||
| - name: Commit version bump | ||
| id: commit-version-bump | ||
| env: | ||
| GITHUB_TOKEN: ${{ steps.releaser.outputs.token }} | ||
|
haacked marked this conversation as resolved.
|
||
| run: | | ||
| git add Directory.Build.props src/PostHog/Generated/VersionConstants.cs | ||
| if git diff --staged --quiet; then | ||
| echo "No changes to commit" | ||
| echo "committed=false" >> "$GITHUB_OUTPUT" | ||
| else | ||
| git commit -m "Bump version to ${{ steps.version.outputs.new }}" | ||
| git push origin main | ||
| echo "committed=true" >> "$GITHUB_OUTPUT" | ||
|
haacked marked this conversation as resolved.
|
||
| fi | ||
|
|
||
| - name: Create tag and GitHub Release | ||
| if: steps.commit-version-bump.outputs.committed == 'true' | ||
| env: | ||
| GH_TOKEN: ${{ steps.releaser.outputs.token }} | ||
| run: | | ||
| version="${{ steps.version.outputs.new }}" | ||
| git tag -a "v$version" -m "v$version" | ||
| git push origin "v$version" | ||
| gh release create "v$version" --generate-notes | ||
|
|
||
|
haacked marked this conversation as resolved.
|
||
| - name: Send failure event to PostHog | ||
| if: failure() | ||
| uses: PostHog/posthog-github-action@v0.1 | ||
| with: | ||
| posthog-token: "${{ secrets.POSTHOG_PROJECT_API_KEY }}" | ||
| event: "posthog-dotnet-github-release-workflow-failure" | ||
| properties: >- | ||
| { | ||
| "commitSha": "${{ github.sha }}", | ||
| "jobStatus": "${{ job.status }}", | ||
| "ref": "${{ github.ref }}", | ||
| "version": "v${{ steps.version.outputs.new }}" | ||
| } | ||
|
haacked marked this conversation as resolved.
|
||
|
|
||
| - name: Notify Slack - Failed | ||
| if: failure() && needs.notify-approval-needed.outputs.slack_ts != '' | ||
| uses: posthog/.github/.github/actions/slack-thread-reply@main | ||
| with: | ||
| slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }} | ||
| slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }} | ||
| thread_ts: ${{ needs.notify-approval-needed.outputs.slack_ts }} | ||
| message: "❌ Failed to release `posthog-dotnet@v${{ steps.version.outputs.new }}`! <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|View logs>" | ||
|
haacked marked this conversation as resolved.
|
||
| emoji_reaction: "x" | ||
|
|
||
| notify-rejected: | ||
| name: Notify Slack - Rejected | ||
| needs: [release, notify-approval-needed] | ||
| runs-on: ubuntu-latest | ||
| if: always() && (needs.release.result == 'failure' || needs.release.result == 'skipped') && needs.notify-approval-needed.outputs.slack_ts != '' | ||
| steps: | ||
| - name: Check for rejection | ||
| id: check-rejection | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| RESPONSE=$(gh api /repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/approvals) | ||
| REJECTED=$(echo "$RESPONSE" | jq '[.[] | select(.state == "rejected")] | length') | ||
| if [ "$REJECTED" -gt 0 ]; then | ||
| echo "was_rejected=true" >> "$GITHUB_OUTPUT" | ||
| COMMENT=$(echo "$RESPONSE" | jq -r '.[] | select(.state == "rejected") | .comment // empty' | head -1) | ||
| if [ -n "$COMMENT" ]; then | ||
| { | ||
| echo 'message<<EOF' | ||
| echo "🚫 Release was rejected: $COMMENT" | ||
| echo 'EOF' | ||
| } >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "message=🚫 Release was rejected." >> "$GITHUB_OUTPUT" | ||
| fi | ||
| else | ||
| echo "was_rejected=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Notify Slack - Rejected | ||
| if: steps.check-rejection.outputs.was_rejected == 'true' | ||
| continue-on-error: true | ||
| uses: posthog/.github/.github/actions/slack-thread-reply@main | ||
| with: | ||
| slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }} | ||
| slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }} | ||
| thread_ts: ${{ needs.notify-approval-needed.outputs.slack_ts }} | ||
| message: '${{ steps.check-rejection.outputs.message }}' | ||
| emoji_reaction: 'no_entry_sign' | ||
|
|
||
| notify-released: | ||
| name: Notify Slack - Released | ||
| needs: [notify-approval-needed, release] | ||
| runs-on: ubuntu-latest | ||
| if: always() && needs.release.result == 'success' && needs.notify-approval-needed.outputs.slack_ts != '' | ||
| steps: | ||
| - name: Notify Slack - Released | ||
| uses: posthog/.github/.github/actions/slack-thread-reply@main | ||
| with: | ||
| slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }} | ||
| slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }} | ||
| thread_ts: ${{ needs.notify-approval-needed.outputs.slack_ts }} | ||
| message: "🚀 posthog-dotnet released successfully!" | ||
| emoji_reaction: "rocket" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.