Skip to content

Commit cfeac2a

Browse files
authored
[tooling] Add milestone to automated backport PR (#1856)
* automatically add milestone to backport pr * pin action by hash
1 parent ebb4e0a commit cfeac2a

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

.github/workflows/backport-pr.yml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ jobs:
1616
permissions:
1717
contents: write
1818
pull-requests: write
19+
issues: write
20+
env:
21+
BRANCH_NAME: ${{ replace(github.event.label.name, 'backport/', '') }}
1922
steps:
20-
- uses: actions/create-github-app-token@21cfef2b496dd8ef5b904c159339626a10ad380e # v1.11.6
23+
- name: Create app token
24+
uses: actions/create-github-app-token@21cfef2b496dd8ef5b904c159339626a10ad380e # v1.11.6
2125
id: app-token
2226
with:
2327
app-id: ${{ secrets.DD_GITHUBOPS_TOKEN_APP_ID }}
2428
private-key: ${{ secrets.DD_GITHUBOPS_TOKEN_PRIVATE_KEY }}
25-
- uses: tibdex/backport@9565281eda0731b1d20c4025c43339fb0a23812e # v2.0.4
29+
- name: Create backport PR
30+
uses: tibdex/backport@9565281eda0731b1d20c4025c43339fb0a23812e # v2.0.4
2631
with:
2732
label_pattern: "^backport/(?<base>([^ ]+))$"
2833
labels_template: "<%= JSON.stringify([...labels, 'backport', 'bot']) %>"
@@ -34,3 +39,28 @@ jobs:
3439
___
3540
3641
<%- body %>
42+
43+
- name: Parse backport PR number
44+
run: |
45+
echo "CREATED=${{ steps.backport.outputs.created_pull_requests }}" >> $GITHUB_ENV
46+
PR_NUM=$(echo "$CREATED" | jq -r ".\"${BRANCH_NAME}\"")
47+
echo "PR_NUMBER=$PR_NUM" >> $GITHUB_ENV
48+
49+
- name: Copy milestone to backport PR
50+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
51+
env:
52+
PR_NUMBER: ${{ env.PR_NUMBER }}
53+
with:
54+
github-token: ${{ steps.app-token.outputs.token }}
55+
script: |
56+
const orig = context.payload.pull_request;
57+
if (!orig.milestone) {
58+
console.log('No milestone to copy.');
59+
return;
60+
}
61+
await github.rest.issues.update({
62+
owner: context.repo.owner,
63+
repo: context.repo.repo,
64+
issue_number: parseInt(process.env.PR_NUMBER, 10)
65+
milestone: orig.milestone.number
66+
});

0 commit comments

Comments
 (0)