Skip to content

Commit 5983693

Browse files
[Backport 8.19] ci: use ephemeral token for backport action (#1048)
ci: use ephemeral token for backport action (#1047) * ci: use ephemeral token for backport action * uses ephemeral token so that backport PRs still trigger GitHub Actions checks * uses `pull_request_target` so that backporting PRs from forked repos works * ci: update fetch-github-token action to specific commit version (best practice) * ci: restrict backport action to only react to merged PRs, and backport labels (cherry picked from commit 39f8a22) Co-authored-by: Matt Devy <32791943+MattDevy@users.noreply.github.com>
1 parent ef44da2 commit 5983693

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

.github/workflows/backport.yml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,44 @@
1+
# See: https://github.com/tibdex/backport/blob/main/.github/workflows/backport.yml
12
name: Backport
3+
24
on:
3-
pull_request:
5+
pull_request_target:
46
types:
57
- closed
68
- labeled
79

10+
permissions:
11+
contents: read
12+
id-token: write
13+
814
jobs:
915
backport:
16+
permissions:
17+
contents: write
18+
pull-requests: write
19+
issues: write
20+
id-token: write
1021
runs-on: ubuntu-latest
22+
# Only react to merged PRs for security reasons.
23+
# See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target.
24+
if: >
25+
github.event.pull_request.merged
26+
&& (
27+
github.event.action == 'closed'
28+
|| (
29+
github.event.action == 'labeled'
30+
&& contains(github.event.label.name, 'backport')
31+
)
32+
)
1133
name: Backport
1234
steps:
35+
- name: Fetch ephemeral GitHub token
36+
id: fetch-token
37+
uses: elastic/ci-gh-actions/fetch-github-token@8a7604dfdd4e7fe21f969bfe9ff96e17635ea577 # v1.0.0
38+
with:
39+
vault-instance: "ci-prod"
40+
1341
- name: Backport
14-
uses: tibdex/backport@v1
42+
uses: tibdex/backport@9565281eda0731b1d20c4025c43339fb0a23812e # v2.0.4
1543
with:
16-
github_token: ${{ secrets.GITHUB_TOKEN }}
44+
github_token: ${{ steps.fetch-token.outputs.token }}

0 commit comments

Comments
 (0)