forked from tracewayapp/traceway
-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (99 loc) · 3.38 KB
/
Copy pathrelease-cli.yml
File metadata and controls
109 lines (99 loc) · 3.38 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
name: Release CLI
on:
push:
tags:
- 'backend/v*'
workflow_dispatch:
inputs:
version:
description: "Release version (X.Y.Z, no leading v)"
required: true
type: string
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Determine version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "version=${{ inputs.version }}" >> "$GITHUB_OUTPUT"
else
TAG="${{ github.ref_name }}"
echo "version=${TAG#backend/v}" >> "$GITHUB_OUTPUT"
fi
- name: Validate version format
run: |
if ! [[ "${{ steps.version.outputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: version must be in X.Y.Z format (got '${{ steps.version.outputs.version }}')"
exit 1
fi
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check tag does not already exist
run: |
TAG="cli/v${{ steps.version.outputs.version }}"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Error: tag $TAG already exists"
exit 1
fi
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: cli/go.mod
cache-dependency-path: cli/go.sum
- name: Build cross-platform binaries
working-directory: cli
env:
VERSION: ${{ steps.version.outputs.version }}
CGO_ENABLED: "0"
run: |
set -euo pipefail
mkdir -p dist
# OS ARCH LABEL — LABEL is the user-facing arch name in the archive filename
PAIRS=(
"linux amd64 x86_64"
"linux arm64 arm64"
"darwin amd64 x86_64"
"darwin arm64 arm64"
"windows amd64 x86_64"
)
for entry in "${PAIRS[@]}"; do
read -r OS ARCH LABEL <<< "$entry"
STAGE="dist/staging/${OS}_${LABEL}"
mkdir -p "$STAGE"
BIN="traceway"
[[ "$OS" == "windows" ]] && BIN="traceway.exe"
echo "Building $OS/$ARCH -> $STAGE/$BIN"
GOOS="$OS" GOARCH="$ARCH" go build -trimpath -ldflags "-X main.version=${VERSION}" -o "$STAGE/$BIN" ./cmd/traceway
cp README.md "$STAGE/"
cp ../LICENSE "$STAGE/"
ARCHIVE_BASE="traceway_${VERSION}_${OS}_${LABEL}"
if [[ "$OS" == "windows" ]]; then
(cd "$STAGE" && zip -q "../../${ARCHIVE_BASE}.zip" *)
else
tar -C "$STAGE" -czf "dist/${ARCHIVE_BASE}.tar.gz" .
fi
done
rm -rf dist/staging
ls -la dist
- name: Generate checksums
working-directory: cli/dist
run: |
sha256sum * > checksums.txt
cat checksums.txt
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.version }}
run: |
NOTES="CLI v${VERSION}, released alongside [Backend v${VERSION}](https://github.com/${{ github.repository }}/releases/tag/backend/v${VERSION})."
gh release create "cli/v${VERSION}" \
--target "${{ github.sha }}" \
--title "CLI v${VERSION}" \
--notes "$NOTES" \
cli/dist/*