-
Notifications
You must be signed in to change notification settings - Fork 179
185 lines (172 loc) · 5.7 KB
/
github-cherrypick.yml
File metadata and controls
185 lines (172 loc) · 5.7 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name: GH Cherrypick bugfixes/features for LTS/Prod
env:
GITHUB_SHA: ${{ github.sha }}
on:
push:
branches:
- dev
jobs:
get_ver:
name: Get Latest LTS/Prod Versions
runs-on: ubuntu-latest
outputs:
maxlts: ${{ steps.parse_lts.outputs.maxlts }}
maxprod: ${{ steps.parse_prod.outputs.maxprod }}
steps:
- name: Checkout Files
uses: actions/checkout@v6
- name: Fetch/Parse LTS Version
id: parse_lts
run: |
MAX_LTS="$( \
git ls-remote --heads origin | \
sed '/-lts/!d; s/^.*refs\/heads\///; s/-lts//; /^[0-9][0-9]*$/!d' | \
sort -n | \
tail -n 1 \
)"
echo "maxlts=${MAX_LTS}-lts" >> $GITHUB_OUTPUT
- name: Fetch/Parse Prod Version
id: parse_prod
run: |
MAX_PROD="$( \
git ls-remote --heads origin | \
sed '/-prod/!d; s/^.*refs\/heads\///; s/-prod//; /^[0-9][0-9]*$/!d' | \
sort -n | \
tail -n 1 \
)"
echo "maxprod=${MAX_PROD}-prod" >> $GITHUB_OUTPUT
- name: Echo Versions
run: |
echo "Detected LTS Version: ${{ steps.parse_lts.outputs.maxlts }}"
echo "Detected Prod Version: ${{ steps.parse_prod.outputs.maxprod }}"
# Check if the PR is a bugfix/feature
check_labels:
runs-on: ubuntu-latest
permissions:
pull-requests: write
name: Check PR labels action step
# Make the output of this job available to other jobs
outputs:
pr: ${{ steps.getpr.outputs.pr }}
fixes: ${{ steps.fixfrags.outputs.fixes }}
steps:
- name: Checkout files
uses: actions/checkout@v6
- name: Get PR number
id: getpr
continue-on-error: true
uses: bcgov/action-get-pr@v0.1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check if PR
if: steps.getpr.outcome == 'failure'
run: |
echo "No PR Number found (this is probably just a push). Further steps skipped."
- name: Detect Fix Change Fragments
if: steps.getpr.outcome == 'success'
env:
GH_TOKEN: ${{ github.token }}
id: fixfrags
run: |
if gh api repos/${{ github.repository }}/pulls/${{ steps.getpr.outputs.pr }}/files --jq '.[].filename' | \
grep '^changes\/[0-9]*\.fix\.md$'; then
echo "Fixes Found"
echo "fixes=true" >> $GITHUB_OUTPUT
else
echo "No Fixes Found"
echo "fixes=false" >> $GITHUB_OUTPUT
fi
cherrypick-lts:
needs:
- get_ver
- check_labels
# Only run this step if code was a bugfix
if: needs.check_labels.outputs.fixes == 'true'
runs-on: ubuntu-22.04
defaults:
run:
shell: bash -l {0} # bash login mode so conda can auto activate isis env
permissions:
pull-requests: write
contents: write
env:
MAX_LTS: ${{ needs.get_ver.outputs.maxlts }}
steps:
- name: Checkout Repo
uses: actions/checkout@v6
with:
submodules: recursive
ref: '${{ env.MAX_LTS }}' # This branch must exist in the repo. Target LTS changes branch.
fetch-depth: '0'
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Cherry Pick
id: cherryPickStep
continue-on-error: true
run: git cherry-pick -m 1 $GITHUB_SHA
- name: Failed Cherry Pick - Re-Checkout
if: steps.cherryPickStep.outcome == 'failure'
uses: actions/checkout@v6
with:
sparse-checkout: |
.github
- name: Failed Cherry Pick - Email
if: steps.cherryPickStep.outcome == 'failure'
env:
GITHUB_PR: ${{ needs.check_labels.outputs.pr }}
GOV_DELIVERY_AUTH: ${{ secrets.GOV_DELIVERY_AUTH }}
run: |
echo 'Auto Cherry Pick Failed, sending notification.'
# Create Template
sed -e "s/###PR###/${GITHUB_PR}/" \
-e "s/###SHA###/${GITHUB_SHA}/" \
-e "s/###CURRENT_LTS###/${MAX_LTS}/" \
.github/cherry-pick-bulletin-template.xml > bulletin-${GITHUB_PR}.xml
# Post and Send Bulletin
curl -X POST https://api.govdelivery.com/api/account/USDOIGS/bulletins/send_now \
-H 'Content-Type: application/xml' \
-H "Authorization: ${GOV_DELIVERY_AUTH}" \
-d @bulletin-${GITHUB_PR}.xml
- name: Setup conda
if: steps.cherryPickStep.outcome == 'success'
uses: conda-incubator/setup-miniconda@v3
with:
miniconda-version: "latest"
activate-environment: isis
environment-file: environment.yml
auto-activate-base: false
auto-update-conda: true
- name: Check Environment (Debug)
if: steps.cherryPickStep.outcome == 'success'
env:
ISISROOT: ${{ github.workspace }}/build
run: |
echo "--- Conda Env"
conda info --envs
echo "--- cmake Location (Should be in isis conda env)"
which cmake
cmake --version
echo "--- python location"
which python
echo "--- Working Directory"
pwd
echo "--- Files"
ls
echo "--- ISISROOT"
echo $ISISROOT
- name: Build ISIS
if: steps.cherryPickStep.outcome == 'success'
env:
ISISROOT: ${{ github.workspace }}/build
run: |
mkdir build
cd build
cmake -GNinja ../isis
ninja -j8
- name: Successful Cherry Pick - Auto Push to LTS
if: steps.cherryPickStep.outcome == 'success'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: git push