Skip to content

Commit 420b45b

Browse files
authored
ci: Add comment with explanation when a release conflict is detected (#7162)
## Explanation This adds some logic to #7114 to add a comment to a pull request if a conflict was detected, either in the pull request checks or in the merge queue. Old comments will be hidden automatically as well: <img width="933" height="475" alt="image" src="https://github.com/user-attachments/assets/94153654-9aea-4b97-b67a-19205f8fdb7c" /> ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [ ] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Enhances the release-conflict check to post a PR comment (minimizing old ones), expose outputs for conflicted package names, and conditionally fail; updates workflow permissions. > > - **CI / Release conflict checks**: > - **Action `check-release`** (`.github/actions/check-release/action.yml`): > - Emits outputs `package-names` and `has-conflicts` instead of exiting immediately upon conflicts; final separate step now fails when conflicts exist. > - Adds `id: check-release` to expose outputs. > - Posts a PR comment listing conflicted packages and notes merge-queue context; hides previous such comments via GraphQL minimization. > - **Workflow** (`.github/workflows/main.yml`): > - Grants `contents: read` and `pull-requests: write` permissions to `check-release` job to allow commenting. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 3fe207d. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 7bdb9c1 commit 420b45b

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

.github/actions/check-release/action.yml

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ runs:
3030
fi
3131
3232
- name: Check commits for changes in released packages
33+
id: check-release
3334
shell: bash
3435
env:
3536
GH_TOKEN: ${{ github.token }}
@@ -77,11 +78,84 @@ runs:
7778
fi
7879
7980
if [ ${#CONFLICTS[@]} -ne 0 ]; then
81+
PACKAGE_NAMES=()
82+
8083
for conflict in "${CONFLICTS[@]}"; do
8184
package_name=$(jq -r ".name" "$conflict/package.json")
85+
PACKAGE_NAMES+=("$package_name")
8286
echo "::error::Release conflict detected in \`$package_name\`. This package is being released in this PR, but files in the package were also modified ahead of this PR. Please ensure that all changes are included in the release."
8387
done
84-
exit 1
88+
89+
PACKAGE_NAMES_JSON=$(printf '%s\n' "${PACKAGE_NAMES[@]}" | jq -R . | jq -s -c .)
90+
echo "package-names=$PACKAGE_NAMES_JSON" >> "$GITHUB_OUTPUT"
91+
echo "has-conflicts=true" >> "$GITHUB_OUTPUT"
8592
else
8693
echo "✅ No release conflicts detected."
8794
fi
95+
96+
- name: Hide previous comments
97+
uses: actions/github-script@v8
98+
env:
99+
PR_NUMBER: ${{ inputs.pull-request }}
100+
with:
101+
script: |
102+
const comments = await github.paginate(github.rest.issues.listComments, {
103+
owner: context.repo.owner,
104+
repo: context.repo.repo,
105+
issue_number: process.env.PR_NUMBER,
106+
});
107+
108+
for (const comment of comments) {
109+
if (comment.body.includes('<!-- Pull request release conflict comment -->')) {
110+
await github.graphql(`
111+
mutation($commentId: ID!, $classifier: ReportedContentClassifiers!) {
112+
minimizeComment(input: {subjectId: $commentId, classifier: $classifier}) {
113+
minimizedComment {
114+
isMinimized
115+
}
116+
}
117+
}
118+
`, {
119+
commentId: comment.node_id,
120+
classifier: 'OUTDATED',
121+
});
122+
}
123+
}
124+
125+
- name: Reply on pull request
126+
if: steps.check-release.outputs.has-conflicts == 'true'
127+
uses: actions/github-script@v8
128+
env:
129+
PACKAGE_NAMES: ${{ steps.check-release.outputs.package-names }}
130+
PR_NUMBER: ${{ inputs.pull-request }}
131+
with:
132+
script: |
133+
const packageNames = JSON.parse(process.env.PACKAGE_NAMES);
134+
const packageList = packageNames.map(name => `- \`${name}\``).join('\n');
135+
136+
const mergeQueueNote = context.eventName === 'merge_group' ? ' while this pull request was in the merge queue' : '';
137+
138+
const body = `
139+
## Release conflict detected
140+
141+
The following packages are being released in this pull request, but files in these packages were also modified ahead of this pull request${mergeQueueNote}:
142+
143+
${packageList}
144+
145+
Please ensure that all changes are included in the release by updating this pull request, and adjusting the changelogs and version bumps as necessary.
146+
147+
<!-- Pull request release conflict comment -->
148+
`;
149+
150+
await github.rest.issues.createComment({
151+
owner: context.repo.owner,
152+
repo: context.repo.repo,
153+
issue_number: process.env.PR_NUMBER,
154+
body: body.split('\n').map(line => line.trim()).join('\n'),
155+
});
156+
157+
- name: Fail if conflicts found
158+
if: steps.check-release.outputs.has-conflicts == 'true'
159+
shell: bash
160+
run: |
161+
exit 1

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ jobs:
6767
name: Check release
6868
needs: check-workflows
6969
runs-on: ubuntu-latest
70+
permissions:
71+
contents: read
72+
pull-requests: write
7073
steps:
7174
- name: Checkout repository
7275
uses: actions/checkout@v5

0 commit comments

Comments
 (0)