forked from cloudnative-pg/cloudnative-pg
-
Notifications
You must be signed in to change notification settings - Fork 0
165 lines (156 loc) · 6.28 KB
/
backport.yml
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
163
164
165
name: Backport Pull Request
on:
pull_request_target:
types:
- closed
- opened
- reopened
branches:
- main
env:
GOLANG_VERSION: "1.23.x"
jobs:
# Label the source pull request with 'backport-requested' and all supported releases label, the goal is, by default
# we backport everything, except those PR that are created or contain `do not backport` explicitly.
label-source-pr:
name: Add labels to PR
if: |
github.event.pull_request.merged == false &&
!contains(github.event.pull_request.labels.*.name, 'backport-requested') &&
!contains(github.event.pull_request.labels.*.name, 'do not backport')
runs-on: ubuntu-22.04
steps:
-
name: Label the pull request
uses: actions-ecosystem/action-add-labels@v1
if: ${{ !contains(github.event.pull_request.labels.*.name, 'do not backport') }}
with:
github_token: ${{ secrets.REPO_GHA_PAT }}
number: ${{ github.event.pull_request.number }}
labels: |
backport-requested :arrow_backward:
release-1.22
release-1.23
release-1.24
-
name: Create comment
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
:exclamation: By default, the pull request is configured to backport to all release branches.
- To stop backporting this pr, remove the label: backport-requested :arrow_backward: or add the label 'do not backport'
- To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y
reactions: heart
-
name: Remove redundant labels
uses: actions-ecosystem/action-remove-labels@v1
if: ${{ contains(github.event.pull_request.labels.*.name, 'do not backport') }}
with:
github_token: ${{ secrets.REPO_GHA_PAT }}
labels: |
backport-requested :arrow_backward:
release-1.22
release-1.23
release-1.24
## backport pull request in condition when pr contains 'backport-requested' label and contains target branches labels
back-porting-pr:
name: Backport to release branches
if: |
github.event.pull_request.merged == true &&
(
contains(github.event.pull_request.labels.*.name, 'backport-requested') ||
contains(github.event.pull_request.labels.*.name, 'backport-requested :arrow_backward:')
) &&
!contains(github.event.pull_request.labels.*.name, 'do not backport')
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
branch: [release-1.22, release-1.23, release-1.24]
env:
PR: ${{ github.event.pull_request.number }}
outputs:
commit: ${{ steps.check_commits.outputs.commit }}
steps:
-
name: Checkout code
if: contains( github.event.pull_request.labels.*.name, matrix.branch )
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ matrix.branch }}
token: ${{ secrets.REPO_GHA_PAT }}
-
name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GOLANG_VERSION }}
check-latest: true
-
name: Check commits
if: contains( github.event.pull_request.labels.*.name, matrix.branch )
id: check_commits
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
commit=$(gh pr view ${PR} --json mergeCommit -q ".mergeCommit.oid" 2>/dev/null || :)
if [ -z "${commit}" ]
then
echo "No commit found!"
exit 0
fi
echo "commit=${commit}" >> $GITHUB_OUTPUT
echo "cherry-pick commit ${commit} to branch ${{ matrix.branch }}"
author_name=$(git show -s --format='%an' "${commit}")
echo "AUTHOR_NAME=${author_name}" >> $GITHUB_ENV
author_email=$(git show -s --format='%ae' "${commit}")
echo "AUTHOR_EMAIL=${author_email}" >> $GITHUB_ENV
-
name: cherry pick
env:
COMMIT: ${{ steps.check_commits.outputs.commit }}
if: |
contains( github.event.pull_request.labels.*.name, matrix.branch ) && env.COMMIT != ''
run: |
git config user.email "${{ env.AUTHOR_EMAIL }}"
git config user.name "${{ env.AUTHOR_NAME }}"
git fetch
git cherry-pick -x --mainline 1 ${{ env.COMMIT }}
make fmt vet generate apidoc wordlist-ordered
if ! git diff --exit-code --quiet
then
echo "!!! Generated files need manually handling"
exit 1
fi
git push
create-tickets:
name: Create tickets for failures
needs:
- back-porting-pr
if: |
failure() && !cancelled() &&
needs.back-porting-pr.outputs.commit != ''
env:
PR: ${{ github.event.pull_request.number }}
COMMIT: ${{ needs.back-porting-pr.outputs.commit }}
runs-on: ubuntu-22.04
steps:
- name: create ticket
uses: dacbd/create-issue-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: Backport failure for pull request ${{ env.PR }}
labels: backport failure
body: |
### Context
Automatically backport failure for pull request ${{ env.PR }}
Pull request: ${{ github.server_url }}/${{ github.repository }}/pull/${{ env.PR }}
Commit: ${{ github.server_url }}/${{ github.repository }}/commit/${{ env.COMMIT }}
Workflow: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
To solve the ticket, open the workflow link above, and for each failed release branch check the following:
1. Whether the commit should be `cherry-pick`(ed) to this release branch, otherwise skip this release branch
2. If yes, `cherry-pick` the commit manually and push it to the release branch. You may need to resolve the
conflicts and issue `cherry-pick --continue` again. Also, a dependent commit missing may be causing the
failure, so if that's the case you may need to `cherry-pick` the dependent commit first.