-
Notifications
You must be signed in to change notification settings - Fork 1
295 lines (254 loc) · 10 KB
/
Copy pathrelease.yaml
File metadata and controls
295 lines (254 loc) · 10 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
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
name: Release
on:
push:
branches:
- main
paths:
- 'src/**'
- 'tests/**'
- 'Cargo.toml'
- 'Cargo.lock'
- 'Dockerfile'
- 'deploy/**'
- 'CHANGELOG.md'
- 'scripts/release-gate.sh'
- '.github/workflows/release.yaml'
- '.github/workflows/sync-helm-chart.yaml'
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
permissions:
contents: write
packages: write
jobs:
validate:
name: Validate Release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
docker_tags: ${{ steps.version.outputs.docker_tags }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
fetch-depth: 0
fetch-tags: true
- name: Extract release version
id: version
run: |
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
VERSION="${GITHUB_REF#refs/tags/v}"
else
VERSION=$(awk -F '"' '/^version = / { print $2; exit }' Cargo.toml)
fi
TAG="v${VERSION}"
MAJOR="${VERSION%%.*}"
REST="${VERSION#*.}"
MINOR="${REST%%.*}"
MAJOR_MINOR="${MAJOR}.${MINOR}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=$TAG" >> $GITHUB_OUTPUT
{
echo "docker_tags<<EOF"
echo "${REGISTRY}/${IMAGE_NAME}:${VERSION}"
if [[ "$VERSION" != *-* ]]; then
echo "${REGISTRY}/${IMAGE_NAME}:${MAJOR_MINOR}"
echo "${REGISTRY}/${IMAGE_NAME}:${MAJOR}"
echo "${REGISTRY}/${IMAGE_NAME}:latest"
fi
echo "EOF"
} >> $GITHUB_OUTPUT
echo "Release version: $VERSION"
- name: Validate release gate
env:
EXPECTED_VERSION: ${{ steps.version.outputs.version }}
ALLOW_EXISTING_TAG: ${{ startsWith(github.ref, 'refs/tags/') }}
run: bash scripts/release-gate.sh
test:
name: Pre-release Tests
runs-on: ubuntu-latest
needs: validate
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9 # stable
with:
toolchain: stable
components: clippy, rustfmt
- name: Install Helm
uses: azure/setup-helm@v4.2.0
with:
version: v3.14.4
- name: Cache cargo registry
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-release-test-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-release-test-
- name: Check formatting
run: cargo fmt --all -- --check
- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Run tests
run: cargo test --all-features
env:
RUST_LOG: debug
- name: Generate CRDs
run: cargo run --bin crdgen
- name: Verify CRDs are up to date
run: |
git diff --exit-code deploy/crds/ deploy/helm/strimzi-backup-operator/crds/
cmp deploy/crds/kafkabackups.yaml deploy/helm/strimzi-backup-operator/crds/kafkabackups.yaml
cmp deploy/crds/kafkarestores.yaml deploy/helm/strimzi-backup-operator/crds/kafkarestores.yaml
- name: Lint Helm chart
run: helm lint deploy/helm/strimzi-backup-operator
- name: Render Helm chart
run: |
APP_VERSION=$(awk '$1 == "appVersion:" { gsub(/"/, "", $2); print $2; exit }' deploy/helm/strimzi-backup-operator/Chart.yaml)
helm template strimzi-backup-operator deploy/helm/strimzi-backup-operator \
| tee /tmp/strimzi-backup-operator-default.yaml
grep -q 'name: BACKUP_JOB_SERVICE_ACCOUNT' /tmp/strimzi-backup-operator-default.yaml
grep -q 'value: "strimzi-backup-operator"' /tmp/strimzi-backup-operator-default.yaml
grep -q "image: ghcr.io/osodevops/strimzi-backup-operator:${APP_VERSION}" /tmp/strimzi-backup-operator-default.yaml
helm template strimzi-backup-operator deploy/helm/strimzi-backup-operator \
--set backupJobs.serviceAccountName=kafka-backup-operator \
| tee /tmp/strimzi-backup-operator-override.yaml
grep -q 'value: "kafka-backup-operator"' /tmp/strimzi-backup-operator-override.yaml
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: [validate, test]
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Set up QEMU
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
- name: Log in to Container Registry
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7
with:
context: .
load: true
tags: ${{ env.IMAGE_NAME }}:test
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Smoke test - verify binary is linked and executable
run: |
docker run --rm --entrypoint ldd ${{ env.IMAGE_NAME }}:test --version
docker run --rm --entrypoint ls ${{ env.IMAGE_NAME }}:test -la /usr/local/bin/kafka-backup-operator
echo "Docker smoke test passed!"
- name: Push Docker image
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7
with:
context: .
platforms: linux/amd64
push: true
tags: ${{ needs.validate.outputs.docker_tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [validate, build-and-push]
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
fetch-depth: 0
fetch-tags: true
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9 # stable
with:
toolchain: stable
- name: Cache cargo registry
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
- name: Generate CRDs
run: cargo run --release --bin crdgen
- name: Package CRDs
run: |
cat deploy/crds/kafkabackups.yaml > crds.yaml
echo "---" >> crds.yaml
cat deploy/crds/kafkarestores.yaml >> crds.yaml
- name: Generate changelog
id: changelog
run: |
TAG="${{ needs.validate.outputs.tag }}"
# Find the previous tag for changelog generation
PREV_TAG=$(git tag --sort=-v:refname | grep -v "^${TAG}$" | head -1)
if [ -z "$PREV_TAG" ]; then
PREV_TAG=$(git rev-list --max-parents=0 HEAD | head -1)
fi
echo "Generating changelog: ${PREV_TAG}..HEAD"
# Generate changelog grouped by conventional commit type
echo "## What's Changed" > changelog.md
echo "" >> changelog.md
FEATURES=$(git log "${PREV_TAG}..HEAD" --oneline --grep="^feat" --format="* %s" 2>/dev/null | head -20)
if [ -n "$FEATURES" ]; then
echo "### Features" >> changelog.md
echo "$FEATURES" >> changelog.md
echo "" >> changelog.md
fi
FIXES=$(git log "${PREV_TAG}..HEAD" --oneline --grep="^fix" --format="* %s" 2>/dev/null | head -20)
if [ -n "$FIXES" ]; then
echo "### Fixes" >> changelog.md
echo "$FIXES" >> changelog.md
echo "" >> changelog.md
fi
DEPS=$(git log "${PREV_TAG}..HEAD" --oneline --grep="^deps\|^dep\|^chore(deps)\|Bump" --format="* %s" 2>/dev/null | head -20)
if [ -n "$DEPS" ]; then
echo "### Dependencies" >> changelog.md
echo "$DEPS" >> changelog.md
echo "" >> changelog.md
fi
OTHER=$(git log "${PREV_TAG}..HEAD" --oneline --grep="^ci\|^chore\|^style\|^refactor" --format="* %s" 2>/dev/null | head -20)
if [ -n "$OTHER" ]; then
echo "### Other" >> changelog.md
echo "$OTHER" >> changelog.md
echo "" >> changelog.md
fi
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${TAG}" >> changelog.md
- name: Create GitHub Release
uses: softprops/action-gh-release@153bb8e04406b158c6c84fc1615b65b24149a1fe # v2
with:
name: v${{ needs.validate.outputs.version }}
tag_name: ${{ needs.validate.outputs.tag }}
target_commitish: ${{ github.sha }}
body_path: changelog.md
files: |
crds.yaml
draft: false
prerelease: ${{ contains(needs.validate.outputs.version, '-') }}
generate_release_notes: false
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PAT || secrets.GITHUB_TOKEN }}
sync-helm-chart:
name: Sync Helm Chart
needs: [create-release]
uses: ./.github/workflows/sync-helm-chart.yaml
secrets: inherit