-
Notifications
You must be signed in to change notification settings - Fork 29
feat(workflow): add event-driven CI-ready gate for publish #7664
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
+134
−1
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6a836b0
feat(workflow): add event-driven CI-ready gate for publish
BYK 399055e
chore: remove redundant GH_TOKEN env, gh uses GITHUB_TOKEN natively
BYK 6e7fdb4
fix: require accepted label on the issue before starting the publish job
BYK 2de04ae
refactor: move gating logic to job-level if, remove gate step
BYK c796855
fix: use GitHub App token for label changes and increase issue list l…
BYK a6fc6b5
fix: make ci-ready comment reflect whether accepted label is already …
BYK 3d53901
fix: add missing GH_TOKEN and issues:read permission for gh CLI
BYK 423ba41
chore: remove redundant GH_TOKEN where gh uses GITHUB_TOKEN natively
BYK c544155
fix: use issue title as concurrency group to lock on repo@version
BYK d42256b
fix: remove --no-status-check, let craft verify CI status itself
BYK 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| name: CI Ready Signal | ||
|
|
||
| on: | ||
| repository_dispatch: | ||
| types: [ci-ready] | ||
|
|
||
| # client_payload schema: | ||
| # repo: "getsentry/sentry-native" (full owner/repo) | ||
| # version: "0.13.4" | ||
| # sha: "abc123..." (the release branch HEAD SHA) | ||
|
|
||
| permissions: | ||
| contents: read | ||
| issues: read | ||
|
|
||
| jobs: | ||
| signal: | ||
| runs-on: ubuntu-latest | ||
| name: Process CI-ready signal | ||
| steps: | ||
| - name: Find matching publish issue | ||
| id: find-issue | ||
| env: | ||
| REPO: ${{ github.event.client_payload.repo }} | ||
| VERSION: ${{ github.event.client_payload.version }} | ||
| run: | | ||
| title="publish: ${REPO}@${VERSION}" | ||
| echo "Looking for issue: ${title}" | ||
|
|
||
| # Find matching open issue by exact title match. | ||
| # Use --limit 200 to handle active repos with many open issues. | ||
| issue=$(gh issue list -R "$GITHUB_REPOSITORY" \ | ||
| --state open \ | ||
| --limit 200 \ | ||
| --json number,title,labels \ | ||
| | jq -r --arg t "$title" \ | ||
| '[.[] | select(.title == $t)] | first // empty') | ||
sentry[bot] marked this conversation as resolved.
Show resolved
Hide resolved
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if [[ -z "$issue" ]]; then | ||
| # Retry a few times in case the issue hasn't been created yet | ||
| for i in 1 2 3; do | ||
| echo "Issue not found, retry ${i}/3 in 10s..." | ||
| sleep 10 | ||
| issue=$(gh issue list -R "$GITHUB_REPOSITORY" \ | ||
| --state open \ | ||
| --limit 200 \ | ||
| --json number,title,labels \ | ||
| | jq -r --arg t "$title" \ | ||
| '[.[] | select(.title == $t)] | first // empty') | ||
| if [[ -n "$issue" ]]; then break; fi | ||
| done | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fi | ||
|
|
||
| if [[ -z "$issue" ]]; then | ||
| echo "::warning::No open issue found with title: ${title}" | ||
| exit 0 | ||
| fi | ||
|
|
||
| number=$(echo "$issue" | jq -r '.number') | ||
| has_ci_pending=$(echo "$issue" | jq '[.labels[].name] | any(. == "ci-pending")') | ||
|
|
||
| if [[ "$has_ci_pending" != "true" ]]; then | ||
| echo "::warning::Issue #${number} does not have ci-pending label. Ignoring signal." | ||
| exit 0 | ||
| fi | ||
|
|
||
| has_accepted=$(echo "$issue" | jq '[.labels[].name] | any(. == "accepted")') | ||
|
|
||
| echo "number=${number}" >> "$GITHUB_OUTPUT" | ||
| echo "has_accepted=${has_accepted}" >> "$GITHUB_OUTPUT" | ||
| echo "Found issue #${number} with ci-pending label (accepted=${has_accepted})" | ||
|
|
||
| # Use a GitHub App token so the label change triggers publish.yml. | ||
| # GITHUB_TOKEN events are deliberately suppressed by GitHub and | ||
| # would not create new workflow runs. | ||
| - name: Get auth token | ||
| if: steps.find-issue.outputs.number | ||
| id: token | ||
| uses: actions/create-github-app-token@v2.2.1 | ||
| with: | ||
| app-id: ${{ vars.SENTRY_INTERNAL_APP_ID }} | ||
| private-key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }} | ||
|
Comment on lines
+81
to
+82
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. niche: probably better to use release-bot here to unify the app usage, release bot is also managed more tightly and less likely to break or affected by other changes |
||
|
|
||
| - name: Add ci-ready label | ||
| if: steps.find-issue.outputs.number | ||
| env: | ||
| # Override the default GITHUB_TOKEN with the app token so the | ||
| # label event triggers publish.yml (GITHUB_TOKEN events are | ||
| # suppressed by GitHub and would not start new workflow runs). | ||
| GH_TOKEN: ${{ steps.token.outputs.token }} | ||
| ISSUE_NUMBER: ${{ steps.find-issue.outputs.number }} | ||
| SHA: ${{ github.event.client_payload.sha }} | ||
| REPO: ${{ github.event.client_payload.repo }} | ||
| run: | | ||
| gh issue edit "$ISSUE_NUMBER" -R "$GITHUB_REPOSITORY" \ | ||
| --remove-label "ci-pending" \ | ||
| --add-label "ci-ready" | ||
|
|
||
| if [[ "${{ steps.find-issue.outputs.has_accepted }}" == "true" ]]; then | ||
| comment="CI checks passed for ${REPO} (\`${SHA:0:8}\`). Publishing is starting now." | ||
| else | ||
| comment="CI checks passed for ${REPO} (\`${SHA:0:8}\`). Publishing will start once the **accepted** label is also present." | ||
| fi | ||
| gh issue comment "$ISSUE_NUMBER" -R "$GITHUB_REPOSITORY" --body "$comment" | ||
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
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.