Skip to content

Commit be3b7ee

Browse files
chore(ci): Add job to automate backport label creation (#2873)
### Proposed Changes Automatically create a backport label when a release branch is created * only runs when create-release-branch runs+succeeds * checks for existing label * logs success/failure ### Checklist - [ ] I have added or updated unit tests - [ ] I have added or updated integration tests (if appropriate) - [ ] I have added or updated documentation ### Testing Instructions
1 parent 7493941 commit be3b7ee

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

.github/workflows/create-release-branch.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,69 @@ jobs:
1616
secrets:
1717
APP_ID: ${{ secrets.APP_ID }}
1818
AUTOMATION_KEY: ${{ secrets.AUTOMATION_KEY }}
19+
20+
create-backport-label:
21+
needs: create-release-branch
22+
permissions:
23+
issues: write
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Create Backport PR label if it doesn't exist
27+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
28+
with:
29+
github-token: ${{ secrets.GITHUB_TOKEN }}
30+
script: |
31+
const tagName = context.payload.release?.tag_name;
32+
if (!tagName) {
33+
console.error("❌ No tag name found in the release payload");
34+
throw new Error("No tag name found");
35+
}
36+
// check if it matches vX.Y.Z format or something/vX.Y.Z
37+
const tagPattern = /^([\w/-_]+\/)?v\d+\.\d+\.\d+$/;
38+
if (!tagPattern.test(tagName)) {
39+
console.error(`❌ Tag name "${tagName}" does not match expected format`);
40+
throw new Error("Invalid tag name format");
41+
}
42+
const labelPrefix = "backport release/";
43+
// Extract the label name by removing patch version
44+
let labelName;
45+
if (tagName && tagName.includes('.')) {
46+
const lastDotIndex = tagName.lastIndexOf('.');
47+
labelName = `${labelPrefix}${tagName.substring(0, lastDotIndex)}`;
48+
} else {
49+
labelName = `${labelPrefix}${tagName}`;
50+
}
51+
52+
const labelColor = "731ddb"; // purple
53+
const labelDescription = "Backport PR to release " + tagName;
54+
55+
try {
56+
// Check if label already exists
57+
await github.rest.issues.getLabel({
58+
owner: context.repo.owner,
59+
repo: context.repo.repo,
60+
name: labelName,
61+
});
62+
console.log(`✅ Label "${labelName}" already exists`);
63+
} catch (error) {
64+
if (error.status === 404) {
65+
console.log(`🏷️ Creating label "${labelName}"`);
66+
try {
67+
await github.rest.issues.createLabel({
68+
owner: context.repo.owner,
69+
repo: context.repo.repo,
70+
name: labelName,
71+
color: labelColor,
72+
description: labelDescription,
73+
});
74+
console.log(`✅ Label "${labelName}" created`);
75+
} catch (createError) {
76+
console.error(`❌ Error creating label "${labelName}":`, createError);
77+
throw createError;
78+
}
79+
} else {
80+
console.error(`❌ Error getting label "${labelName}":`, error);
81+
throw error;
82+
}
83+
}
84+

0 commit comments

Comments
 (0)