Repository navigation
350 lines (286 loc) · 9.9 KB
/
Copy pathrelease.yml
File metadata and controls
350 lines (286 loc) · 9.9 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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
name: Release
on:
push:
tags:
- 'v*'
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Build (${{ matrix.name }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: Linux x86_64
target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- name: Linux ARM64
target: aarch64-unknown-linux-gnu
os: ubuntu-24.04-arm
- name: macOS ARM64
target: aarch64-apple-darwin
os: macos-latest
steps:
- uses: actions/checkout@v6.0.2
with:
submodules: recursive
- name: Install dependencies (Ubuntu)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libncurses-dev
- name: Install Rust
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
- name: Set version from tag
run: |
# Extract version from tag (e.g., v0.1.0 -> 0.1.0)
VERSION="${GITHUB_REF_NAME#v}"
echo "Setting version to $VERSION"
sed -i.bak "s/^version = .*/version = \"$VERSION\"/" Cargo.toml
rm -f Cargo.toml.bak
grep "^version" Cargo.toml
- name: Build
run: cargo build --release
- name: Run tests
run: cargo test --release -- --test-threads=1
- name: Package
shell: bash
run: |
cd target/release
tar czvf ../../bash-ast-${{ github.ref_name }}-${{ matrix.target }}.tar.gz bash-ast
cd ../..
- name: Upload artifact
uses: actions/upload-artifact@v7.0.0
with:
name: bash-ast-${{ matrix.target }}
path: bash-ast-${{ github.ref_name }}-${{ matrix.target }}.tar.gz
linux-packages:
name: Build Linux Packages (${{ matrix.arch }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
os: ubuntu-22.04 # Use older glibc for wider compatibility
- arch: arm64
os: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v6.0.2
with:
submodules: recursive
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libncurses-dev rpm
- name: Install Rust
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
- name: Install packaging tools
run: cargo install cargo-deb cargo-generate-rpm
- name: Set version from tag
run: |
VERSION="${GITHUB_REF_NAME#v}"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Setting version to $VERSION"
sed -i "s/^version = .*/version = \"$VERSION\"/" Cargo.toml
grep "^version" Cargo.toml
- name: Build release
run: cargo build --release
- name: Build .deb package
run: |
cargo deb --no-build
ls -la target/debian/
- name: Build .rpm package
run: |
cargo generate-rpm
ls -la target/generate-rpm/
- name: Upload .deb artifact
uses: actions/upload-artifact@v7.0.0
with:
name: linux-deb-${{ matrix.arch }}
path: target/debian/*.deb
- name: Upload .rpm artifact
uses: actions/upload-artifact@v7.0.0
with:
name: linux-rpm-${{ matrix.arch }}
path: target/generate-rpm/*.rpm
bottle:
name: Build Bottle (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: macos-14 # ARM64 (M1/M2) - Sonoma
bottle_tag: arm64_sonoma
- os: macos-15 # ARM64 - Sequoia
bottle_tag: arm64_sequoia
steps:
- uses: actions/checkout@v6.0.2
- name: Set up Homebrew
uses: Homebrew/actions/setup-homebrew@main
- name: Tap and install formula for bottling
env:
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_INSTALL_FROM_API: 1
run: |
# Create a local tap with updated formula
TAP_DIR="$(brew --repository)/Library/Taps/cv/homebrew-taps"
mkdir -p "$TAP_DIR/Formula"
# Get tag info
TAG="${{ github.ref_name }}"
REVISION="${{ github.sha }}"
# Update formula with tag and revision
sed \
-e "s/VERSION_TAG_PLACEHOLDER/${TAG}/" \
-e "s/REVISION_PLACEHOLDER/${REVISION}/" \
Formula/bash-ast.rb > "$TAP_DIR/Formula/bash-ast.rb"
echo "Formula contents:"
cat "$TAP_DIR/Formula/bash-ast.rb"
# Build bottle
brew install --build-bottle cv/taps/bash-ast
- name: Create bottle
run: |
cd $(mktemp -d)
brew bottle --no-rebuild --json cv/taps/bash-ast
# Rename bottle to standard format
# Homebrew creates: bash-ast--VERSION.BOTTLE_TAG.bottle.tar.gz
# We want: bash-ast-VERSION.BOTTLE_TAG.bottle.tar.gz
for f in bash-ast--*.bottle.tar.gz; do
newname="${f/bash-ast--/bash-ast-}"
mv "$f" "$newname" 2>/dev/null || true
done
# Also rename in JSON
for f in bash-ast--*.bottle.json; do
newname="${f/bash-ast--/bash-ast-}"
mv "$f" "$newname" 2>/dev/null || true
done
ls -la
# Move to workspace
mv bash-ast-*.bottle.* ${{ github.workspace }}/
- name: Upload bottle artifact
uses: actions/upload-artifact@v7.0.0
with:
name: bottle-${{ matrix.bottle_tag }}
path: |
bash-ast-*.bottle.tar.gz
bash-ast-*.bottle.json
release:
name: Create Release
needs: [build, bottle, linux-packages]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6.0.2
- name: Download all artifacts
uses: actions/download-artifact@v8.0.1
with:
path: artifacts
merge-multiple: true
- name: List artifacts
run: ls -la artifacts/
- name: Create GitHub Release
uses: softprops/action-gh-release@v2.6.1
with:
files: |
artifacts/*.tar.gz
artifacts/*.deb
artifacts/*.rpm
generate_release_notes: true
draft: false
prerelease: ${{ contains(github.ref_name, '-') }}
homebrew:
name: Update Homebrew Formula
needs: [release, bottle]
runs-on: ubuntu-latest
# Skip for prereleases
if: ${{ !contains(github.ref_name, '-') }}
steps:
- name: Checkout bash-ast
uses: actions/checkout@v6.0.2
- name: Download bottle artifacts
uses: actions/download-artifact@v8.0.1
with:
pattern: bottle-*
path: bottles
merge-multiple: true
- name: List bottles
run: ls -la bottles/
- name: Generate bottle block
id: bottle
run: |
TAG="${{ github.ref_name }}"
VERSION="${TAG#v}"
# Collect SHA256 hashes from JSON files
echo "Generating bottle block..."
BOTTLE_BLOCK=" bottle do"
BOTTLE_BLOCK+="\n root_url \"https://github.com/cv/bash-ast/releases/download/${TAG}\""
# Process each bottle JSON file
for json_file in bottles/*.bottle.json; do
if [ -f "$json_file" ]; then
echo "Processing $json_file"
cat "$json_file"
# Extract tag and sha256 from JSON
# The JSON structure is: {"cv/taps/bash-ast": {"formula": {...}, "bottle": {"tags": {"arm64_sonoma": {"sha256": "..."}}}}}
TAGS=$(jq -r '.["cv/taps/bash-ast"].bottle.tags | keys[]' "$json_file" 2>/dev/null || jq -r '.[].bottle.tags | keys[]' "$json_file")
for tag in $TAGS; do
SHA=$(jq -r ".\"cv/taps/bash-ast\".bottle.tags.\"$tag\".sha256 // .[].bottle.tags.\"$tag\".sha256" "$json_file")
echo " Tag: $tag, SHA: $SHA"
BOTTLE_BLOCK+="\n sha256 cellar: :any_skip_relocation, $tag: \"$SHA\""
done
fi
done
BOTTLE_BLOCK+="\n end"
echo "Generated bottle block:"
echo -e "$BOTTLE_BLOCK"
# Save to file for next step
echo -e "$BOTTLE_BLOCK" > bottle_block.txt
- name: Generate updated formula
run: |
TAG="${{ github.ref_name }}"
VERSION="${TAG#v}"
REVISION="${{ github.sha }}"
# Start with template
cp Formula/bash-ast.rb formula_updated.rb
# Update tag and revision
sed -i \
-e "s/VERSION_TAG_PLACEHOLDER/${TAG}/" \
-e "s/REVISION_PLACEHOLDER/${REVISION}/" \
formula_updated.rb
# Insert bottle block after license line
BOTTLE_BLOCK=$(cat bottle_block.txt)
# Use awk to insert bottle block after license line
awk -v bottle="$BOTTLE_BLOCK" '
/^ license/ {
print
print bottle
next
}
{ print }
' formula_updated.rb > formula_final.rb
echo "Final formula:"
cat formula_final.rb
mv formula_final.rb Formula/bash-ast.rb
- name: Checkout homebrew-taps
uses: actions/checkout@v6.0.2
with:
repository: cv/homebrew-taps
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
path: homebrew-taps
- name: Update formula in tap
run: |
mkdir -p homebrew-taps/Formula
cp Formula/bash-ast.rb homebrew-taps/Formula/
cd homebrew-taps
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/bash-ast.rb
git diff --staged --quiet || git commit -m "bash-ast ${{ github.ref_name }}"
git push