-
Notifications
You must be signed in to change notification settings - Fork 117
272 lines (226 loc) · 9.57 KB
/
release.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
name: Release
on:
schedule:
# Every Monday at 07:00 (UTC)
- cron: '00 7 * * MON'
workflow_dispatch:
inputs:
release_type:
description: 'Release type'
required: true
type: choice
options:
- minor
- patch
release_branch:
description: Branch to release
required: true
default: master
type: string
quay_repository:
description: Quay repository
type: string
default: quay.io/kiali/kiali-operator
required: true
jobs:
initialize:
name: Initialize
runs-on: ubuntu-20.04
outputs:
release_type: ${{ steps.release_type.outputs.release_type }}
release_version: ${{ steps.release_version.outputs.release_version }}
branch_version: ${{ steps.branch_version.outputs.branch_version }}
next_version: ${{ steps.next_version.outputs.next_version }}
quay_tag: ${{ steps.quay_tag.outputs.quay_tag }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.release_branch || github.ref_name }}
- name: Prepare scripts
run: |
cat <<-EOF > bump.py
import sys
release_type = sys.argv[1]
version = sys.argv[2]
parts = version.split('.')
major = int(parts[0][1:])
minor = int(parts[1])
patch = int(parts[2])
if release_type == 'major':
major = major + 1
minor = 0
patch = 0
elif release_type == 'minor':
minor = minor + 1
patch = 0
elif release_type == 'patch':
patch = patch + 1
print('.'.join(['v' + str(major), str(minor), str(patch)]))
EOF
cat <<-EOF > minor.py
import datetime
# The base date can be any end of sprint from the past
base = int(datetime.datetime.strptime("24/04/2022", "%d/%m/%Y").timestamp())
now = int(datetime.datetime.now().timestamp())
diff = now - base
days_elapsed = int(diff / (24*60*60))
weeks_elapsed = int(days_elapsed / 7)
weeks_mod3 = int(weeks_elapsed % 3)
print(weeks_mod3)
EOF
- name: Determine release type
id: release_type
run: |
if [ -z ${{ github.event.inputs.release_type }} ];
then
DO_RELEASE=$(python minor.py)
if [[ $DO_RELEASE == "1" ]]
then
echo "release_type=minor" >> $GITHUB_OUTPUT
else
echo "release_type=skip" >> $GITHUB_OUTPUT
fi
else
echo "release_type=${{ github.event.inputs.release_type }}" >> $GITHUB_OUTPUT
fi
- name: Determine release version
if: ${{ steps.release_type.outputs.release_type != 'skip' }}
env:
RELEASE_TYPE: ${{ steps.release_type.outputs.release_type }}
id: release_version
run: |
RAW_VERSION=$(sed -rn 's/^VERSION \?= (.*)/\1/p' Makefile)
# Remove any pre release identifier (ie: "-SNAPSHOT")
RELEASE_VERSION=${RAW_VERSION%-*}
if [[ $RELEASE_TYPE == "patch" ]]
then
RELEASE_VERSION=$(python bump.py $RELEASE_TYPE $RELEASE_VERSION)
elif [[ $RELEASE_TYPE == "minor" ]]
then
RELEASE_VERSION=$RELEASE_VERSION
fi
echo "release_version=$RELEASE_VERSION" >> $GITHUB_OUTPUT
- name: Determine next version
if: ${{ steps.release_type.outputs.release_type != 'skip' }}
env:
RELEASE_TYPE: ${{ steps.release_type.outputs.release_type }}
RELEASE_VERSION: ${{ steps.release_version.outputs.release_version }}
id: next_version
run: |
if [[ $RELEASE_TYPE == "patch" ]]
then
NEXT_VERSION=$(python bump.py $RELEASE_TYPE $RELEASE_VERSION)
elif [[ $RELEASE_TYPE == "minor" ]]
then
NEXT_VERSION=$(python bump.py $RELEASE_TYPE $RELEASE_VERSION)
fi
echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT
- name: Determine branch version
if: ${{ steps.release_type.outputs.release_type != 'skip' }}
env:
RELEASE_VERSION: ${{ steps.release_version.outputs.release_version }}
id: branch_version
run: |
echo "branch_version=$(echo $RELEASE_VERSION | sed 's/\.[0-9]*\+$//')" >> $GITHUB_OUTPUT
- name: Determine Quay tag
if: ${{ steps.release_type.outputs.release_type != 'skip' }}
env:
RELEASE_VERSION: ${{ steps.release_version.outputs.release_version }}
BRANCH_VERSION: ${{ steps.branch_version.outputs.branch_version }}
id: quay_tag
run: |
if [ -z ${{ github.event.inputs.quay_repository }} ];
then
QUAY_REPO="quay.io/kiali/kiali-operator"
else
QUAY_REPO="${{ github.event.inputs.quay_repository }}"
fi
QUAY_TAG="$QUAY_REPO:$RELEASE_VERSION $QUAY_REPO:$BRANCH_VERSION"
echo "quay_tag=$QUAY_TAG" >> $GITHUB_OUTPUT
- name: Cleanup
run: rm bump.py minor.py
- name: Log information
run: |
echo "Release type: ${{ steps.release_type.outputs.release_type }}"
echo "Release version: ${{ steps.release_version.outputs.release_version }}"
echo "Next version: ${{ steps.next_version.outputs.next_version }}"
echo "Branch version: ${{ steps.branch_version.outputs.branch_version }}"
echo "Quay tag": ${{ steps.quay_tag.outputs.quay_tag }}
release:
name: Release
if: ${{ needs.initialize.outputs.release_type != 'skip' && ((github.event_name == 'schedule' && github.repository == 'kiali/kiali-operator') || github.event_name != 'schedule') }}
runs-on: ubuntu-20.04
needs: [initialize]
env:
RELEASE_TYPE: ${{ needs.initialize.outputs.release_type }}
RELEASE_VERSION: ${{ needs.initialize.outputs.release_version }}
BRANCH_VERSION: ${{ needs.initialize.outputs.branch_version }}
NEXT_VERSION: ${{ needs.initialize.outputs.next_version }}
RELEASE_BRANCH: ${{ github.event.inputs.release_branch || github.ref_name }}
OPERATOR_QUAY_TAG: ${{ needs.initialize.outputs.quay_tag }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.release_branch || github.ref_name }}
- name: Set version to release
run: sed -i -r "s/^VERSION \?= (.*)/VERSION \?= $RELEASE_VERSION/" Makefile
- name: Build and push image
run: |
docker login -u ${{ secrets.QUAY_USER }} -p ${{ secrets.QUAY_PASSWORD }} quay.io
make -e DOCKER_CLI_EXPERIMENTAL=enabled container-multi-arch-push-kiali-operator-quay
- name: Configure git
run: |
git config user.email '[email protected]'
git config user.name 'kiali-bot'
- name: Create tag
run: |
# Skip OLM metadata for patch releases
if [[ $RELEASE_TYPE == "minor" ]]
then
VERSION_TO_RELEASE=${RELEASE_VERSION:1}
DATETIME_NOW="$(date --utc +'%FT%TZ')"
CSV_UPSTREAM_FILE="./manifests/kiali-upstream/${VERSION_TO_RELEASE}/manifests/kiali.v${VERSION_TO_RELEASE}.clusterserviceversion.yaml"
CSV_COMMUNITY_FILE="./manifests/kiali-community/${VERSION_TO_RELEASE}/manifests/kiali.v${VERSION_TO_RELEASE}.clusterserviceversion.yaml"
for csv in ${CSV_UPSTREAM_FILE} ${CSV_COMMUNITY_FILE}
do
rm -f /tmp/kiali-csv-changes.txt
sed -i "s/createdAt: .\+Z/createdAt: ${DATETIME_NOW}/gw /tmp/kiali-csv-changes.txt" ${csv}
if [ ! -s /tmp/kiali-csv-changes.txt ]; then
echo "It looks like 'createdAt' metadata was not changed in the new CSV file. Check the new CSV file for correctness."
echo CSV FILE: ${csv}
# we could abort the build here, but this would not be a blocker so we could just let the build keep going
fi
done
git add $CSV_UPSTREAM_FILE $CSV_COMMUNITY_FILE
fi
git add Makefile
git commit -m "Release $RELEASE_VERSION"
git push origin $(git rev-parse HEAD):refs/tags/$RELEASE_VERSION
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create $RELEASE_VERSION -t "Kiali Operator $RELEASE_VERSION"
- name: Create or update version branch
run: git push origin $(git rev-parse HEAD):refs/heads/$BRANCH_VERSION
- name: Configure Operator SDK
if: ${{ needs.initialize.outputs.release_type == 'minor' }}
run: |
make get-operator-sdk
- name: Create a PR to prepare for next version
env:
BUILD_TAG: kiali-operator-release-${{ github.run_number }}-main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ needs.initialize.outputs.release_type == 'minor' }}
run: |
export PATH="$PATH:$GITHUB_WORKSPACE/_output/operator-sdk-install"
sed -i -r "s/^VERSION \?= (.*)/VERSION \?= $NEXT_VERSION-SNAPSHOT/" Makefile
# Using versions without the prefix 'v'
./manifests/create-new-version.sh -nv ${NEXT_VERSION:1} -ov ${RELEASE_VERSION:1} -om kiali-upstream/
./manifests/create-new-version.sh -nv ${NEXT_VERSION:1} -ov ${RELEASE_VERSION:1} -om kiali-community/
git add Makefile manifests/
git commit -m "Prepare for next version"
git push origin $(git rev-parse HEAD):refs/heads/$BUILD_TAG
gh pr create -t "Prepare for next version" -b "Please, merge to update version numbers and prepare for release $NEXT_VERSION." -H $BUILD_TAG -B $RELEASE_BRANCH