-
Notifications
You must be signed in to change notification settings - Fork 0
311 lines (275 loc) · 9.39 KB
/
release.yml
File metadata and controls
311 lines (275 loc) · 9.39 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
name: Release
on:
push:
tags:
- "v*.*.*"
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
APP_NAME: eos-tui
HOMEBREW_TAP_REPO: lobis/homebrew-tap
jobs:
verify:
name: Verify release tag and Go checks
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v6
- name: Validate tag format
shell: bash
run: |
set -euo pipefail
if [[ ! "${GITHUB_REF_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Release tags must match vMAJOR.MINOR.PATCH, got ${GITHUB_REF_NAME}"
exit 1
fi
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true
- name: Verify formatting
shell: bash
run: |
set -euo pipefail
unformatted="$(gofmt -l .)"
if [ -n "$unformatted" ]; then
echo "These files need gofmt:"
echo "$unformatted"
exit 1
fi
- name: Run tests
env:
EOS_TEST_SKIP: "1"
run: go test ./...
- name: Build repository
run: go build ./...
build-native:
name: Build ${{ matrix.label }}
needs: verify
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- label: Linux amd64
runner: ubuntu-latest
goos: linux
goarch: amd64
exe_suffix: ""
archive_ext: tar.gz
asset_suffix: linux_amd64
- label: Linux arm64
runner: ubuntu-latest
goos: linux
goarch: arm64
exe_suffix: ""
archive_ext: tar.gz
asset_suffix: linux_arm64
- label: macOS amd64
runner: macos-latest
goos: darwin
goarch: amd64
exe_suffix: ""
archive_ext: tar.gz
asset_suffix: macos_amd64
- label: Windows amd64
runner: windows-latest
goos: windows
goarch: amd64
exe_suffix: .exe
archive_ext: zip
asset_suffix: windows_amd64
steps:
- name: Check out repository
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true
- name: Build binary
shell: bash
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
EXE_SUFFIX: ${{ matrix.exe_suffix }}
run: |
set -euo pipefail
mkdir -p dist
CGO_ENABLED=0 go build -trimpath -buildvcs=false -ldflags="-s -w" -o "dist/${APP_NAME}${EXE_SUFFIX}" .
- name: Package archive
shell: bash
env:
EXE_SUFFIX: ${{ matrix.exe_suffix }}
ARCHIVE_PATH: dist/${{ env.APP_NAME }}_${{ github.ref_name }}_${{ matrix.asset_suffix }}.${{ matrix.archive_ext }}
run: |
set -euo pipefail
export BINARY_PATH="dist/${APP_NAME}${EXE_SUFFIX}"
python - <<'PY'
import os
import tarfile
import zipfile
from pathlib import Path
binary_path = Path(os.environ["BINARY_PATH"])
archive_path = Path(os.environ["ARCHIVE_PATH"])
archive_path.parent.mkdir(parents=True, exist_ok=True)
if archive_path.suffix == ".zip":
with zipfile.ZipFile(archive_path, "w", compression=zipfile.ZIP_DEFLATED) as zf:
zf.write(binary_path, arcname=binary_path.name)
else:
with tarfile.open(archive_path, "w:gz") as tf:
tf.add(binary_path, arcname=binary_path.name)
PY
- name: Upload release archive
uses: actions/upload-artifact@v7
with:
name: release-${{ matrix.asset_suffix }}
path: dist/${{ env.APP_NAME }}_${{ github.ref_name }}_${{ matrix.asset_suffix }}.${{ matrix.archive_ext }}
build-rpm:
name: Build RPM AlmaLinux ${{ matrix.alma_major }} ${{ matrix.arch }}
needs: verify
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- alma_major: "9"
arch: x86_64
platform: linux/amd64
go_bootstrap_arch: amd64
- alma_major: "9"
arch: aarch64
platform: linux/arm64
go_bootstrap_arch: arm64
- alma_major: "10"
arch: x86_64
platform: linux/amd64
go_bootstrap_arch: amd64
- alma_major: "10"
arch: aarch64
platform: linux/arm64
go_bootstrap_arch: arm64
steps:
- name: Set up QEMU
if: matrix.arch == 'aarch64'
uses: docker/setup-qemu-action@v4
- name: Check out repository
uses: actions/checkout@v6
- name: Prepare RPM sources
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME#v}"
rm -rf packaging
mkdir -p packaging/SOURCES packaging/SPECS
git archive --format=tar.gz --prefix="${APP_NAME}-${version}/" -o "packaging/SOURCES/${APP_NAME}-${version}.tar.gz" HEAD
cp "${APP_NAME}.spec" packaging/SPECS/
- name: Build RPM
shell: bash
env:
ALMA_IMAGE: almalinux:${{ matrix.alma_major }}
CONTAINER_PLATFORM: ${{ matrix.platform }}
GO_BOOTSTRAP_ARCH: ${{ matrix.go_bootstrap_arch }}
run: |
set -euo pipefail
version="${GITHUB_REF_NAME#v}"
go_version="$(awk '/^go / { print $2 }' go.mod)"
docker run --rm \
--platform "${CONTAINER_PLATFORM}" \
-v "${PWD}:/workspace" \
-w /workspace \
"${ALMA_IMAGE}" \
bash -lc '
set -euo pipefail
dnf install -y tar gzip rpm-build
curl -fsSL "https://go.dev/dl/go'"${go_version}"'.linux-'"${GO_BOOTSTRAP_ARCH}"'.tar.gz" -o /tmp/go.tgz
rm -rf /usr/local/go
tar -C /usr/local -xzf /tmp/go.tgz
export PATH=/usr/local/go/bin:$PATH
rpmbuild \
--define "_topdir /workspace/packaging" \
--define "pkg_version '"${version}"'" \
--define "pkg_release 1" \
-bb /workspace/packaging/SPECS/'"${APP_NAME}"'.spec
'
- name: Upload RPM artifacts
uses: actions/upload-artifact@v7
with:
name: release-rpm-el${{ matrix.alma_major }}-${{ matrix.arch }}
path: packaging/RPMS/*/*.rpm
github-release:
name: Create GitHub release
needs: [build-native, build-rpm]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download release artifacts
uses: actions/download-artifact@v8
with:
path: release-artifacts
merge-multiple: true
- name: Generate checksums
shell: bash
run: |
set -euo pipefail
cd release-artifacts
sha256sum * > SHA256SUMS.txt
- name: Publish GitHub release
uses: softprops/action-gh-release@v2
with:
files: release-artifacts/*
generate_release_notes: true
update-homebrew-tap:
name: Update Homebrew tap
needs: github-release
runs-on: ubuntu-latest
steps:
- name: Update tap formula
shell: bash
env:
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
run: |
set -euo pipefail
if [ -z "${HOMEBREW_TAP_GITHUB_TOKEN}" ]; then
echo "::warning::HOMEBREW_TAP_GITHUB_TOKEN is not configured; skipping Homebrew tap update."
exit 0
fi
version="${GITHUB_REF_NAME#v}"
source_url="https://github.com/${GITHUB_REPOSITORY}/archive/refs/tags/${GITHUB_REF_NAME}.tar.gz"
curl -fsSL -o /tmp/eos-tui-source.tar.gz "${source_url}"
source_sha="$(sha256sum /tmp/eos-tui-source.tar.gz | awk '{print $1}')"
git clone "https://x-access-token:${HOMEBREW_TAP_GITHUB_TOKEN}@github.com/${HOMEBREW_TAP_REPO}.git" /tmp/homebrew-tap
mkdir -p /tmp/homebrew-tap/Formula
cat > /tmp/homebrew-tap/Formula/eos-tui.rb <<EOF
class EosTui < Formula
desc "Terminal UI for monitoring and managing EOS storage clusters"
homepage "https://github.com/${GITHUB_REPOSITORY}"
url "${source_url}"
version "${version}"
sha256 "${source_sha}"
license "MIT"
head "https://github.com/${GITHUB_REPOSITORY}.git", branch: "main"
depends_on "go" => :build
def install
system "go", "build", *std_go_args(ldflags: "-s -w"), "."
end
test do
assert_match "Usage:", shell_output("#{bin}/eos-tui --help 2>&1")
end
end
EOF
cd /tmp/homebrew-tap
if git diff --quiet -- Formula/eos-tui.rb; then
echo "Homebrew formula already up to date."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add Formula/eos-tui.rb
git commit -m "Update eos-tui to ${GITHUB_REF_NAME}"
git push origin HEAD:main