Repository navigation
148 lines (140 loc) · 4.75 KB
/
Copy pathcd.yml
File metadata and controls
148 lines (140 loc) · 4.75 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
name: CD
on:
push:
tags: ['v*']
# Manual runs check release artifacts without publishing anything.
workflow_dispatch:
permissions:
contents: read
concurrency:
group: cd-${{ github.ref }}
cancel-in-progress: false
jobs:
checks:
name: Basic checks
uses: ./.github/workflows/ci.yml
packages:
name: Release packages
needs: checks
uses: ./.github/workflows/packages.yml
with:
version: ${{ github.ref_type == 'tag' && github.ref_name || format('ci-{0}', github.sha) }}
docker:
name: Publish Docker image
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
needs: validation
runs-on: ubuntu-latest
timeout-minutes: 45
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v6
- name: Set image name
id: image
env:
REPOSITORY: ${{ github.repository }}
run: echo "name=ghcr.io/${REPOSITORY,,}" >> "$GITHUB_OUTPUT"
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/metadata-action@v5
id: meta
with:
images: ${{ steps.image.outputs.name }}
tags: |
type=semver,pattern={{version}}
- uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
build-args: VERSION=${{ github.ref_name }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
release:
name: Publish release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
needs: docker
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
steps:
- uses: actions/checkout@v6
- uses: actions/download-artifact@v4
with:
pattern: release-*
merge-multiple: true
path: dist
- name: Verify release checksums
working-directory: dist
shell: bash
run: |
sha256sum -c SHA256SUMS
- name: Publish release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
TAG: ${{ github.ref_name }}
shell: bash
run: |
flags=()
if [[ "$TAG" == *-* ]]; then
flags+=(--prerelease)
fi
notes="$RUNNER_TEMP/release-notes.md"
awk -v version="$TAG" '
$1 == "##" { if (found) exit; found = ($2 == version); next }
found { print }
' CHANGELOG.md > "$notes"
test -s "$notes"
if gh release view "$TAG" >/dev/null 2>&1; then
gh release upload "$TAG" dist/*.tar.gz dist/*.zip --clobber
gh release upload "$TAG" dist/SHA256SUMS --clobber
gh release edit "$TAG" --title "zcode2api $TAG" --notes-file "$notes" "${flags[@]}"
else
gh release create "$TAG" dist/* --verify-tag --title "zcode2api $TAG" --notes-file "$notes" --generate-notes "${flags[@]}"
fi
validation:
name: Verify release artifacts
needs: packages
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/download-artifact@v4
with:
pattern: release-*
merge-multiple: true
path: dist
- name: Check complete artifact set and generate checksums
working-directory: dist
shell: bash
run: |
test "$(find . -maxdepth 1 -name '*.zip' | wc -l)" -eq 2
test "$(find . -maxdepth 1 -name '*.tar.gz' | wc -l)" -eq 4
sha256sum ./*.tar.gz ./*.zip > SHA256SUMS
sha256sum -c SHA256SUMS
- name: Check packaged Linux version
env:
RELEASE_VERSION: ${{ github.ref_type == 'tag' && github.ref_name || format('ci-{0}', github.sha) }}
shell: bash
run: |
package="zcode2api_${RELEASE_VERSION}_linux_amd64"
tar -xzf "dist/${package}.tar.gz" -C "$RUNNER_TEMP"
actual_version=$("$RUNNER_TEMP/$package/zcode2api" --version)
test "$actual_version" = "zcode2api $RELEASE_VERSION"
- uses: actions/upload-artifact@v4
with:
name: release-checksums
path: dist/SHA256SUMS
if-no-files-found: error
- name: Summarize validation-only run
if: github.event_name == 'workflow_dispatch'
run: echo 'Source and build checks, six release packages, packaged version and release checksums passed. No release or image was published.' >> "$GITHUB_STEP_SUMMARY"