-
Notifications
You must be signed in to change notification settings - Fork 1.4k
106 lines (94 loc) · 3.68 KB
/
Copy pathbackport.yml
File metadata and controls
106 lines (94 loc) · 3.68 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
103
104
105
106
name: Backport PR
on:
pull_request:
types: [closed]
permissions: {}
jobs:
prepare:
name: Prepare Backport Targets
if: github.event.pull_request.merged == true
timeout-minutes: 15
runs-on: ubuntu-latest
permissions:
contents: read # Reads repository workflow script and remote branch refs.
pull-requests: write # Adds comments/labels to the source pull request.
outputs:
dry_run: ${{ steps.plan.outputs.dry_run }}
has_targets: ${{ steps.plan.outputs.has_targets }}
targets: ${{ steps.plan.outputs.targets }}
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
persist-credentials: false
- name: Plan backports
id: plan
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_MERGE_COMMIT_SHA: ${{ github.event.pull_request.merge_commit_sha }}
BACKPORT_DRY_RUN: ${{ vars.BACKPORT_DRY_RUN || 'true' }}
run: ./.github/workflows/backport.sh
backport:
name: Create Backport Pull Requests
needs: prepare
if: needs.prepare.outputs.has_targets == 'true' && needs.prepare.outputs.dry_run != 'true'
timeout-minutes: 30
runs-on: ubuntu-latest
permissions:
contents: write # Pushes generated backport branches.
pull-requests: write # Creates backport pull requests and comments on failures.
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.prepare.outputs.targets) }}
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
persist-credentials: false
- name: Cherry-pick with approved action
id: cherry_pick
continue-on-error: true
uses: carloscastrojumo/github-cherry-pick-action@503773289f4a459069c832dc628826685b75b4b3 # v1.0.10
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ matrix.target }}
cherry-pick-branch: backport-${{ github.event.pull_request.number }}-to-${{ matrix.target }}
title: '[Backport ${{ matrix.target }}] {old_title}'
body: |
## 🔄 Automatic Backport
Backport of #{old_pull_request_id} to `${{ matrix.target }}`.
**Target:** `${{ matrix.target }}`
**Version:** `${{ matrix.version }}`
labels: |
backport
inherit_labels: 'false'
- name: Handle failed action backport
if: steps.cherry_pick.outcome != 'success'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
TARGET_BRANCH: ${{ matrix.target }}
run: |
body="❌ **Backport to \`${TARGET_BRANCH}\` failed**"$'\n\n'"Automatic cherry-pick action failed for this target. Please inspect workflow logs and backport manually if needed."
gh pr comment "$PR_NUMBER" --body "$body"
gh pr edit "$PR_NUMBER" --add-label "backport-failed" 2>/dev/null || true
dry-run-report:
name: Report Dry-Run Plan
needs: prepare
if: needs.prepare.outputs.has_targets == 'true' && needs.prepare.outputs.dry_run == 'true'
timeout-minutes: 5
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Report dry-run targets
env:
PLANNED_TARGETS: ${{ needs.prepare.outputs.targets }}
run: |
echo "Backport dry-run mode is enabled."
printf 'Planned targets: %s\n' "$PLANNED_TARGETS"