-
Notifications
You must be signed in to change notification settings - Fork 0
251 lines (224 loc) · 8 KB
/
Copy pathrelease.yml
File metadata and controls
251 lines (224 loc) · 8 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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "Tag to release (e.g. v0.1.0). Must already exist."
required: true
permissions:
contents: write
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- target: macos-arm64
runner: macos-14
archive: tar.gz
- target: macos-x86_64
runner: macos-13
archive: tar.gz
- target: linux-arm64
runner: ubuntu-24.04-arm
archive: tar.gz
- target: linux-x86_64
runner: ubuntu-24.04
archive: tar.gz
- target: windows-x86_64
runner: windows-latest
archive: zip
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.tag || github.ref }}
- name: Setup Dart
uses: dart-lang/setup-dart@v1
- name: Resolve tag
id: tag
shell: bash
run: |
if [ -n "${{ github.event.inputs.tag }}" ]; then
echo "name=${{ github.event.inputs.tag }}" >> "$GITHUB_OUTPUT"
else
echo "name=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
fi
- name: Verify pubspec version matches tag
shell: bash
run: |
tag="${{ steps.tag.outputs.name }}"
pubspec_version=$(awk '/^version:/ {print $2}' pubspec.yaml)
expected="v${pubspec_version}"
if [ "$tag" != "$expected" ]; then
echo "::error::Tag $tag does not match pubspec.yaml version $pubspec_version (expected $expected)"
exit 1
fi
- name: Install dependencies
run: dart pub get
- name: Compile binary (Unix)
if: runner.os != 'Windows'
run: |
mkdir -p build
dart compile exe bin/space.dart -o build/space
- name: Compile binary (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path build | Out-Null
dart compile exe bin/space.dart -o build/space.exe
- name: Package archive (Unix)
if: matrix.archive == 'tar.gz'
shell: bash
run: |
name="space-cli-${{ matrix.target }}"
staging="dist/$name"
mkdir -p "$staging"
cp build/space "$staging/"
cp README.md LICENSE "$staging/" 2>/dev/null || cp README.md "$staging/"
tar -czf "dist/${name}.tar.gz" -C dist "$name"
(cd dist && shasum -a 256 "${name}.tar.gz" > "${name}.tar.gz.sha256")
- name: Package archive (Windows)
if: matrix.archive == 'zip'
shell: pwsh
run: |
$name = "space-cli-${{ matrix.target }}"
$staging = "dist/$name"
New-Item -ItemType Directory -Force -Path $staging | Out-Null
Copy-Item build/space.exe "$staging/"
Copy-Item README.md "$staging/"
Compress-Archive -Path "$staging/*" -DestinationPath "dist/${name}.zip"
$hash = (Get-FileHash -Algorithm SHA256 "dist/${name}.zip").Hash.ToLower()
"$hash ${name}.zip" | Out-File -FilePath "dist/${name}.zip.sha256" -Encoding ascii
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: |
dist/*.tar.gz
dist/*.zip
dist/*.sha256
if-no-files-found: error
retention-days: 7
release:
name: Publish GitHub Release
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Assemble checksums.txt
run: |
mkdir -p release
find artifacts -type f \( -name "*.tar.gz" -o -name "*.zip" \) -exec cp {} release/ \;
cd release
sha256sum ./*.tar.gz ./*.zip | sed 's| \./| |g' > checksums.txt
cat checksums.txt
- name: Resolve tag
id: tag
run: |
if [ -n "${{ github.event.inputs.tag }}" ]; then
echo "name=${{ github.event.inputs.tag }}" >> "$GITHUB_OUTPUT"
else
echo "name=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.tag.outputs.name }}
name: ${{ steps.tag.outputs.name }}
draft: false
prerelease: ${{ contains(steps.tag.outputs.name, '-') }}
generate_release_notes: true
files: |
release/*.tar.gz
release/*.zip
release/checksums.txt
homebrew:
name: Update Homebrew Tap
runs-on: ubuntu-latest
needs: release
if: ${{ !contains(github.ref, '-') }}
steps:
- name: Checkout tap
uses: actions/checkout@v4
with:
repository: space-org/homebrew-tap
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
path: tap
- name: Resolve tag and version
id: meta
run: |
tag="${GITHUB_REF#refs/tags/}"
echo "tag=$tag" >> "$GITHUB_OUTPUT"
echo "version=${tag#v}" >> "$GITHUB_OUTPUT"
- name: Fetch checksums
id: sums
run: |
tag="${{ steps.meta.outputs.tag }}"
base="https://github.com/${{ github.repository }}/releases/download/${tag}"
curl -fsSL "${base}/checksums.txt" -o checksums.txt
get() { grep " $1$" checksums.txt | awk '{print $1}'; }
{
echo "macos_arm64=$(get space-cli-macos-arm64.tar.gz)"
echo "macos_x86_64=$(get space-cli-macos-x86_64.tar.gz)"
echo "linux_arm64=$(get space-cli-linux-arm64.tar.gz)"
echo "linux_x86_64=$(get space-cli-linux-x86_64.tar.gz)"
} >> "$GITHUB_OUTPUT"
- name: Render formula
run: |
cat > tap/Formula/space-cli.rb <<EOF
class SpaceCli < Formula
desc "CLI for querying your local Space flashcard database"
homepage "https://getspace.dev/cli"
version "${{ steps.meta.outputs.version }}"
license "MIT"
on_macos do
on_arm do
url "https://github.com/${{ github.repository }}/releases/download/${{ steps.meta.outputs.tag }}/space-cli-macos-arm64.tar.gz"
sha256 "${{ steps.sums.outputs.macos_arm64 }}"
end
on_intel do
url "https://github.com/${{ github.repository }}/releases/download/${{ steps.meta.outputs.tag }}/space-cli-macos-x86_64.tar.gz"
sha256 "${{ steps.sums.outputs.macos_x86_64 }}"
end
end
on_linux do
on_arm do
url "https://github.com/${{ github.repository }}/releases/download/${{ steps.meta.outputs.tag }}/space-cli-linux-arm64.tar.gz"
sha256 "${{ steps.sums.outputs.linux_arm64 }}"
end
on_intel do
url "https://github.com/${{ github.repository }}/releases/download/${{ steps.meta.outputs.tag }}/space-cli-linux-x86_64.tar.gz"
sha256 "${{ steps.sums.outputs.linux_x86_64 }}"
end
end
def install
bin.install "space"
end
test do
assert_match "space-cli", shell_output("#{bin}/space --version")
end
end
EOF
- name: Commit and push
run: |
cd tap
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add Formula/space-cli.rb
if git diff --cached --quiet; then
echo "No changes to formula."
exit 0
fi
git commit -m "space-cli ${{ steps.meta.outputs.tag }}"
git push