-
Notifications
You must be signed in to change notification settings - Fork 2
203 lines (179 loc) · 6.51 KB
/
Copy pathrelease.yml
File metadata and controls
203 lines (179 loc) · 6.51 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
name: Release
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
tag:
description: "Release tag (e.g. v0.1.0)"
required: true
type: string
permissions:
contents: write
id-token: write
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
env:
BIN_NAME: cefas
NPM_PACKAGE: "@cefasdb/cefas"
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ env.RELEASE_TAG }}
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Test
run: go test ./cmd/cefasctl/...
- name: Build binaries
shell: bash
run: |
set -euo pipefail
mkdir -p dist
VERSION="${RELEASE_TAG#v}"
# 386 only makes sense for linux today — it's used by the
# cefas-sandbox V86 image (V86 is a 32-bit x86 emulator).
# darwin and windows dropped 386 long ago.
for GOOS in linux darwin windows; do
for GOARCH in amd64 arm64 386; do
if [ "$GOARCH" = "386" ] && [ "$GOOS" != "linux" ]; then
continue
fi
ext=""
if [ "$GOOS" = "windows" ]; then ext=".exe"; fi
echo "Building cefasctl $GOOS/$GOARCH"
CGO_ENABLED=0 GOOS="$GOOS" GOARCH="$GOARCH" \
go build -trimpath \
-ldflags "-s -w -X github.com/CefasDb/cefasdb/cmd/cefasctl/cmd.Version=${VERSION}" \
-o "dist/${BIN_NAME}-${GOOS}-${GOARCH}${ext}" \
./cmd/cefasctl
if [ "$GOOS" = "windows" ]; then
continue
fi
echo "Building cefasdb $GOOS/$GOARCH"
CGO_ENABLED=0 GOOS="$GOOS" GOARCH="$GOARCH" \
go build -trimpath \
-ldflags "-s -w" \
-o "dist/${BIN_NAME}-server-${GOOS}-${GOARCH}${ext}" \
./cmd/cefasdb
done
done
- name: Checksums
shell: bash
run: |
set -euo pipefail
# dist/ also holds the publishable helm/ and npm/ trees
# (committed). Only the just-built cefas-* binaries belong
# in SHA256SUMS.txt.
(cd dist && shasum -a 256 cefas-* > SHA256SUMS.txt)
- name: GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ env.RELEASE_TAG }}
name: ${{ env.RELEASE_TAG }}
generate_release_notes: true
files: |
dist/cefas-*
dist/SHA256SUMS.txt
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: "20"
registry-url: "https://registry.npmjs.org"
scope: "@cefasdb"
- name: Publish npm package (npmjs)
shell: bash
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
set -euo pipefail
if [ -z "${NODE_AUTH_TOKEN:-}" ]; then
echo "Missing secret NPM_TOKEN (required to publish to registry.npmjs.org)." >&2
exit 1
fi
VERSION="${RELEASE_TAG#v}"
cd dist/npm
npm version --no-git-tag-version --allow-same-version "$VERSION"
npm pack --dry-run --registry=https://registry.npmjs.org --@cefasdb:registry=https://registry.npmjs.org
npm publish --access public --registry=https://registry.npmjs.org --@cefasdb:registry=https://registry.npmjs.org
- name: Smoke test npm install
shell: bash
run: |
set -euo pipefail
VERSION="${RELEASE_TAG#v}"
PREFIX="${RUNNER_TEMP}/cefas-npm-smoke"
for attempt in {1..12}; do
if npm view "${NPM_PACKAGE}@${VERSION}" version --registry=https://registry.npmjs.org --@cefasdb:registry=https://registry.npmjs.org >/dev/null 2>&1; then
break
fi
if [ "$attempt" -eq 12 ]; then
echo "Package ${NPM_PACKAGE}@${VERSION} was not visible on npm after waiting." >&2
exit 1
fi
sleep 10
done
npm install --global --prefix "$PREFIX" "${NPM_PACKAGE}@${VERSION}" --registry=https://registry.npmjs.org --@cefasdb:registry=https://registry.npmjs.org
"$PREFIX/bin/${BIN_NAME}" version
publish-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/cefasdb
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ env.RELEASE_TAG }}
- name: Compute version
id: vars
shell: bash
run: |
set -euo pipefail
VERSION="${RELEASE_TAG#v}"
echo "version=${VERSION}" >>"$GITHUB_OUTPUT"
echo "image_lower=${REGISTRY}/${IMAGE_NAME,,}" >>"$GITHUB_OUTPUT"
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push cefas image
uses: docker/build-push-action@v7
with:
context: .
file: ./deploy/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
provenance: false
build-args: |
VERSION=${{ steps.vars.outputs.version }}
COMMIT=${{ github.sha }}
tags: |
${{ steps.vars.outputs.image_lower }}:${{ steps.vars.outputs.version }}
${{ steps.vars.outputs.image_lower }}:${{ env.RELEASE_TAG }}
${{ steps.vars.outputs.image_lower }}:latest
labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ steps.vars.outputs.version }}
# Package visibility is a one-time setting per package, not per release.
# After the first push, set it via:
# https://github.com/users/<owner>/packages/container/cefasdb/settings
# -> "Danger Zone" -> "Change package visibility" -> Public.
# The setting persists across all subsequent pushes.