-
Notifications
You must be signed in to change notification settings - Fork 8
358 lines (308 loc) · 11.7 KB
/
Copy pathci.yml
File metadata and controls
358 lines (308 loc) · 11.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
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
name: CI
on:
push:
branches:
- master
pull_request:
permissions:
contents: read
packages: write
pages: write
id-token: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true
- name: Install restic and sqlite3 for integration tests
run: sudo apt-get update && sudo apt-get install -y restic sqlite3
- run: bin/test
env:
KAMAL_BACKUP_RUN_INTEGRATION: "1"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
files: ./coverage/coverage.xml
fail_ci_if_error: false
release_gate:
runs-on: ubuntu-latest
needs: test
outputs:
publish_artifacts: ${{ steps.check_release.outputs.publish_artifacts }}
should_release: ${{ steps.check_release.outputs.should_release }}
stable: ${{ steps.check_release.outputs.stable }}
tag: ${{ steps.check_release.outputs.tag }}
version: ${{ steps.check_release.outputs.version }}
version_changed: ${{ steps.check_release.outputs.version_changed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
- name: Check release state
id: check_release
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
VERSION=$(ruby -r ./lib/kamal_backup/version -e 'puts KamalBackup::VERSION')
TAG="v${VERSION}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
if ruby -rrubygems/version -e 'exit Gem::Version.new(ARGV.fetch(0)).prerelease? ? 0 : 1' "$VERSION"; then
echo "stable=false" >> "$GITHUB_OUTPUT"
else
echo "stable=true" >> "$GITHUB_OUTPUT"
fi
GEM_NAME="kamal-backup"
ALL_PUBLISHED_VERSIONS=$(( \
gem list ^${GEM_NAME}$ -r --all 2>/dev/null || true; \
gem list ^${GEM_NAME}$ -r --prerelease 2>/dev/null || true; \
) | sed -n 's/.*(\(.*\)).*/\1/p' \
| tr ',' '\n' \
| sed 's/^[[:space:]]*//;s/[[:space:]]*$//' \
| sed '/^$/d' \
| sort -u )
if echo "$ALL_PUBLISHED_VERSIONS" | grep -Fxq "$VERSION"; then
version_changed=false
else
version_changed=true
fi
echo "version_changed=${version_changed}" >> "$GITHUB_OUTPUT"
if git ls-remote --exit-code --tags origin "refs/tags/${TAG}" >/dev/null 2>&1; then
tag_missing=false
else
tag_missing=true
fi
if gh release view "$TAG" >/dev/null 2>&1; then
release_missing=false
else
release_missing=true
fi
release_ref=false
if [ "$GITHUB_REF" = "refs/heads/${{ github.event.repository.default_branch }}" ]; then
release_ref=true
fi
if [ "$release_ref" = "true" ] && { [ "$version_changed" = "true" ] || [ "$tag_missing" = "true" ]; }; then
echo "publish_artifacts=true" >> "$GITHUB_OUTPUT"
else
echo "publish_artifacts=false" >> "$GITHUB_OUTPUT"
fi
if [ "$release_ref" = "true" ] && { [ "$version_changed" = "true" ] || [ "$tag_missing" = "true" ] || [ "$release_missing" = "true" ]; }; then
echo "should_release=true" >> "$GITHUB_OUTPUT"
else
echo "should_release=false" >> "$GITHUB_OUTPUT"
fi
image:
runs-on: ubuntu-latest
needs: [test, release_gate]
steps:
- uses: actions/checkout@v4
- id: version
name: Read kamal-backup version
run: |
VERSION=$(ruby -r ./lib/kamal_backup/version -e 'puts KamalBackup::VERSION')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
if [ "${{ needs.release_gate.outputs.publish_artifacts }}" = "true" ]; then
echo "version_tag=true" >> "$GITHUB_OUTPUT"
else
echo "version_tag=false" >> "$GITHUB_OUTPUT"
fi
if ruby -rrubygems/version -e 'exit Gem::Version.new(ARGV.fetch(0)).prerelease? ? 0 : 1' "$VERSION"; then
echo "stable=false" >> "$GITHUB_OUTPUT"
else
echo "stable=true" >> "$GITHUB_OUTPUT"
fi
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/crmne/kamal-backup
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha,prefix=sha-
type=raw,value=${{ steps.version.outputs.version }},enable=${{ steps.version.outputs.version_tag == 'true' }}
type=raw,value=latest,enable=${{ steps.version.outputs.version_tag == 'true' && steps.version.outputs.stable == 'true' }}
labels: |
org.opencontainers.image.version=${{ steps.version.outputs.version }}
- uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
gem:
runs-on: ubuntu-latest
needs: [test, release_gate]
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true
- name: Build gem
run: gem build kamal-backup.gemspec
- name: Inspect gem
run: |
ruby -rrubygems/package -e '
spec = Gem::Package.new(Dir["kamal-backup-*.gem"].first).spec
puts "name=#{spec.name}"
puts "version=#{spec.version}"
puts "summary=#{spec.summary}"
puts "executables=#{spec.executables.join(",")}"
'
- name: Check if version needs publishing
if: github.event_name != 'pull_request' && needs.release_gate.outputs.should_release == 'true'
id: check_version
run: |
set -euo pipefail
VERSION=$(ruby -r ./lib/kamal_backup/version -e 'puts KamalBackup::VERSION')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
GEM_NAME="kamal-backup"
ALL_PUBLISHED_VERSIONS=$(( \
gem list ^${GEM_NAME}$ -r --all 2>/dev/null || true; \
gem list ^${GEM_NAME}$ -r --prerelease 2>/dev/null || true; \
) | sed -n 's/.*(\(.*\)).*/\1/p' \
| tr ',' '\n' \
| sed 's/^[[:space:]]*//;s/[[:space:]]*$//' \
| grep . \
| sort -u )
if echo "$ALL_PUBLISHED_VERSIONS" | grep -Fxq "$VERSION"; then
echo "version_changed=false" >> "$GITHUB_OUTPUT"
else
echo "version_changed=true" >> "$GITHUB_OUTPUT"
fi
shell: bash
- name: Publish to RubyGems
if: steps.check_version.outputs.version_changed == 'true'
run: |
mkdir -p "$HOME/.gem"
touch "$HOME/.gem/credentials"
chmod 0600 "$HOME/.gem/credentials"
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > "$HOME/.gem/credentials"
output=$(gem push "kamal-backup-${VERSION}.gem" 2>&1) || {
echo "$output"
if echo "$output" | grep -q "Repushing of gem versions is not allowed"; then
echo "Version already exists on RubyGems, skipping"
exit 0
else
exit 1
fi
}
env:
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_AUTH_TOKEN }}
VERSION: ${{ steps.check_version.outputs.version }}
release:
runs-on: ubuntu-latest
needs: [test, release_gate, image, gem]
if: github.event_name != 'pull_request' && needs.release_gate.outputs.should_release == 'true'
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
- name: Create GitHub release
run: |
set -euo pipefail
VERSION=$(ruby -r ./lib/kamal_backup/version -e 'puts KamalBackup::VERSION')
TAG="v${VERSION}"
release_target="$GITHUB_SHA"
git fetch --tags --force
if git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null; then
tag_sha=$(git rev-list -n 1 "${TAG}")
if [ "$tag_sha" != "$GITHUB_SHA" ] && [ "${{ needs.release_gate.outputs.version_changed }}" = "true" ]; then
echo "::error::Tag ${TAG} already exists at ${tag_sha}, not ${GITHUB_SHA}."
exit 1
fi
release_target="$tag_sha"
else
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag "$TAG" "$GITHUB_SHA"
git push origin "$TAG"
fi
if gh release view "$TAG" >/dev/null 2>&1; then
echo "GitHub release $TAG already exists."
exit 0
fi
prerelease_args=()
if ruby -rrubygems/version -e "exit Gem::Version.new(ARGV.fetch(0)).prerelease? ? 0 : 1" "$VERSION"; then
prerelease_args=(--prerelease)
fi
previous_tag=$(git tag --sort=-v:refname --list 'v*' | awk -v current="$TAG" '$0 != current { print; exit }')
if [ -n "$previous_tag" ]; then
commit_range="${previous_tag}..${release_target}"
else
commit_range="${release_target}"
fi
commits=$(git log --reverse --format='* %H %s' "$commit_range" | grep -Ev '^\* [0-9a-f]+ (docs|test|chore):' || true)
if [ -z "$commits" ]; then
commits=$(git log --reverse --format='* %H %s' "$commit_range")
fi
{
echo "## Changelog"
echo "$commits"
if [ -n "$previous_tag" ]; then
echo
echo "**Full Changelog**: https://github.com/${GITHUB_REPOSITORY}/compare/${previous_tag}...${TAG}"
fi
} > release-notes.md
gh release create "$TAG" \
--target "$release_target" \
--notes-file release-notes.md \
"${prerelease_args[@]}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docs:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
- uses: actions/configure-pages@v5
- name: Install docs dependencies
working-directory: docs
run: bundle install
- name: Build docs
working-directory: docs
run: bundle exec jekyll build
- uses: actions/upload-pages-artifact@v3
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
with:
path: docs/_site
deploy-docs:
runs-on: ubuntu-latest
needs: docs
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
concurrency:
group: pages
cancel-in-progress: false
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v4