-
Notifications
You must be signed in to change notification settings - Fork 0
497 lines (423 loc) · 18.8 KB
/
Copy pathrelease.yml
File metadata and controls
497 lines (423 loc) · 18.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
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
name: Release
on:
workflow_dispatch:
inputs:
dry_run:
description: 'Dry run (skip actual release)'
type: boolean
default: false
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
BINARY_NAME: git-sc
jobs:
prepare-release:
name: Prepare Release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.bump.outputs.version }}
tag: ${{ steps.bump.outputs.tag }}
steps:
- uses: actions/checkout@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Bump version
id: bump
run: |
# Use 2-digit year (YY) for Windows MSI compatibility (major version must be <= 255)
YEAR=$(date +%y)
MONTH=$(date +%-m)
CURRENT=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
echo "Current version: ${CURRENT}"
if echo "${CURRENT}" | grep -qE '^[0-9]{2,4}\.[0-9]{1,2}\.[0-9]+$'; then
OLD_YEAR=$(echo "${CURRENT}" | cut -d. -f1)
OLD_MONTH=$(echo "${CURRENT}" | cut -d. -f2)
OLD_COUNTER=$(echo "${CURRENT}" | cut -d. -f3)
# Handle both 2-digit and 4-digit year formats
OLD_YEAR_2DIGIT=$(echo "${OLD_YEAR}" | sed 's/^20//')
if [ "${OLD_YEAR_2DIGIT}" = "${YEAR}" ] && [ "${OLD_MONTH}" = "${MONTH}" ]; then
NEW_COUNTER=$((OLD_COUNTER + 1))
else
NEW_COUNTER=100
fi
else
NEW_COUNTER=100
fi
NEW_VERSION="${YEAR}.${MONTH}.${NEW_COUNTER}"
echo "New version: ${NEW_VERSION}"
# Only replace the first occurrence (package version, not dependency versions)
sed -i "0,/^version = \"[^\"]*\"/s//version = \"${NEW_VERSION}\"/" Cargo.toml
if [ -f "Cargo.lock" ]; then
cargo generate-lockfile 2>/dev/null || true
fi
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
echo "tag=v${NEW_VERSION}" >> $GITHUB_OUTPUT
- name: Commit and tag
if: ${{ !inputs.dry_run }}
run: |
git add Cargo.toml
[ -f "Cargo.lock" ] && git add Cargo.lock || true
git commit -m "Release ${{ steps.bump.outputs.tag }}"
git tag -a "${{ steps.bump.outputs.tag }}" -m "Release ${{ steps.bump.outputs.tag }}"
git push origin HEAD "${{ steps.bump.outputs.tag }}"
- name: Dry run info
if: ${{ inputs.dry_run }}
run: |
echo "🧪 Dry run mode - skipping commit and tag"
echo "Would release: ${{ steps.bump.outputs.tag }}"
build:
name: Build (${{ matrix.target }})
needs: prepare-release
if: ${{ !inputs.dry_run }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact_name: git-sc
asset_name: git-sc-x86_64-unknown-linux-gnu.tar.gz
cross: false
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
artifact_name: git-sc
asset_name: git-sc-aarch64-unknown-linux-gnu.tar.gz
cross: true
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: git-sc
asset_name: git-sc-x86_64-apple-darwin.tar.gz
cross: false
- os: macos-latest
target: aarch64-apple-darwin
artifact_name: git-sc
asset_name: git-sc-aarch64-apple-darwin.tar.gz
cross: false
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: git-sc.exe
asset_name: git-sc-x86_64-pc-windows-msvc.zip
cross: false
steps:
- uses: actions/checkout@v5
with:
ref: ${{ needs.prepare-release.outputs.tag }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross-compilation tools
if: matrix.cross
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Build with cross
if: matrix.cross
run: |
cargo install cross --git https://github.com/cross-rs/cross
cross build --release --target ${{ matrix.target }}
- name: Build
if: "!matrix.cross"
run: cargo build --release --target ${{ matrix.target }}
- name: Package (Unix)
if: runner.os != 'Windows'
run: |
cd target/${{ matrix.target }}/release
tar czvf ../../../${{ matrix.asset_name }} ${{ matrix.artifact_name }}
cd ../../..
- name: Package (Windows)
if: runner.os == 'Windows'
run: |
cd target/${{ matrix.target }}/release
7z a ../../../${{ matrix.asset_name }} ${{ matrix.artifact_name }}
cd ../../..
- name: Upload artifact
uses: actions/upload-artifact@v6
with:
name: ${{ matrix.asset_name }}
path: ${{ matrix.asset_name }}
release:
name: Create Release
needs: [prepare-release, build]
if: ${{ !inputs.dry_run }}
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v7
with:
path: artifacts
- name: Prepare release files
run: |
mkdir -p release
find artifacts -type f \( -name "*.tar.gz" -o -name "*.zip" \) -exec mv {} release/ \;
ls -la release/
- name: Create Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ needs.prepare-release.outputs.tag }}
name: ${{ needs.prepare-release.outputs.tag }}
body: |
## git-sc ${{ needs.prepare-release.outputs.version }}
AI-powered smart commit message generator for coding agents
### Installation
#### Homebrew (macOS/Linux)
```bash
brew install owayo/git-sc/git-sc
```
#### WinGet (Windows)
```powershell
winget install owayo.git-sc
```
Open a new terminal afterwards so the updated PATH takes effect.
#### Manual Download
Download the appropriate binary for your platform and add it to your PATH.
#### macOS (Apple Silicon)
```bash
curl -L https://github.com/${{ github.repository }}/releases/download/${{ needs.prepare-release.outputs.tag }}/git-sc-aarch64-apple-darwin.tar.gz | tar xz
sudo mv git-sc /usr/local/bin/
```
#### macOS (Intel)
```bash
curl -L https://github.com/${{ github.repository }}/releases/download/${{ needs.prepare-release.outputs.tag }}/git-sc-x86_64-apple-darwin.tar.gz | tar xz
sudo mv git-sc /usr/local/bin/
```
#### Linux (x86_64)
```bash
curl -L https://github.com/${{ github.repository }}/releases/download/${{ needs.prepare-release.outputs.tag }}/git-sc-x86_64-unknown-linux-gnu.tar.gz | tar xz
sudo mv git-sc /usr/local/bin/
```
#### Linux (ARM64)
```bash
curl -L https://github.com/${{ github.repository }}/releases/download/${{ needs.prepare-release.outputs.tag }}/git-sc-aarch64-unknown-linux-gnu.tar.gz | tar xz
sudo mv git-sc /usr/local/bin/
```
#### Windows (manual)
Download `git-sc-x86_64-pc-windows-msvc.zip`, extract, and add to PATH.
files: release/*
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update-homebrew:
name: Update Homebrew Tap
needs: [prepare-release, release]
if: ${{ !inputs.dry_run }}
runs-on: ubuntu-latest
steps:
- name: Generate GitHub App Token
id: app-token
uses: actions/create-github-app-token@v3
with:
client-id: ${{ vars.APP_CLIENT_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: homebrew-git-sc
permission-contents: write
- name: Create Homebrew bottles and calculate SHA256
id: bottles
run: |
VERSION="${{ needs.prepare-release.outputs.version }}"
TAG="${{ needs.prepare-release.outputs.tag }}"
# Download source archive for formula URL
curl -sL "https://github.com/${{ github.repository }}/archive/refs/tags/${TAG}.tar.gz" -o source.tar.gz
SHA256_SOURCE=$(sha256sum source.tar.gz | cut -d' ' -f1)
echo "sha256_source=${SHA256_SOURCE}" >> $GITHUB_OUTPUT
# Download release binaries
curl -sL "https://github.com/${{ github.repository }}/releases/download/${TAG}/git-sc-aarch64-apple-darwin.tar.gz" -o mac_arm64.tar.gz
curl -sL "https://github.com/${{ github.repository }}/releases/download/${TAG}/git-sc-x86_64-apple-darwin.tar.gz" -o mac_x86_64.tar.gz
curl -sL "https://github.com/${{ github.repository }}/releases/download/${TAG}/git-sc-x86_64-unknown-linux-gnu.tar.gz" -o linux_x86_64.tar.gz
# Create Homebrew bottle tarball from release binary
create_bottle() {
local src_tarball=$1
local bottle_tag=$2
rm -rf bottle_staging
mkdir -p "bottle_staging/git-sc/${VERSION}/bin"
# Extract binary from release tarball into bottle structure
tar xzf "${src_tarball}" -C "bottle_staging/git-sc/${VERSION}/bin/"
chmod +x "bottle_staging/git-sc/${VERSION}/bin/git-sc"
# Create bottle tarball
local bottle_name="git-sc-${VERSION}.${bottle_tag}.bottle.tar.gz"
tar czf "${bottle_name}" -C bottle_staging git-sc
# Return SHA256
sha256sum "${bottle_name}" | cut -d' ' -f1
}
SHA256_BOTTLE_ARM64_SONOMA=$(create_bottle mac_arm64.tar.gz arm64_sonoma)
SHA256_BOTTLE_SONOMA=$(create_bottle mac_x86_64.tar.gz sonoma)
SHA256_BOTTLE_X86_64_LINUX=$(create_bottle linux_x86_64.tar.gz x86_64_linux)
echo "sha256_bottle_arm64_sonoma=${SHA256_BOTTLE_ARM64_SONOMA}" >> $GITHUB_OUTPUT
echo "sha256_bottle_sonoma=${SHA256_BOTTLE_SONOMA}" >> $GITHUB_OUTPUT
echo "sha256_bottle_x86_64_linux=${SHA256_BOTTLE_X86_64_LINUX}" >> $GITHUB_OUTPUT
- name: Upload bottles to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ needs.prepare-release.outputs.version }}"
TAG="${{ needs.prepare-release.outputs.tag }}"
gh release upload "${TAG}" \
"git-sc-${VERSION}.arm64_sonoma.bottle.tar.gz" \
"git-sc-${VERSION}.sonoma.bottle.tar.gz" \
"git-sc-${VERSION}.x86_64_linux.bottle.tar.gz" \
--clobber \
--repo "${{ github.repository }}"
- name: Update Homebrew Formula
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
VERSION="${{ needs.prepare-release.outputs.version }}"
TAG="${{ needs.prepare-release.outputs.tag }}"
SHA256_SOURCE="${{ steps.bottles.outputs.sha256_source }}"
SHA256_BOTTLE_ARM64_SONOMA="${{ steps.bottles.outputs.sha256_bottle_arm64_sonoma }}"
SHA256_BOTTLE_SONOMA="${{ steps.bottles.outputs.sha256_bottle_sonoma }}"
SHA256_BOTTLE_X86_64_LINUX="${{ steps.bottles.outputs.sha256_bottle_x86_64_linux }}"
# Clone homebrew tap
git clone "https://x-access-token:${GH_TOKEN}@github.com/owayo/homebrew-git-sc.git"
cd homebrew-git-sc
# Create Formula directory if not exists
mkdir -p Formula
# Create/update formula with bottle support
cat > Formula/git-sc.rb << 'FORMULA'
class GitSc < Formula
desc "AI-powered smart commit message generator for coding agents"
homepage "https://github.com/owayo/git-smart-commit"
url "URL_SOURCE_PLACEHOLDER"
sha256 "SHA256_SOURCE_PLACEHOLDER"
license "MIT"
bottle do
root_url "ROOT_URL_PLACEHOLDER"
sha256 cellar: :any_skip_relocation, arm64_sonoma: "SHA256_BOTTLE_ARM64_SONOMA_PLACEHOLDER"
sha256 cellar: :any_skip_relocation, sonoma: "SHA256_BOTTLE_SONOMA_PLACEHOLDER"
sha256 cellar: :any_skip_relocation, x86_64_linux: "SHA256_BOTTLE_X86_64_LINUX_PLACEHOLDER"
end
depends_on "rust" => :build
def install
system "cargo", "install", *std_cargo_args
end
test do
system "#{bin}/git-sc", "--version"
end
end
FORMULA
# Remove leading spaces from heredoc
sed -i 's/^ //' Formula/git-sc.rb
# Replace placeholders with actual values
sed -i "s|URL_SOURCE_PLACEHOLDER|https://github.com/owayo/git-smart-commit/archive/refs/tags/${TAG}.tar.gz|g" Formula/git-sc.rb
sed -i "s|SHA256_SOURCE_PLACEHOLDER|${SHA256_SOURCE}|g" Formula/git-sc.rb
sed -i "s|ROOT_URL_PLACEHOLDER|https://github.com/owayo/git-smart-commit/releases/download/${TAG}|g" Formula/git-sc.rb
sed -i "s|SHA256_BOTTLE_ARM64_SONOMA_PLACEHOLDER|${SHA256_BOTTLE_ARM64_SONOMA}|g" Formula/git-sc.rb
sed -i "s|SHA256_BOTTLE_SONOMA_PLACEHOLDER|${SHA256_BOTTLE_SONOMA}|g" Formula/git-sc.rb
sed -i "s|SHA256_BOTTLE_X86_64_LINUX_PLACEHOLDER|${SHA256_BOTTLE_X86_64_LINUX}|g" Formula/git-sc.rb
# Commit and push
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/git-sc.rb
git commit -m "Update git-sc to ${TAG}"
git push
publish-winget:
name: Publish to WinGet
needs: [prepare-release, release]
if: ${{ !inputs.dry_run }}
# Komac is cross-platform; windows-latest is not needed
runs-on: ubuntu-latest
outputs:
submitted: ${{ steps.submit.outcome == 'success' }}
env:
WINGET_IDENTIFIER: owayo.git-sc
steps:
# `secrets` is not available in a job-level `if`, so gate inside a step
# to keep a missing token from failing the whole release
- name: Check WinGet token
id: token
env:
WINGET_TOKEN: ${{ secrets.WINGET_TOKEN }}
run: |
if [ -z "${WINGET_TOKEN}" ]; then
echo "::warning::WINGET_TOKEN is not set; skipping winget-pkgs submission"
echo "available=false" >> "$GITHUB_OUTPUT"
else
echo "available=true" >> "$GITHUB_OUTPUT"
fi
# A brand-new package needs a moderator to approve its first winget-pkgs PR,
# which can sit for days. winget-releaser exits 1 in that window
# ("Package ... does not exist in the winget-pkgs repository"), so check the
# registration first and skip: "not merged yet" is the normal state while
# waiting, not a release failure. continue-on-error is deliberately avoided
# because it would also hide a revoked PAT or a wrong installers-regex.
- name: Check winget-pkgs registration
id: registration
if: steps.token.outputs.available == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Same path winget-releaser checks: manifests/<initial>/<Publisher>/<Package>
INITIAL=$(printf '%s' "${WINGET_IDENTIFIER}" | cut -c1 | tr '[:upper:]' '[:lower:]')
MANIFEST_DIR="manifests/${INITIAL}/${WINGET_IDENTIFIER//.//}"
# `bash -e` would abort the step on a connection failure, so swallow it
# and judge by the HTTP status alone
http_status() {
curl --silent --output /dev/null --write-out '%{http_code}' "$@" || true
}
STATUS=$(http_status \
--header "Authorization: Bearer ${GH_TOKEN}" \
--header "Accept: application/vnd.github+json" \
"https://api.github.com/repos/microsoft/winget-pkgs/contents/${MANIFEST_DIR}")
# Re-check over the plain web path when the API is unusable (rate limit etc.)
if [ "${STATUS}" != "200" ] && [ "${STATUS}" != "404" ]; then
STATUS=$(http_status "https://github.com/microsoft/winget-pkgs/tree/master/${MANIFEST_DIR}")
fi
case "${STATUS}" in
200)
echo "registered=true" >> "$GITHUB_OUTPUT"
;;
404)
echo "::notice::${WINGET_IDENTIFIER} is not in winget-pkgs yet (initial PR awaiting moderator approval); skipping submission"
echo "registered=false" >> "$GITHUB_OUTPUT"
;;
*)
# Undetermined: submit anyway, so a permanently failing lookup cannot
# silently stop updates forever
echo "::warning::Could not determine winget-pkgs registration (HTTP ${STATUS}); attempting submission"
echo "registered=true" >> "$GITHUB_OUTPUT"
;;
esac
- name: Submit manifest to winget-pkgs
id: submit
if: steps.registration.outputs.registered == 'true'
uses: vedantmgoyal9/winget-releaser@v2
with:
identifier: ${{ env.WINGET_IDENTIFIER }}
version: ${{ needs.prepare-release.outputs.version }}
# workflow_dispatch has no release event, so the tag must be passed explicitly
release-tag: ${{ needs.prepare-release.outputs.tag }}
# The default regex matches only exe/msi/msix/appx and would select zero assets
installers-regex: '-pc-windows-msvc\.zip$'
max-versions-to-keep: 5
token: ${{ secrets.WINGET_TOKEN }}
release-summary:
name: Release Summary
needs: [prepare-release, release, update-homebrew, publish-winget]
if: ${{ !inputs.dry_run }}
runs-on: ubuntu-latest
steps:
- name: Summary
run: |
echo "🚀 Released ${{ needs.prepare-release.outputs.tag }}"
echo ""
echo "Assets uploaded:"
echo " - git-sc-x86_64-unknown-linux-gnu.tar.gz"
echo " - git-sc-aarch64-unknown-linux-gnu.tar.gz"
echo " - git-sc-x86_64-apple-darwin.tar.gz"
echo " - git-sc-aarch64-apple-darwin.tar.gz"
echo " - git-sc-x86_64-pc-windows-msvc.zip"
echo ""
echo "🍺 Homebrew tap updated: owayo/homebrew-git-sc"
if [ "${{ needs.publish-winget.outputs.submitted }}" = "true" ]; then
echo "📦 WinGet manifest submitted: owayo.git-sc"
else
echo "📦 WinGet submission skipped (owayo.git-sc not in winget-pkgs yet, or WINGET_TOKEN unset)"
fi