Repository navigation
Extend hotfix label automation to cover issues #4741
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
Open
mdaigle
wants to merge
27
commits into
dotnet:main
Choose a base branch
from
mdaigle:mdaigle-hotfix-label-issue-automation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
028663d
Extend hotfix label automation to cover issues
mdaigle 5a238d0
fix(cherry-pick-to-release): gh api --jq doesn't support jq's --arg
mdaigle a2f424e
Address review feedback: cross-repo issue filtering, duplicate-guard …
mdaigle 3661b11
hotfix-label-issue.yml: serialize runs per issue+label to close a che…
mdaigle 12e25f7
sync-hotfix-label-to-pr.sh: don't swallow gh issue view failures
mdaigle c69ee76
Add hotfix label automation diagram doc
mdaigle dcfabf6
Link every closing issue's backport, not just the first
mdaigle 4f6de72
Refine hotfix automation diagram
mdaigle b68b931
Move hotfix automation doc out of .github/workflows
mdaigle 5f9a299
Fix cut-off/wrapped labels in hotfix automation diagram
mdaigle 524cf81
Remove hotfix automation diagram doc
mdaigle a64d78a
Require [VERSION] title prefix when matching backport sub-issue
mdaigle d88aa47
Explicitly close backport issues on release-branch PR merge
mdaigle 6de6dba
Fix duplicate-detection false positive, PR label permissions, and doc…
mdaigle 052b8f0
Fix backport-issue closing to use an explicit marker, not closingIssu…
mdaigle 447f2b6
Clarify comments: close-backport-issue job scope and duplicate-guard …
mdaigle ce8ba9f
Fix cherry-pick automation for retroactively-labeled, already-merged PRs
mdaigle f4d58fb
Fix PR-title injection risk and backport-issue lookup race
mdaigle 12f9c6a
Restrict close-backport-issue.yml to same-repo automation branches
mdaigle fb6322f
Serialize cherry-pick-hotfix.yml runs per PR number
mdaigle 6530110
Merge main into hotfix-label automation branch
mdaigle c12bbfa
Address hotfix automation review findings
mdaigle 2996890
Pipe issue PR lookup through jq
mdaigle cfd56ec
Fix backport PR merge state lookup
mdaigle 6322a86
Fix merged PR dispatch reconciliation
mdaigle b6425ed
Check out dispatch helper before use
mdaigle e4ffac4
Recover backport issues from CLI bot identity
mdaigle 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
Some comments aren't visible on the classic Files Changed page.
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,122 @@ | ||
| #!/usr/bin/env bash | ||
| ################################################################################# | ||
| # Licensed to the .NET Foundation under one or more agreements. # | ||
| # The .NET Foundation licenses this file to you under the MIT license. # | ||
| # See the LICENSE file in the project root for more information. # | ||
| ################################################################################# | ||
| # | ||
| # close-backport-issue.sh | ||
| # | ||
| # Explicitly closes the backport issue(s) that a cherry-pick PR (created by | ||
| # cherry-pick-to-release.sh) is meant to close, after that PR merges into a | ||
| # non-default branch (e.g. a release/X.Y branch). | ||
| # | ||
| # WHY THIS EXISTS | ||
| # ---------------- | ||
| # GitHub only auto-closes an issue referenced by closing keywords (Fixes, | ||
| # Closes, Resolves) when the referencing PR merges into the repository's | ||
| # *default* branch — and for PRs targeting any other branch, it doesn't even | ||
| # populate 'closingIssuesReferences' for keyword references (only issues | ||
| # manually linked via the PR's "Development" sidebar show up there). The | ||
| # cherry-pick PRs created by cherry-pick-to-release.sh always target a | ||
| # release/X.Y branch, so their "Fixes #<backport issue>" text is purely | ||
| # cosmetic and gives the GitHub API nothing to report. This script closes the | ||
| # gap by reading the "<!-- backport-issue-numbers: ... -->" marker that | ||
| # lookup_backport_issue() (in cherry-pick-to-release.sh) embeds in the PR | ||
| # body, and closing each issue named there explicitly. Using an explicit | ||
| # marker (rather than any closing keyword found in the PR body) also means | ||
| # this only ever closes issues our own automation created and recorded, never | ||
| # an issue a human happens to reference with "Fixes #N" in an unrelated, | ||
| # manually-authored release-branch PR. | ||
| # | ||
| # OVERVIEW | ||
| # -------- | ||
| # 1. Read the merged PR's body and extract the issue numbers recorded in | ||
| # its "<!-- backport-issue-numbers: ... -->" marker, if any. | ||
| # | ||
| # 2. For each such issue that is still open, close it with a comment | ||
| # linking back to the merged PR. | ||
| # | ||
| # This is a no-op (and not an error) when the PR has no marker, or when every | ||
| # referenced issue is already closed. | ||
| # | ||
| # REQUIRED ENVIRONMENT VARIABLES | ||
| # ------------------------------ | ||
| # PR_NUMBER The pull request number that just merged. | ||
| # GH_TOKEN GitHub token for 'gh' CLI authentication. | ||
| # GITHUB_REPOSITORY Owner/repo (e.g. "dotnet/SqlClient"). Set by Actions. | ||
| # | ||
| # OUTPUTS | ||
| # ------- | ||
| # Closes zero or more issues in this repository. | ||
| # | ||
| # USAGE | ||
| # Called from the close-backport-issue.yml workflow. Can also be run | ||
| # locally: | ||
| # | ||
| # export PR_NUMBER=4750 | ||
| # export GH_TOKEN="ghp_..." | ||
| # export GITHUB_REPOSITORY="dotnet/SqlClient" | ||
| # bash .github/scripts/close-backport-issue.sh | ||
| # | ||
| ################################################################################# | ||
| set -euo pipefail | ||
|
|
||
| # -- Runtime help ------------------------------------------------------------- | ||
| if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then | ||
| # Print the header comment block (between the license banner and the | ||
| # closing banner), stripping the leading '# ' prefix. | ||
| awk '/^#{2,}$/ { n++; next } n == 2 { sub(/^# ?/, ""); print }' "$0" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # -- Input validation --------------------------------------------------------- | ||
| : "${PR_NUMBER:?PR_NUMBER environment variable is required}" | ||
| : "${GITHUB_REPOSITORY:?GITHUB_REPOSITORY environment variable is required}" | ||
|
|
||
| echo "Pull request: #${PR_NUMBER}" | ||
|
|
||
| # -- Step 1: Extract backport issue numbers from the PR body's marker -------- | ||
| PR_BODY=$(gh pr view "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" \ | ||
| --json body --jq '.body') | ||
|
|
||
| # The marker line looks like: <!-- backport-issue-numbers: 123 456 --> | ||
| MARKER_LINE=$(grep -o '<!-- *backport-issue-numbers:[0-9 ]*-->' <<< "${PR_BODY}" || true) | ||
|
|
||
| if [[ -z "${MARKER_LINE}" ]]; then | ||
| echo "No backport-issue-numbers marker found on #${PR_NUMBER}. Nothing to close." | ||
| exit 0 | ||
| fi | ||
|
|
||
| CLOSING_ISSUES=$(grep -o '[0-9]\+' <<< "${MARKER_LINE}") | ||
|
|
||
| echo "Backport issue numbers: ${CLOSING_ISSUES}" | ||
|
|
||
| # -- Step 2: Close each referenced issue that is still open ------------------- | ||
| CLOSED_ANY=0 | ||
| while IFS= read -r issue_number; do | ||
| [[ -z "${issue_number}" ]] && continue | ||
|
mdaigle marked this conversation as resolved.
Resolved
|
||
|
|
||
| # A real API/permission failure here must not be swallowed and mistaken for | ||
| # "issue doesn't exist" — surface it loudly instead of silently skipping. | ||
| if ! issue_state=$(gh issue view "${issue_number}" --repo "${GITHUB_REPOSITORY}" \ | ||
| --json state --jq '.state'); then | ||
| echo "::error::Failed to look up state for issue #${issue_number}." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ "${issue_state}" != "OPEN" ]]; then | ||
| echo "Issue #${issue_number} is already $(tr '[:upper:]' '[:lower:]' <<< "${issue_state}"). Skipping." | ||
| continue | ||
| fi | ||
|
|
||
| echo "Closing issue #${issue_number} (referenced by merged PR #${PR_NUMBER})." | ||
| gh issue close "${issue_number}" --repo "${GITHUB_REPOSITORY}" \ | ||
| --reason completed \ | ||
| --comment "Closed by #${PR_NUMBER}, which merged into a non-default branch. GitHub only auto-closes issues for PRs merged into the default branch, so this was closed explicitly." | ||
| CLOSED_ANY=1 | ||
| done <<< "${CLOSING_ISSUES}" | ||
|
|
||
| if [[ "${CLOSED_ANY}" -eq 0 ]]; then | ||
| echo "All referenced issues were already closed." | ||
| fi | ||
Oops, something went wrong.
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.