Repository navigation
270 lines (247 loc) · 9.82 KB
/
Copy pathgithub-release.yml
File metadata and controls
270 lines (247 loc) · 9.82 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
name: Release
# Conventional commits on main drive the version: semantic-release computes the
# tag and cuts the GitHub Release, then the binaries and the three component
# images are built from that exact tag. Nothing publishes when no commit since
# the last release warrants a version bump.
on:
workflow_dispatch:
inputs:
tag:
description: "Version to release (e.g. 1.2.3), leave empty to let semantic-release decide"
required: false
type: string
push:
branches:
- main
permissions: {}
env:
DOCKERHUB_USER: devopsiaci
jobs:
version:
name: Resolve version
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
outputs:
published: ${{ steps.resolve.outputs.published }}
version: ${{ steps.resolve.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Semantic Release
id: semantic_release
if: inputs.tag == ''
uses: cycjimmy/semantic-release-action@b12c8f6015dc215fe37bc154d4ad456dd3833c90 # v6.0.0
with:
branch: main
tag_format: ${version}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# A manual run with an explicit tag skips semantic-release entirely. That
# is also how a release whose build failed after the tag landed gets
# rebuilt, without inventing a second version number for it.
- name: Resolve the version to build
id: resolve
env:
TAG_INPUT: ${{ inputs.tag }}
SR_PUBLISHED: ${{ steps.semantic_release.outputs.new_release_published }}
SR_VERSION: ${{ steps.semantic_release.outputs.new_release_version }}
run: |
if [ -n "${TAG_INPUT}" ]; then
echo "published=true" >> "$GITHUB_OUTPUT"
echo "version=${TAG_INPUT#v}" >> "$GITHUB_OUTPUT"
elif [ "${SR_PUBLISHED}" = "true" ]; then
echo "published=true" >> "$GITHUB_OUTPUT"
echo "version=${SR_VERSION}" >> "$GITHUB_OUTPUT"
else
echo "published=false" >> "$GITHUB_OUTPUT"
echo "No release warranted by the commits since the last tag."
fi
binaries:
name: ${{ matrix.component }} ${{ matrix.goos }}/${{ matrix.goarch }}
needs: version
if: needs.version.outputs.published == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
strategy:
fail-fast: false
matrix:
component: [manager, gateway, ui]
goos: [linux, darwin]
goarch: [amd64, arm64]
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.version.outputs.version }}
persist-credentials: false
- name: Setup Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
- name: Build
env:
CGO_ENABLED: "0"
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
VERSION: ${{ needs.version.outputs.version }}
COMPONENT: ${{ matrix.component }}
run: |
out="dwpk-${COMPONENT}_${VERSION}_${GOOS}_${GOARCH}"
mkdir -p "dist/${out}"
go build -ldflags "-s -w -X main.version=${VERSION}" \
-o "dist/${out}/dwpk-${COMPONENT}" "./cmd/${COMPONENT}"
cp LICENSE README.md "dist/${out}/"
tar -czf "dist/${out}.tar.gz" -C dist "${out}"
( cd dist && sha256sum "${out}.tar.gz" > "${out}.tar.gz.sha256" )
- name: Attach to the release
uses: softprops/action-gh-release@efb35369e0ad2afab669f228072c1b0d510eae64 # v3.0.3
with:
tag_name: ${{ needs.version.outputs.version }}
files: |
dist/*.tar.gz
dist/*.tar.gz.sha256
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
images:
name: Image ${{ matrix.component }}
needs: version
if: needs.version.outputs.published == 'true'
runs-on: ubuntu-latest
permissions:
attestations: write
contents: read
id-token: write
packages: write
strategy:
fail-fast: false
matrix:
include:
- component: manager
dockerfile: Dockerfile
repo: dwpk
title: dwpk manager
description: The dwpk operator - reconciles UserSpace, Workspace and WorkspaceImage
- component: gateway
dockerfile: cmd/gateway/Dockerfile
repo: dwpk-gateway
title: dwpk gateway
description: The dwpk SSH gateway - public-key authentication into workspace pods
- component: ui
dockerfile: cmd/ui/Dockerfile
repo: dwpk-ui
title: dwpk UI
description: The dwpk marketplace web UI
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.version.outputs.version }}
persist-credentials: false
- name: Set Docker metadata
id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
with:
images: |
${{ env.DOCKERHUB_USER }}/${{ matrix.repo }}
ghcr.io/${{ github.repository_owner }}/${{ matrix.repo }}
labels: |
org.opencontainers.image.authors=ialejandro
org.opencontainers.image.description=${{ matrix.description }}
org.opencontainers.image.maintainer=ialejandro
org.opencontainers.image.title=${{ matrix.title }}
org.opencontainers.image.vendor=DevOps IA
tags: |
type=raw,value=${{ needs.version.outputs.version }}
type=raw,value=latest
type=sha,enable=false
- name: Set up QEMU
uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: "[DOCKERHUB] Log in to Docker Hub"
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: "[GHCR] Log in to the Container registry"
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: push
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
build-args: VERSION=${{ needs.version.outputs.version }}
cache-from: type=gha,scope=${{ matrix.component }}
cache-to: type=gha,mode=max,scope=${{ matrix.component }}
context: .
file: ${{ matrix.dockerfile }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
push: true
sbom: true
tags: ${{ steps.meta.outputs.tags }}
- name: "[DOCKERHUB] Update the registry description"
uses: peter-evans/dockerhub-description@1b9a80c056b620d92cedb9d9b5a223409c68ddfa # v5.0.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: ${{ env.DOCKERHUB_USER }}/${{ matrix.repo }}
# GHCR only: DockerHub has no attestation endpoint, and it is the same
# image digest either way.
- name: "[GHCR] Generate artifact attestation"
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-name: ghcr.io/${{ github.repository_owner }}/${{ matrix.repo }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
docs:
name: Publish versioned docs
needs: version
if: needs.version.outputs.published == 'true'
runs-on: ubuntu-latest
# Shared with github-pages.yml: both push gh-pages, and racing makes the second push fail.
concurrency:
group: gh-pages
cancel-in-progress: false
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.version.outputs.version }}
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: "3"
- name: Install mkdocs-material and mike
run: pip install mkdocs-material mike mkdocs-llmstxt
# mike's version identifier is major.minor, not the full patch version:
# a patch release (1.4.0 -> 1.4.1) redeploys the same "1.4" entry in
# place instead of adding a new one to the dropdown, which only a major
# or minor bump does.
- name: Deploy this version and move the "latest" alias
env:
VERSION: ${{ needs.version.outputs.version }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# mike resolves the "gh-pages" ref literally (git show gh-pages:...)
# and needs it fetched to see - and not clobber - versions already
# deployed there. First-ever deploy: this fails harmlessly, and mike
# creates gh-pages from scratch.
git fetch origin gh-pages:gh-pages --depth=1 2>/dev/null || true
minor="${VERSION%.*}"
mike deploy --push --update-aliases "${minor}" latest
mike set-default --push latest