-
Notifications
You must be signed in to change notification settings - Fork 1.5k
102 lines (90 loc) · 3.75 KB
/
Copy pathbackport-pr.yml
File metadata and controls
102 lines (90 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Backport PR
on:
pull_request:
types:
- closed
- labeled
jobs:
get-backport-targets:
name: Get backport targets
runs-on: ubuntu-latest
if: github.event.pull_request.merged
outputs:
targets: ${{ steps.get-targets.outputs.targets }}
steps:
- name: Get backport targets
id: get-targets
run: |
# For 'labeled' event, use just the added label
# For 'closed' event, use all backport labels
if [[ "${{ github.event.action }}" == "labeled" ]]; then
if [[ "${{ github.event.label.name }}" == backport/* ]]; then
echo "targets=[\"${{ github.event.label.name }}\"]" >> $GITHUB_OUTPUT
else
echo "targets=[]" >> $GITHUB_OUTPUT
fi
else
# Extract all backport/* labels as JSON array
targets=$(echo '${{ toJson(github.event.pull_request.labels.*.name) }}' | jq -c '[.[] | select(startswith("backport/"))]')
echo "targets=$targets" >> $GITHUB_OUTPUT
fi
backport:
name: Backport PR to ${{ matrix.target }}
needs: get-backport-targets
if: needs.get-backport-targets.outputs.targets != '[]' && needs.get-backport-targets.outputs.targets != ''
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: ${{ fromJson(needs.get-backport-targets.outputs.targets) }}
permissions:
id-token: write # This is required for getting the required OIDC token from GitHub
contents: write # This is required for pushing the backport branch
pull-requests: write # This is required for creating the backport PR
steps:
- name: Compute target branch
id: target
run: |
target="${{ matrix.target }}"
target_branch="${target/backport\//}"
echo "target_branch=$target_branch" >> $GITHUB_OUTPUT
- uses: DataDog/dd-octo-sts-action@96a25462dbcb10ebf0bfd6e2ccc917d2ab235b9a # v1.0.4
id: octo-sts
with:
scope: DataDog/datadog-agent
policy: self.backport-pr.create-pr
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0 # needed to get the full history of the PR
- name: Install dda
uses: ./.github/actions/install-dda
with:
features: github
- name: Run cherry-pick script
id: cherry-pick
env:
GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }}
GITHUB_EVENT_PATH: ${{ github.event_path }}
run: dda gh cherry-pick-pr --target-branch "${{ steps.target.outputs.target_branch }}"
- name: Reset cherry-pick
if: steps.cherry-pick.outputs.base != ''
run: git reset HEAD~1
- name: Create pull request
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
if: steps.cherry-pick.outputs.base != ''
with:
token: ${{ steps.octo-sts.outputs.token }}
base: ${{ steps.cherry-pick.outputs.base }}
branch: backport-${{steps.cherry-pick.outputs.original_pr_number}}-to-${{steps.cherry-pick.outputs.base}}
sign-commits: true
title: "[Backport ${{steps.cherry-pick.outputs.base}}] ${{steps.cherry-pick.outputs.original_title}}"
body: |
Backport ${{steps.cherry-pick.outputs.merge_commit_sha}} from #${{steps.cherry-pick.outputs.original_pr_number}}.
___
${{ steps.cherry-pick.outputs.original_body }}
labels: ${{ steps.cherry-pick.outputs.original_labels }},backport,bot
commit-message: |
${{ steps.cherry-pick.outputs.message }}
___
Co-authored-by: ${{ steps.cherry-pick.outputs.author }}