-
Notifications
You must be signed in to change notification settings - Fork 1
162 lines (144 loc) · 6.48 KB
/
backtrack.yml
File metadata and controls
162 lines (144 loc) · 6.48 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: 'Backtrack'
on:
pull_request:
types:
- closed
branches:
- 'preview/**'
- 'release/**'
permissions:
actions: read
contents: write
concurrency:
group: backtrack-${{ github.base_ref }}
cancel-in-progress: false
jobs:
backtrack:
name: 'Backtrack changes from ${{ github.base_ref }}'
if: ${{ github.event.pull_request.merged == true }}
runs-on: ubuntu-latest
steps:
- name: 'Checkout ${{ github.base_ref }}'
uses: actions/checkout@v6
with:
ref: ${{ github.base_ref }}
fetch-depth: 0
token: ${{ secrets.GH_ADMIN_TOKEN }}
- name: 'Configure git'
uses: './.github/actions/git/configure-identity'
- name: 'Resolve backtrack targets'
id: targets
run: |
base_ref="${{ github.base_ref }}"
if [[ "$base_ref" == preview/* ]]; then
version="${base_ref#preview/}"
echo "preview-branch=" >> $GITHUB_OUTPUT # no intermediate branch; merge directly into develop
echo "develop-branch=develop/$version" >> $GITHUB_OUTPUT
echo "merge-source=$base_ref" >> $GITHUB_OUTPUT
elif [[ "$base_ref" == release/* ]]; then
version="${base_ref#release/}"
echo "preview-branch=preview/$version" >> $GITHUB_OUTPUT
echo "develop-branch=develop/$version" >> $GITHUB_OUTPUT
echo "merge-source=preview/$version" >> $GITHUB_OUTPUT
fi
- name: 'Check if develop branch exists'
id: check-develop
run: |
git fetch origin
if git ls-remote --exit-code --heads origin "${{ steps.targets.outputs.develop-branch }}" > /dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "::warning::Develop branch '${{ steps.targets.outputs.develop-branch }}' not found, skipping backtrack."
fi
- name: 'Lock base branch'
id: lock-base
uses: './.github/actions/github/branch-protection/lock'
with:
branch: ${{ github.base_ref }}
token: ${{ secrets.GH_ADMIN_TOKEN }}
lock-branch: 'true'
- name: 'Lock preview branch'
id: lock-preview
if: ${{ steps.targets.outputs.preview-branch != '' }}
uses: './.github/actions/github/branch-protection/lock'
with:
branch: ${{ steps.targets.outputs.preview-branch }}
token: ${{ secrets.GH_ADMIN_TOKEN }}
lock-branch: 'true'
- name: 'Lock develop branch'
id: lock-develop
if: ${{ steps.check-develop.outputs.exists == 'true' }}
uses: './.github/actions/github/branch-protection/lock'
with:
branch: ${{ steps.targets.outputs.develop-branch }}
token: ${{ secrets.GH_ADMIN_TOKEN }}
lock-branch: 'true'
- name: 'Unlock preview branch for merge'
if: ${{ steps.targets.outputs.preview-branch != '' }}
uses: './.github/actions/github/branch-protection/lock'
with:
branch: ${{ steps.targets.outputs.preview-branch }}
token: ${{ secrets.GH_ADMIN_TOKEN }}
lock-branch: 'false'
skip-pull-request-reviews: 'true'
- name: 'Backtrack: merge ${{ github.base_ref }} into ${{ steps.targets.outputs.preview-branch }}'
if: ${{ steps.targets.outputs.preview-branch != '' }}
env:
GH_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }}
run: |
gh api --method POST /repos/${{ github.repository }}/merges \
--field base="${{ steps.targets.outputs.preview-branch }}" \
--field head="${{ github.base_ref }}" \
--field commit_message="Backtrack: merge ${{ github.base_ref }} into ${{ steps.targets.outputs.preview-branch }}"
- name: 'Unlock develop branch for merge'
if: ${{ steps.check-develop.outputs.exists == 'true' }}
uses: './.github/actions/github/branch-protection/lock'
with:
branch: ${{ steps.targets.outputs.develop-branch }}
token: ${{ secrets.GH_ADMIN_TOKEN }}
lock-branch: 'false'
skip-pull-request-reviews: 'true'
- name: 'Backtrack: merge ${{ steps.targets.outputs.merge-source }} into ${{ steps.targets.outputs.develop-branch }}'
if: ${{ steps.check-develop.outputs.exists == 'true' }}
env:
GH_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }}
run: |
gh api --method POST /repos/${{ github.repository }}/merges \
--field base="${{ steps.targets.outputs.develop-branch }}" \
--field head="${{ steps.targets.outputs.merge-source }}" \
--field commit_message="Backtrack: merge ${{ steps.targets.outputs.merge-source }} into ${{ steps.targets.outputs.develop-branch }}"
- name: 'Restore protection: base branch'
if: ${{ always() && steps.lock-base.outcome == 'success' }}
uses: './.github/actions/github/branch-protection/unlock'
with:
branch: ${{ github.base_ref }}
token: ${{ secrets.GH_ADMIN_TOKEN }}
fail-on-error: 'true'
- name: 'Restore protection: preview branch'
if: ${{ always() && steps.lock-preview.outcome == 'success' }}
uses: './.github/actions/github/branch-protection/unlock'
with:
branch: ${{ steps.targets.outputs.preview-branch }}
token: ${{ secrets.GH_ADMIN_TOKEN }}
fail-on-error: 'true'
- name: 'Restore protection: develop branch'
if: ${{ always() && steps.lock-develop.outcome == 'success' }}
uses: './.github/actions/github/branch-protection/unlock'
with:
branch: ${{ steps.targets.outputs.develop-branch }}
token: ${{ secrets.GH_ADMIN_TOKEN }}
fail-on-error: 'true'
- name: 'Write backtrack summary'
if: ${{ always() }}
run: |
echo "## 🔁 Backtrack Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Branch | Merged from |" >> $GITHUB_STEP_SUMMARY
echo "|--------|-------------|" >> $GITHUB_STEP_SUMMARY
if [[ "${{ steps.targets.outputs.preview-branch }}" != "" ]]; then
echo "| \`${{ steps.targets.outputs.preview-branch }}\` | \`${{ github.base_ref }}\` |" >> $GITHUB_STEP_SUMMARY
fi
if [[ "${{ steps.check-develop.outputs.exists }}" == "true" ]]; then
echo "| \`${{ steps.targets.outputs.develop-branch }}\` | \`${{ steps.targets.outputs.merge-source }}\` |" >> $GITHUB_STEP_SUMMARY
fi