Skip to content

Commit 6b34f38

Browse files
authored
better notifications (#8714)
1 parent 143e5c3 commit 6b34f38

File tree

2 files changed

+86
-8
lines changed

2 files changed

+86
-8
lines changed

.github/workflows/release-patch-1-create-pr.yml

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,76 @@ jobs:
6666
permission-contents: 'write'
6767

6868
- name: 'Create Patch for Stable'
69+
id: 'create_patch_stable'
6970
if: "github.event.inputs.channel == 'stable'"
7071
env:
7172
GH_TOKEN: '${{ steps.generate_token.outputs.token }}'
72-
run: 'node scripts/create-patch-pr.js --commit=${{ github.event.inputs.commit }} --channel=stable --dry-run=${{ github.event.inputs.dry_run }}'
73+
continue-on-error: true
74+
run: |
75+
node scripts/create-patch-pr.js --commit=${{ github.event.inputs.commit }} --channel=stable --dry-run=${{ github.event.inputs.dry_run }} > patch_output.log 2>&1
76+
echo "EXIT_CODE=$?" >> "$GITHUB_OUTPUT"
77+
cat patch_output.log
7378
7479
- name: 'Create Patch for Preview'
75-
id: 'create_patch'
80+
id: 'create_patch_preview'
81+
if: "github.event.inputs.channel != 'stable'"
7682
env:
7783
GH_TOKEN: '${{ steps.generate_token.outputs.token }}'
78-
run: 'node scripts/create-patch-pr.js --commit=${{ github.event.inputs.commit }} --channel=${{ github.event.inputs.channel }} --dry-run=${{ github.event.inputs.dry_run }}'
84+
continue-on-error: true
85+
run: |
86+
node scripts/create-patch-pr.js --commit=${{ github.event.inputs.commit }} --channel=${{ github.event.inputs.channel }} --dry-run=${{ github.event.inputs.dry_run }} > patch_output.log 2>&1
87+
echo "EXIT_CODE=$?" >> "$GITHUB_OUTPUT"
88+
cat patch_output.log
7989
8090
- name: 'Comment on Original PR'
8191
if: '!inputs.dry_run && inputs.original_pr'
8292
env:
8393
GH_TOKEN: '${{ steps.generate_token.outputs.token }}'
8494
run: |
85-
gh pr comment ${{ github.event.inputs.original_pr }} --body "🚀 Patch PR created!
95+
# Determine which step ran based on channel
96+
if [ "${{ github.event.inputs.channel }}" = "stable" ]; then
97+
EXIT_CODE="${{ steps.create_patch_stable.outputs.EXIT_CODE }}"
98+
else
99+
EXIT_CODE="${{ steps.create_patch_preview.outputs.EXIT_CODE }}"
100+
fi
101+
102+
# Check if patch output exists and contains branch info
103+
if [ -f patch_output.log ]; then
104+
if grep -q "already exists" patch_output.log && grep -q "already contains commit" patch_output.log; then
105+
# Branch exists and has the commit
106+
BRANCH=$(grep "Hotfix branch" patch_output.log | grep "already exists" | sed 's/.*Hotfix branch \(.*\) already exists.*/\1/')
107+
gh pr comment ${{ github.event.inputs.original_pr }} --body "ℹ️ Patch branch already exists!
108+
109+
The commit is already included in the existing patch branch: \`$BRANCH\`
110+
111+
Check if there's already a PR for this patch: https://github.com/${{ github.repository }}/pulls?q=is%3Apr+is%3Aopen+head%3A$BRANCH"
112+
113+
elif grep -q "already exists" patch_output.log; then
114+
# Branch exists but doesn't have the commit
115+
BRANCH=$(grep "Hotfix branch" patch_output.log | grep "already exists" | sed 's/.*Hotfix branch \(.*\) already exists.*/\1/')
116+
gh pr comment ${{ github.event.inputs.original_pr }} --body "⚠️ Patch branch exists but needs update!
117+
118+
A patch branch \`$BRANCH\` exists but doesn't contain this commit. You may need to manually handle this conflict.
119+
120+
View the existing branch: https://github.com/${{ github.repository }}/tree/$BRANCH"
121+
122+
elif [ "$EXIT_CODE" = "0" ]; then
123+
# Success - new branch created
124+
gh pr comment ${{ github.event.inputs.original_pr }} --body "🚀 Patch PR created!
125+
126+
The patch release PR for this change has been created. Please review and approve it to complete the patch release:
127+
128+
View all patch PRs: https://github.com/${{ github.repository }}/pulls?q=is%3Apr+is%3Aopen+label%3Apatch"
129+
else
130+
# Other error
131+
gh pr comment ${{ github.event.inputs.original_pr }} --body "❌ Patch creation failed!
86132
87-
The patch release PR for this change has been created. Please review and approve it to complete the patch release:
133+
There was an error creating the patch. Please check the workflow logs for details:
134+
https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
135+
fi
136+
else
137+
gh pr comment ${{ github.event.inputs.original_pr }} --body "❌ Patch creation failed!
88138
89-
View all patch PRs: https://github.com/${{ github.repository }}/pulls?q=is%3Apr+is%3Aopen+label%3Apatch"
139+
No output was generated. Please check the workflow logs:
140+
https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
141+
fi

scripts/create-patch-pr.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,27 @@ async function main() {
5959
console.log(`Release branch ${releaseBranch} already exists.`);
6060
}
6161

62+
// Check if hotfix branch already exists
63+
if (branchExists(hotfixBranch)) {
64+
console.log(`Hotfix branch ${hotfixBranch} already exists.`);
65+
66+
// Check if the existing branch already has this commit
67+
const hasCommit = run(
68+
`git branch --contains ${commit} | grep ${hotfixBranch}`,
69+
dryRun,
70+
false,
71+
);
72+
if (hasCommit) {
73+
console.log(`Branch ${hotfixBranch} already contains commit ${commit}.`);
74+
return { existingBranch: hotfixBranch, hasCommit: true };
75+
} else {
76+
console.log(
77+
`Branch ${hotfixBranch} exists but doesn't contain commit ${commit}.`,
78+
);
79+
return { existingBranch: hotfixBranch, hasCommit: false };
80+
}
81+
}
82+
6283
// Create the hotfix branch from the release branch.
6384
console.log(
6485
`Creating hotfix branch ${hotfixBranch} from ${releaseBranch}...`,
@@ -94,9 +115,11 @@ async function main() {
94115
console.log(`Pull Request Command: ${prCommand}`);
95116
console.log('---------------------');
96117
}
118+
119+
return { newBranch: hotfixBranch, created: true };
97120
}
98121

99-
function run(command, dryRun = false) {
122+
function run(command, dryRun = false, throwOnError = true) {
100123
console.log(`> ${command}`);
101124
if (dryRun) {
102125
return;
@@ -105,7 +128,10 @@ function run(command, dryRun = false) {
105128
return execSync(command).toString().trim();
106129
} catch (err) {
107130
console.error(`Command failed: ${command}`);
108-
throw err;
131+
if (throwOnError) {
132+
throw err;
133+
}
134+
return null;
109135
}
110136
}
111137

0 commit comments

Comments
 (0)