Repository navigation
268 lines (248 loc) · 10.6 KB
/
Copy pathrelease.yml
File metadata and controls
268 lines (248 loc) · 10.6 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
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Pushing a vX.Y.Z[-PRERELEASE] tag publishes a release:
#
# 1. images: builds ax-server, ax-runner, and ax-runner-volume for
# linux/amd64 and linux/arm64 and pushes them to
# ghcr.io/google/ax/<image>:<tag>.
# 2. release: builds the ax CLI, renders deploy/ax-server.yaml with
# ax-server pinned by digest (and the runner volume, if the
# AX_RELEASE_RUNNER_VOLUME repository variable is "true"), and
# publishes the GitHub release with generated notes and those
# files attached.
#
# The highest stable tag also moves :latest; a prerelease never does.
#
# Part of #609 (stage 1); runs are validated in #610. See docs/releasing.md.
# Run manually to retry a release; only tags that contain this workflow work.
#
# A dry run (pull requests that touch the release, or a manual run with
# dry_run) does everything except publish: images go to a registry that exists
# only inside the job, and no release is created. Only google/ax publishes; in
# a fork only dry runs do anything, since packages are billed to the owner.
name: Release
on:
push:
# The filter cannot express the whole release tag, so hack/release/lib.sh
# rejects anything but vMAJOR.MINOR.PATCH[-PRERELEASE] before publishing.
tags: ['v[0-9]+.[0-9]+.[0-9]+*']
pull_request:
branches: [ main ]
paths:
- '.github/workflows/release.yml'
- 'hack/release/**'
- 'Dockerfile.*'
- '.dockerignore'
- 'deploy/**'
- 'install.sh'
- 'go.mod'
- 'go.sum'
- 'cmd/ax/**'
- 'cmd/ax-server/**'
- 'cmd/ax-runner/**'
- 'internal/version/**'
workflow_dispatch:
inputs:
tag:
description: 'Existing tag to release (e.g. v0.4.0); only tags that contain this workflow'
required: true
type: string
overwrite:
description: 'Rebuild and replace every image for the tag (refused once the release is published)'
type: boolean
default: false
dry_run:
description: 'Build everything but publish nothing: images go to a registry inside the job, no release is created'
type: boolean
default: false
# Each job requests the permissions it needs.
permissions:
contents: read
# Keyed by tag, not event, so a tag push and a manual run for the same tag
# never race on the existence check and push.
concurrency:
group: release-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || inputs.tag || github.ref_name }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
DRY_RUN: ${{ github.event_name == 'pull_request' || inputs.dry_run == true }}
# A pull request has no tag; its dry run builds a placeholder version.
TAG: ${{ inputs.tag || (github.event_name == 'pull_request' && 'v0.0.0-dryrun') || github.ref_name }}
# Pull requests build the merge commit; everything else builds the tag.
REF: ${{ github.event_name != 'pull_request' && format('refs/tags/{0}', inputs.tag || github.ref_name) || '' }}
jobs:
# The only job that writes to a registry.
images:
if: github.repository == 'google/ax' || github.event_name == 'pull_request' || inputs.dry_run
runs-on: ubuntu-latest
timeout-minutes: 45
# packages: write is granted on pull requests too (permissions cannot be
# conditional), but dry runs never log in, and fork PRs get a read-only
# token regardless.
permissions:
contents: read
packages: write
# Receives the images in a dry run.
services:
registry:
image: registry:3@sha256:82f6ff4a7f982960c8aa51617fea3aabc485df6e55cce80d22deb1de36f1bc3c
ports:
- 5000:5000
outputs:
server_image: ${{ steps.publish.outputs.AX_SERVER_IMAGE }}
task_image: ${{ steps.publish.outputs.AX_RUNNER_IMAGE }}
runner_volume_image: ${{ steps.publish.outputs.AX_RUNNER_VOLUME_REF }}
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ env.REF }}
# publish-images.sh reads every tag to decide whether to move :latest.
fetch-depth: 0
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version-file: go.mod
# This job can write packages, so it restores no cache another
# workflow could have written.
cache: false
# The Dockerfiles RUN apk/apt-get, so the arm64 build needs emulation.
- name: Set up QEMU
uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0
# BuildKit is pinned by digest because it builds a published image with
# the ghcr.io login. Host networking lets it reach the dry-run registry.
- name: Set up buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
with:
driver-opts: |
image=moby/buildkit:v0.33.1@sha256:cec9f139f45e93c5c69c60f8b07cfad9f43f4ef6b6a6cd917527fea5ff2e3dea
network=host
- name: Log in to ghcr.io
if: env.DRY_RUN != 'true'
env:
TOKEN: ${{ github.token }}
run: echo "${TOKEN}" | docker login ghcr.io --username "${GITHUB_ACTOR}" --password-stdin
# Releases are cut from main or a release-* branch, and nothing is rebuilt
# once a release is published: operators install it by digest.
- name: Check the tag and release
id: check
if: env.DRY_RUN != 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
source hack/release/lib.sh
require_release_version "${TAG}"
require_on_main "${TAG}"
state="$(release_state "${TAG}" "${GITHUB_REPOSITORY}")"
echo "Release ${TAG}: ${state}"
echo "release_state=${state}" >> "${GITHUB_OUTPUT}"
- name: Build and push images
id: publish
env:
AX_IMAGE_REPO: ${{ env.DRY_RUN == 'true' && 'localhost:5000/ax' || 'ghcr.io/google/ax' }}
AX_PUBLISH_OVERWRITE: ${{ inputs.overwrite == true }}
AX_RELEASE_STATE: ${{ steps.check.outputs.release_state || 'none' }}
GH_TOKEN: ${{ github.token }}
run: |
hack/release/publish-images.sh "${TAG}" bin/release
cat bin/release/images.env >> "${GITHUB_OUTPUT}"
{
echo "### Release images ${TAG} (dry run: ${DRY_RUN})"
echo ""
sed -e 's/^[A-Z_]*=/- `/' -e 's/$/`/' bin/release/images.env
} >> "${GITHUB_STEP_SUMMARY}"
# A rerun must reuse every image and record the same digests. The job's
# registry starts empty, so only a dry run can exercise this before a tag.
- name: Rerun reuses the images (dry run)
if: env.DRY_RUN == 'true'
env:
AX_IMAGE_REPO: localhost:5000/ax
run: |
set -o pipefail
cp bin/release/images.env /tmp/images.first.env
hack/release/publish-images.sh "${TAG}" bin/release | tee /tmp/rerun.log
diff /tmp/images.first.env bin/release/images.env
if grep -q 'Building and pushing' /tmp/rerun.log; then
echo "::error::The rerun rebuilt an image"
exit 1
fi
release:
needs: images
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ env.REF }}
# create-release.sh reads every tag to pick the notes start and Latest.
fetch-depth: 0
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version-file: go.mod
cache: false
- name: Build ax CLI
run: hack/release/build-binaries.sh "${TAG}" bin/release
- name: Render install manifests
env:
AX_SERVER_IMAGE: ${{ needs.images.outputs.server_image }}
AX_RUNNER_IMAGE: ${{ needs.images.outputs.task_image }}
AX_RUNNER_VOLUME_REF: ${{ needs.images.outputs.runner_volume_image }}
# Repository variable; "true" (case-insensitive) makes release
# manifests mount the runner from ax-runner-volume (#625). Off by
# default. Fork pull requests may not see repository variables.
AX_RENDER_RUNNER_VOLUME: ${{ vars.AX_RELEASE_RUNNER_VOLUME == 'true' }}
run: |
printf 'AX_SERVER_IMAGE=%s\nAX_RUNNER_IMAGE=%s\nAX_RUNNER_VOLUME_REF=%s\n' \
"${AX_SERVER_IMAGE}" "${AX_RUNNER_IMAGE}" "${AX_RUNNER_VOLUME_REF}" > bin/release/images.env
hack/release/render-manifests.sh bin/release
- name: Publish release
if: env.DRY_RUN != 'true'
env:
GH_TOKEN: ${{ github.token }}
run: hack/release/create-release.sh "${TAG}" bin/release
# Tags render with the switch as set; check both settings here, so each
# path stays covered whichever way the repository variable is set.
- name: Render with the runner volume off and on (dry run)
if: env.DRY_RUN == 'true'
run: |
set -o errexit -o nounset -o pipefail
for switch in false true; do
out="/tmp/rv-${switch}"
mkdir -p "${out}"
grep -v '^AX_RUNNER_VOLUME_IMAGE=' bin/release/images.env > "${out}/images.env"
AX_RENDER_RUNNER_VOLUME="${switch}" hack/release/render-manifests.sh "${out}"
unset AX_RUNNER_VOLUME_IMAGE
source "${out}/images.env"
want=""
if [[ "${switch}" == true ]]; then
want="${AX_RUNNER_VOLUME_REF}"
[[ -n "${want}" ]]
fi
if [[ "${AX_RUNNER_VOLUME_IMAGE}" != "${want}" ]]; then
echo "::error::AX_RENDER_RUNNER_VOLUME=${switch} recorded AX_RUNNER_VOLUME_IMAGE='${AX_RUNNER_VOLUME_IMAGE}', want '${want}'"
exit 1
fi
if ! grep -A1 'name: AX_RUNNER_VOLUME_IMAGE' "${out}/ax-server.yaml" | grep -qF "value: \"${want}\""; then
echo "::error::AX_RENDER_RUNNER_VOLUME=${switch} did not render value: \"${want}\" in ax-server.yaml"
exit 1
fi
done
- name: List release assets (dry run)
if: env.DRY_RUN == 'true'
run: ls -l bin/release && cat bin/release/images.env