-
Notifications
You must be signed in to change notification settings - Fork 909
198 lines (173 loc) · 6.35 KB
/
release-cli.yml
File metadata and controls
198 lines (173 loc) · 6.35 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
name: Release CLI
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: "Release tag to upload assets to (for example, v0.24)."
required: false
type: string
permissions:
contents: write
jobs:
build-cli:
strategy:
fail-fast: false
matrix:
include:
- name: linux-x64
runs-on: ubuntu-24.04
platform: linux
asset-arch: x86_64
build-arch: ""
static-swift-stdlib: true
- name: linux-arm64
runs-on: ubuntu-24.04-arm
platform: linux
asset-arch: aarch64
build-arch: ""
static-swift-stdlib: true
- name: macos-arm64
runs-on: macos-15
platform: macos
asset-arch: arm64
build-arch: arm64
static-swift-stdlib: false
- name: macos-x86_64
runs-on: macos-15-intel
platform: macos
asset-arch: x86_64
build-arch: x86_64
static-swift-stdlib: false
runs-on: ${{ matrix.runs-on }}
env:
RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
steps:
- uses: actions/checkout@v6
- name: Select Xcode 26.1.1 (if present) or fallback to default
if: matrix.platform == 'macos'
run: |
set -euo pipefail
for candidate in /Applications/Xcode_26.1.1.app /Applications/Xcode_26.1.app /Applications/Xcode.app; do
if [[ -d "$candidate" ]]; then
sudo xcode-select -s "${candidate}/Contents/Developer"
echo "DEVELOPER_DIR=${candidate}/Contents/Developer" >> "$GITHUB_ENV"
break
fi
done
/usr/bin/xcodebuild -version
- name: Runner info
run: |
set -euo pipefail
uname -a
uname -m
swift --version
- name: Install Swift 6.2.1 via swiftly
if: matrix.platform == 'linux'
shell: bash
run: |
set -euo pipefail
if ! command -v gpg >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y ca-certificates gpg
fi
SWIFTLY_ARCH="$(uname -m)"
SWIFTLY_HOME_DIR="$HOME/.local/share/swiftly"
SWIFTLY_BIN_DIR="$HOME/.local/bin"
POST_INSTALL_SCRIPT="$(mktemp)"
mkdir -p "$SWIFTLY_BIN_DIR"
curl -fsSL "https://download.swift.org/swiftly/linux/swiftly-${SWIFTLY_ARCH}.tar.gz" -o /tmp/swiftly.tar.gz
tar -xzf /tmp/swiftly.tar.gz -C /tmp
/tmp/swiftly init --assume-yes --skip-install
. "$SWIFTLY_HOME_DIR/env.sh"
echo "$SWIFTLY_BIN_DIR" >> "$GITHUB_PATH"
echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> "$GITHUB_ENV"
echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> "$GITHUB_ENV"
swiftly install 6.2.1 --use --assume-yes --post-install-file "$POST_INSTALL_SCRIPT"
if [[ -s "$POST_INSTALL_SCRIPT" ]]; then
sudo apt-get update
sudo bash "$POST_INSTALL_SCRIPT"
fi
hash -r
swift --version
- name: Build CodexBarCLI (release)
id: build
shell: bash
run: |
set -euo pipefail
BUILD_ARGS=(swift build -c release --product CodexBarCLI)
if [[ -n "${{ matrix.build-arch }}" ]]; then
BUILD_ARGS+=(--arch "${{ matrix.build-arch }}")
fi
if [[ "${{ matrix.static-swift-stdlib }}" == "true" ]]; then
BUILD_ARGS+=(--static-swift-stdlib)
fi
"${BUILD_ARGS[@]}"
SHOW_BIN_ARGS=(swift build -c release --product CodexBarCLI --show-bin-path)
if [[ -n "${{ matrix.build-arch }}" ]]; then
SHOW_BIN_ARGS+=(--arch "${{ matrix.build-arch }}")
fi
if [[ "${{ matrix.static-swift-stdlib }}" == "true" ]]; then
SHOW_BIN_ARGS+=(--static-swift-stdlib)
fi
echo "bin_dir=$("${SHOW_BIN_ARGS[@]}")" >> "$GITHUB_OUTPUT"
- name: Smoke test CodexBarCLI
timeout-minutes: 5
shell: bash
run: |
set -euo pipefail
BIN_DIR="${{ steps.build.outputs.bin_dir }}"
BIN="$BIN_DIR/CodexBarCLI"
echo "BIN=$BIN"
file "$BIN"
if [[ "${{ matrix.platform }}" == "macos" ]]; then
lipo -archs "$BIN" | tr ' ' '\n' | grep -Fx "${{ matrix.asset-arch }}"
else
"$BIN" --help
"$BIN" --version
file "$BIN" | grep -q "${{ matrix.asset-arch }}"
fi
- name: Package
id: pkg
shell: bash
run: |
set -euo pipefail
REF_NAME="${RELEASE_TAG}"
if [[ -z "$REF_NAME" ]]; then
echo "Missing release tag." >&2
exit 1
fi
SAFE_REF_NAME="${REF_NAME//\//-}"
BIN_DIR="${{ steps.build.outputs.bin_dir }}"
OUT_DIR="$(mktemp -d)"
install -m 0755 "$BIN_DIR/CodexBarCLI" "$OUT_DIR/CodexBarCLI"
ln -s "CodexBarCLI" "$OUT_DIR/codexbar"
ASSET="CodexBarCLI-${SAFE_REF_NAME}-${{ matrix.platform }}-${{ matrix.asset-arch }}.tar.gz"
(cd "$OUT_DIR" && tar czf "$ASSET" CodexBarCLI codexbar)
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$OUT_DIR/$ASSET" > "$OUT_DIR/$ASSET.sha256"
else
shasum -a 256 "$OUT_DIR/$ASSET" > "$OUT_DIR/$ASSET.sha256"
fi
echo "out_dir=$OUT_DIR" >> "$GITHUB_OUTPUT"
echo "asset=$ASSET" >> "$GITHUB_OUTPUT"
- name: Upload release assets
if: github.event_name == 'release' || inputs.tag != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
set -euo pipefail
TAG="${RELEASE_TAG}"
OUT_DIR="${{ steps.pkg.outputs.out_dir }}"
ASSET="${{ steps.pkg.outputs.asset }}"
gh release upload "$TAG" "$OUT_DIR/$ASSET" "$OUT_DIR/$ASSET.sha256" --clobber
- name: Upload workflow artifact (manual runs)
if: github.event_name != 'release' && inputs.tag == ''
uses: actions/upload-artifact@v6
with:
name: codexbar-cli-${{ matrix.name }}
path: |
${{ steps.pkg.outputs.out_dir }}/${{ steps.pkg.outputs.asset }}
${{ steps.pkg.outputs.out_dir }}/${{ steps.pkg.outputs.asset }}.sha256