Skip to content

Extend hotfix label automation to cover issues - #4741

Open
mdaigle wants to merge 27 commits into
dotnet:mainfrom
mdaigle:mdaigle-hotfix-label-issue-automation
Open

mdaigle wants to merge 27 commits into
dotnet:mainfrom
mdaigle:mdaigle-hotfix-label-issue-automation

Conversation

@mdaigle

@mdaigle mdaigle commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Description

Extends the existing "Hotfix X.Y.Z" PR cherry-pick automation to also cover issues, so backport tracking issues are created and linked automatically instead of manually (as done for #4737/#4738).

  • create-backport-issue.sh + hotfix-label-issue.yml: labeling a parent issue Hotfix X.Y.Z creates a child backport issue milestoned to that version and links it as a native GitHub sub-issue. Includes duplicate detection (by milestone or title prefix) so a re-fired labeled event won't create a second backport issue.
  • sync-hotfix-label-to-pr.sh + sync-hotfix-label-to-pr.yml: when a PR's closing issue references include a Hotfix-labeled issue, that label is copied onto the PR, feeding it into the existing cherry-pick automation.
  • cherry-pick-to-release.sh (extended): looks up the milestone-matched backport issue via the original PR's closing references and appends Fixes #N to the auto-generated cherry-pick PR body (both the clean and conflict paths), so merging the backport PR automatically closes the backport issue.
  • Added issues: read permission to cherry-pick-hotfix.yml for the new lookup.

End-to-end flow: label an issue Hotfix 7.1.1 -> backport issue #N created and sub-issued -> PR opened closing the parent issue picks up the Hotfix 7.1.1 label -> merging that PR triggers the existing cherry-pick automation -> generated backport PR links Fixes #N.

Issues

Not tied to a specific bug fix; this generalizes the manual backport-issue pattern used for #4737 and #4738 into automation.

Testing

Added bats coverage for all new/changed behavior, run locally with bats-core:

  • create-backport-issue.bats (10 tests): label validation, duplicate detection, milestone lookup, issue creation, sub-issue linking.
  • sync-hotfix-label-to-pr.bats (7 tests): closing-reference parsing, label collection/dedup, idempotent sync.
  • cherry-pick-to-release.bats (19 tests, 4 new): backport-issue lookup and Fixes #N linking in both the clean and conflict PR-body paths; all 16 pre-existing tests still pass unmodified.

Also ran shellcheck against the new/modified scripts with no new findings.

Guidelines

Please review the contribution guidelines before submitting a pull request:

- create-backport-issue.sh + hotfix-label-issue.yml: labeling an issue
  "Hotfix X.Y.Z" creates a child backport issue milestoned to that
  version and links it as a native GitHub sub-issue.
- sync-hotfix-label-to-pr.sh + sync-hotfix-label-to-pr.yml: copies the
  Hotfix label onto a PR when its closing issue references include a
  Hotfix-labeled issue, feeding the existing cherry-pick automation.
- cherry-pick-to-release.sh: looks up the milestone-matched backport
  issue via the PR's closing references and appends "Fixes #N" to the
  generated cherry-pick PR body (both clean and conflict paths), so
  merging it auto-closes the backport issue.
- Added bats tests for all new/changed behavior and updated the tests
  README.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@mdaigle
mdaigle requested review from a team and a balanced review from Copilot September 23, 2026 18:52
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board Sep 23, 2026
@mdaigle mdaigle added this to the 8.0.0-preview1 milestone Sep 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Missing checkout permissions and broken or ambiguous issue lookups prevent reliable end-to-end automation.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 6 Medium severity

Open (6)
What changed in this PR

Extends hotfix automation from pull requests to linked issues and backport tracking.

Changes:

  • Creates milestone-targeted backport sub-issues.
  • Propagates issue hotfix labels to closing PRs.
  • Links generated cherry-pick PRs to backport issues.
File Description
.github/​workflows/​sync-hotfix-label-to-pr.yml Runs issue-label synchronization for PRs.
.github/​workflows/​hotfix-label-issue.yml Triggers backport issue creation.
.github/​workflows/​cherry-pick-hotfix.yml Grants issue lookup permission.
.github/​scripts/​sync-hotfix-label-to-pr.sh Copies hotfix labels from closing issues.
.github/​scripts/​create-backport-issue.sh Creates and links backport sub-issues.
.github/​scripts/​cherry-pick-to-release.sh Adds backport closure links to cherry-pick PRs.
.github/​scripts/​tests/​sync-hotfix-label-to-pr.bats Tests label synchronization.
.github/​scripts/​tests/​create-backport-issue.bats Tests backport issue creation.
.github/​scripts/​tests/​cherry-pick-to-release.bats Tests backport issue lookup and linking.
.github/​scripts/​tests/​README.md Documents the expanded Bats suite.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Live-testing lookup_backport_issue() against real GitHub issues/PRs
revealed that 'gh api --jq --arg v "$version" ...' silently fails
(gh's --jq flag takes a single query string; it isn't a passthrough
to the jq binary's own flags). The stderr redirect masked the failure,
so the function always returned no match.

Fix by escaping and interpolating the version directly into the jq
filter string instead of relying on --arg.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 23, 2026 20:29
…error handling, exact label matching, workflow permissions

- cherry-pick-to-release.sh / sync-hotfix-label-to-pr.sh: filter
  closingIssuesReferences by repository before extracting issue numbers, so a
  cross-repo closing reference can't collide with a same-numbered local issue.
- create-backport-issue.sh: fail loudly instead of silently proceeding when
  the sub-issues duplicate-guard lookup itself fails, to avoid creating a
  duplicate backport issue on a rerun after a transient API error.
- sync-hotfix-label-to-pr.sh: require the exact "Hotfix X.Y.Z" grammar
  when collecting labels from referenced issues, matching the validation used
  elsewhere, instead of accepting any "Hotfix "-prefixed label.
- hotfix-label-issue.yml / sync-hotfix-label-to-pr.yml: add the missing
  'contents: read' permission needed by actions/checkout.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Retry safety and multi-issue handling can currently create duplicate tracking issues or leave valid backports open.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity · 6 Medium severity

Open (7)
Previously missed (3)

In code that hasn't changed since last review

Medium severity Process all matching parent issues before returning

.github/​scripts/​cherry-pick-to-release.sh:202

Returning after the first match leaves other backport issues open when one PR closes multiple Hotfix-labeled parent issues for the same version. Accumulate one Fixes line per matching parent and finish the loop instead.

Medium severity Fail on milestone API errors before using fallback

.github/​scripts/​create-backport-issue.sh:125

Because this API call is the left side of an if pipeline, an API failure is treated exactly like a missing milestone. The workflow then creates an unmilestoned issue despite the milestone potentially existing. Fetch the titles first so set -e stops on API failure, and only use the fallback after a successful lookup.

Medium severity Recover orphaned issues after partial creation failure

.github/​scripts/​create-backport-issue.sh:154

Issue creation is committed before the child is linked. If either the child-ID lookup or sub-issue POST fails, rerunning checks only linked sub-issues, does not find this orphan, and creates another backport issue. Before creating, detect and relink an existing issue with this generated title/parent marker (or otherwise persist recovery state) so retries remain idempotent after partial failure.

Copilot AI review requested due to automatic review settings September 23, 2026 20:37
…ck-then-create race

Duplicate detection is a check-then-create sequence with no atomic guard.
Two deliveries/re-runs for the same issue+label could both observe no
existing child and create duplicates. A job-level concurrency group keyed
by issue number and label serializes runs so a second run always re-checks
after the first has finished.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Reliability gaps can miss labels, create duplicate orphan issues, or leave some backport issues unclosed.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (7)
Previously missed (4)

In code that hasn't changed since last review

Medium severity Process all matching Hotfix child issues

.github/​scripts/​cherry-pick-to-release.sh:214

A PR can close multiple Hotfix-labeled issues, but this returns after the first matching child, so only one generated backport issue gets a Fixes line and the others remain open after the cherry-pick PR merges. Accumulate every version-matched child instead of stopping at the first.

Medium severity Use fixed-string matching for exact versions

.github/​scripts/​create-backport-issue.sh:137

This exact-version check is using a regular expression, so the dots in 7.1.1 match arbitrary characters; for example, milestone 7x1y1 is treated as a match and the subsequent create call then requests nonexistent milestone 7.1.1. Use fixed-string matching.

Medium severity Recover orphaned backport issues on rerun

.github/​scripts/​create-backport-issue.sh:166

After this issue is created, a failure while resolving its ID or linking it leaves an orphan. On rerun, the duplicate guard only searches existing sub-issues, so it cannot find that orphan and creates another backport issue. Make the create/link sequence recoverable by discovering and linking a previously created matching child before creating a new one.

Medium severity Sync labels to already-open closing PRs

.github/​workflows/​sync-hotfix-label-to-pr.yml:25

If an issue receives its Hotfix label after a closing PR is already open, none of these PR events is emitted. The backport child is created, but the PR never receives the label and can merge without triggering the cherry-pick workflow. Handle the issues:labeled path by finding and labeling existing closing PRs (or dispatching a reusable sync workflow), not only future PR events.

Copilot AI review requested due to automatic review settings September 23, 2026 20:43
The trailing '|| true' covered the whole 'gh issue view | grep' pipeline, so
a real gh API/permission failure was indistinguishable from an issue simply
having no Hotfix labels, and the run would succeed without labeling the PR.
Capture 'gh issue view' separately and fail loudly on its error; only grep's
no-match exit status is now tolerated.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

API failures can silently prevent synchronization or create duplicate orphan issues, and multi-issue PRs close only one backport issue.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (1)
Previously missed (2)

In code that hasn't changed since last review

Medium severity Prevent orphaned duplicate child issues after linking failures

.github/​scripts/​create-backport-issue.sh:180

Issue creation and sub-issue linking are separate writes. If this POST fails after creation, the child remains orphaned; a rerun checks only linked sub-issues and creates another child, defeating duplicate protection. Before creating, detect and reuse an existing matching issue that references this parent, or otherwise make the failed link recoverable on rerun.

Low severity Update reported test count from 10 to 11

.github/​scripts/​tests/​README.md:125

This table reports 10 tests, but create-backport-issue.bats currently contains 11 @test cases. Update the count so the test inventory is accurate.

Copilot AI review requested due to automatic review settings September 23, 2026 20:48
Document how hotfix-label-issue.yml, sync-hotfix-label-to-pr.yml, and
cherry-pick-hotfix.yml work together, with a Mermaid diagram of the
end-to-end flow from labeling an issue through to the linked
cherry-pick PR. Link the new doc from each workflow's header comment.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
lookup_backport_issue() returned as soon as it found a matching
sub-issue for the first closing issue reference, so a PR that closes
multiple Hotfix-labeled parent issues for the same release only linked
one backport issue and left the others open. Accumulate a Fixes line
for every closing issue that has a matching backport sub-issue instead
of stopping at the first match.

Also simplify the hotfix-label-automation.md diagram to show actions
and results rather than individual workflow/script names.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Workflow-source placement and backport reconciliation defects can block CI or leave duplicate and unclosed tracking issues.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (1)
Previously missed (6)

In code that hasn't changed since last review

Low severity Replace non-ASCII punctuation in source comments

.github/​scripts/​cherry-pick-to-release.sh:170

This changed block adds literal non-ASCII em dashes to source comments. Repository policy requires Unicode escapes for non-ASCII source characters (policy/coding-style.md:56-58); use ASCII punctuation in the added comments.

Low severity Replace non-ASCII comment punctuation with ASCII

.github/​scripts/​create-backport-issue.sh:27

This file introduces literal non-ASCII punctuation in comments, including this em dash. Repository policy requires Unicode escapes for non-ASCII source characters (policy/coding-style.md:56-58); use ASCII punctuation throughout this new script.

This issue also appears on line 176 of the same file.

Low severity Replace non-ASCII comment punctuation with ASCII

.github/​scripts/​sync-hotfix-label-to-pr.sh:66

This file introduces literal non-ASCII punctuation in comments, including this em dash. Repository policy requires Unicode escapes for non-ASCII source characters (policy/coding-style.md:56-58); use ASCII punctuation throughout this new script.

Low severity Replace box-drawing separator with ASCII

.github/​scripts/​tests/​cherry-pick-to-release.bats:300

This added separator contains literal non-ASCII box-drawing characters, contrary to policy/coding-style.md:56-58. Use an ASCII-only comment separator.

Low severity Replace non-ASCII test comments with ASCII

.github/​scripts/​tests/​create-backport-issue.bats:92

The new test file uses literal box-drawing characters and em dashes in comments. Repository policy requires Unicode escapes for non-ASCII source characters (policy/coding-style.md:56-58); replace these comment separators and punctuation with ASCII throughout the file.

Low severity Replace non-ASCII test comments with ASCII

.github/​scripts/​tests/​sync-hotfix-label-to-pr.bats:94

The new test file uses literal box-drawing characters and em dashes in comments. Repository policy requires Unicode escapes for non-ASCII source characters (policy/coding-style.md:56-58); replace these comment separators and punctuation with ASCII throughout the file.

Comment thread .github/hotfix-label-automation.md Resolved
Copilot AI review requested due to automatic review settings September 23, 2026 20:54
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

@paulmedynski paulmedynski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also some unaddressed Copilot findings:

  • Copied Hotfix labels become stale when closing references or source labels are removed.
    • Unaddressed: synchronization only adds labels.
  • Later-created backport children are not added to an existing cherry-pick PR.
    • Unaddressed: reconciliation skips versions with an existing branch or PR rather than updating their issue markers.

@github-project-automation github-project-automation Bot moved this from To triage to Waiting for customer in SqlClient Board Oct 21, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 23, 2026 01:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved reconciliation, recovery, and synchronization defects can skip requested hotfixes or create duplicate backport records.

1 open issue
3 previously missed issues

In code that hasn't changed since last review

Medium severity Match CLI app-prefixed bot author identity

.github/​scripts/​create-backport-issue.sh:155

gh issue list --json author serializes bot logins with an app/ prefix (Author.MarshalJSON in the GitHub CLI), rather than the raw REST login github-actions[bot]. This predicate therefore rejects the Actions-created orphan after a successful issue creation followed by a failed link, so a rerun creates another child. Match the CLI's app/github-actions identity and update the recovery fixture in create-backport-issue.bats to use CLI-shaped author data.

Medium severity Abort reconciliation when duplicate PR lookup fails

.github/​scripts/​extract-hotfix-versions.sh:105

cherry_pick_already_exists is called as an if condition, which disables Bash's errexit throughout the function. If gh pr list fails, existing_pr is empty and the helper reports no duplicate instead of stopping. Reconciliation can then recreate a closed backport PR whose branch was deleted. A focused shell check confirms this path proceeds with status zero. Explicitly abort on lookup failure; add an API-failure regression case and give the non-hotfix-label reconciliation test a successful lookup stub.

Medium severity Recheck merge status after label sync and reconcile

.github/​scripts/​sync-hotfix-label-to-pr.sh:131

A PR can merge after the triggering PR snapshot (or the issue-side query reporting OPEN) but before this label addition. The merge event then has no Hotfix label, while this later GITHUB_TOKEN mutation cannot trigger another workflow run. The issue-side caller also skips dispatch because it uses the earlier OPEN state. Recheck merge status after syncing labels in this shared script and dispatch reconciliation if merged, so both entry points handle this ordering. Coordinate that dispatch with the issue-side caller and cover the merge-during-sync case.

Review effort: Balanced

@paulmedynski paulmedynski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot seems to be correct.

Add regression coverage for workflow dispatch PR state resolution.\n\nCo-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 23, 2026 12:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Dispatch reconciliation lacks a required checkout, and orphan recovery rejects the CLI-formatted bot identity, allowing duplicate backport issues.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Accept GitHub CLI's app-prefixed bot identity during orphan recovery

.github/​scripts/​create-backport-issue.sh:155

[P2] Accept the GitHub CLI's exported bot identity during orphan recovery. Its Author.MarshalJSON prefixes bot logins with app/, so this comparison against only github-actions[bot] rejects the Actions bot's issue. If creation succeeds but linking fails, a rerun misses that orphan and creates a duplicate. Accept the CLI-formatted identity and update the recovery test fixture to exercise that format rather than only the unprefixed login.

1 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 23, 2026 13:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Merge-time label synchronization can lose backport requests, and failed PR lookups can bypass duplicate protection.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Abort when PR-existence lookup fails

.github/​scripts/​extract-hotfix-versions.sh:105

[P2] Abort when the PR-existence lookup fails. This helper is called as an if condition, which disables Bash's set -e handling throughout the function. A failed gh pr list therefore falls through to return 1 and schedules the version as if no backport existed; for a closed backport whose branch was deleted, this can create a duplicate. Explicitly exit on lookup failure rather than treating it as a successful empty result.

Medium severity Recheck merged state after label synchronization

.github/​scripts/​sync-hotfix-label-to-pr.sh:132

[P2] Recheck merged state after synchronizing labels. If a PR merges before this mutation, its closed event can lack the Hotfix label, while adding the label afterward with GITHUB_TOKEN cannot trigger the cherry-pick workflow. This affects both PR-triggered runs and issue-triggered runs whose earlier GraphQL lookup recorded OPEN. Move merged-state reconciliation into this shared script after synchronization: query the current state and dispatch cherry-pick-hotfix.yml for merged PRs, including retries where the labels are already present, and cover the OPEN-to-MERGED ordering in tests.

1 resolved since last review

Review effort: Balanced

Add coverage for both Actions bot login representations.\n\nCo-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 23, 2026 15:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

A merge-time label synchronization race can miss cherry-picks, and failed PR lookups can bypass duplicate detection.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Abort on failed existing-PR lookup

.github/​scripts/​extract-hotfix-versions.sh:105

[P2] Abort when the existing-PR lookup fails. Calling this helper as an if condition disables Bash's errexit throughout the function. A failed gh pr list therefore leaves existing_pr empty and falls through to return 1, making the version eligible instead of stopping as the previous top-level assignment did. If an earlier cherry-pick PR still exists but its branch was deleted, an API failure can bypass the remaining duplicate guard. Explicitly exit on lookup failure and add a regression test for an absent branch followed by a failed PR lookup.

Medium severity Reconcile merged PRs after label sync

.github/​scripts/​sync-hotfix-label-to-pr.sh:137

[P2] Recheck the live merge state after syncing labels. A queued PR-side sync can add the Hotfix label after the PR merges, so the merge event contains no Hotfix label. This GITHUB_TOKEN mutation cannot trigger the cherry-pick workflow's labeled event, leaving the backport unprocessed. The issue-side caller has the same gap when its earlier OPEN snapshot becomes stale. Dispatch reconciliation from this shared script when the post-sync state is MERGED, including when the label was already present on a retry. Add regression coverage for a merge between the initial lookup and label mutation; the issue-side caller's redundant dispatch can then be removed.

1 resolved since last review

Review effort: Balanced

@paulmedynski paulmedynski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the new Copilot findings are legitimate. But beware that you may be descending into a robot battle, and we may want to just merge to get 99% of the functionality without trying to achieve perfection.

@mdaigle mdaigle removed this from the 8.0.0-preview1 milestone Oct 29, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Waiting for customer

Development

Successfully merging this pull request may close these issues.

4 participants