Skip to content

Commit ea1c385

Browse files
committed
feat(ci): automate binary builds on release and add install script
Binary builds now run as part of the release workflow instead of relying on release events (which don't propagate from GITHUB_TOKEN). Added curl-pipe install script for one-line installation.
1 parent 11a36ba commit ea1c385

3 files changed

Lines changed: 121 additions & 8 deletions

File tree

.github/workflows/publish.yml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
paths:
99
- '.changeset/**'
1010
- 'packages/*/package.json'
11-
- '.github/workflows/release.yml'
11+
- '.github/workflows/publish.yml'
1212

1313
concurrency: ${{ github.workflow }}-${{ github.ref }}
1414

@@ -21,6 +21,9 @@ jobs:
2121
release:
2222
name: Release
2323
runs-on: ubuntu-latest
24+
outputs:
25+
published: ${{ steps.changesets.outputs.published }}
26+
publishedPackages: ${{ steps.changesets.outputs.publishedPackages }}
2427
steps:
2528
- name: Checkout
2629
uses: actions/checkout@v4
@@ -48,3 +51,35 @@ jobs:
4851
publish: bun run release
4952
env:
5053
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
55+
build-binaries:
56+
name: Build and upload binaries
57+
needs: release
58+
if: >-
59+
needs.release.outputs.published == 'true' &&
60+
contains(needs.release.outputs.publishedPackages, '@noormdev/cli')
61+
runs-on: ubuntu-latest
62+
steps:
63+
- name: Checkout
64+
uses: actions/checkout@v4
65+
66+
- name: Setup Bun
67+
uses: oven-sh/setup-bun@v2
68+
69+
- name: Install dependencies
70+
run: bun install --frozen-lockfile
71+
72+
- name: Get CLI version
73+
id: version
74+
run: echo "tag=@noormdev/cli@$(jq -r .version packages/cli/package.json)" >> "$GITHUB_OUTPUT"
75+
76+
- name: Build binaries
77+
run: bun run build:binary
78+
79+
- name: Upload binaries to release
80+
uses: softprops/action-gh-release@v2
81+
with:
82+
tag_name: ${{ steps.version.outputs.tag }}
83+
files: packages/cli/bin/noorm-*
84+
env:
85+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
name: Release Binaries
1+
name: Release Binaries (Manual)
22

33
on:
4-
release:
5-
types: [published]
64
workflow_dispatch:
75

86
permissions:
@@ -12,10 +10,6 @@ jobs:
1210
build-binaries:
1311
name: Build and upload binaries
1412
runs-on: ubuntu-latest
15-
# Only run for CLI releases, skip SDK-only releases
16-
if: >-
17-
github.event_name == 'workflow_dispatch' ||
18-
contains(github.event.release.tag_name, '@noormdev/cli@')
1913
steps:
2014
- name: Checkout
2115
uses: actions/checkout@v4
@@ -26,12 +20,17 @@ jobs:
2620
- name: Install dependencies
2721
run: bun install --frozen-lockfile
2822

23+
- name: Get CLI version
24+
id: version
25+
run: echo "tag=@noormdev/cli@$(jq -r .version packages/cli/package.json)" >> "$GITHUB_OUTPUT"
26+
2927
- name: Build binaries
3028
run: bun run build:binary
3129

3230
- name: Upload binaries to release
3331
uses: softprops/action-gh-release@v2
3432
with:
33+
tag_name: ${{ steps.version.outputs.tag }}
3534
files: packages/cli/bin/noorm-*
3635
env:
3736
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

install.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# noorm installer
5+
# Usage: curl -fsSL https://raw.githubusercontent.com/noormdev/noorm/master/install.sh | sh
6+
7+
REPO="noormdev/noorm"
8+
INSTALL_DIR="${NOORM_INSTALL_DIR:-/usr/local/bin}"
9+
BINARY_NAME="noorm"
10+
11+
main() {
12+
os=$(detect_os)
13+
arch=$(detect_arch)
14+
suffix="${os}-${arch}"
15+
16+
if [ "$os" = "windows" ]; then
17+
suffix="${suffix}.exe"
18+
BINARY_NAME="noorm.exe"
19+
fi
20+
21+
tag=$(latest_cli_tag)
22+
version=$(echo "$tag" | sed 's/@noormdev\/cli@//')
23+
24+
echo "Installing noorm v${version} (${os}-${arch})..."
25+
26+
url="https://github.com/${REPO}/releases/download/${tag}/noorm-${suffix}"
27+
tmpfile=$(mktemp)
28+
29+
if ! curl -fsSL -o "$tmpfile" "$url"; then
30+
echo "Error: Failed to download binary from ${url}" >&2
31+
echo "No binary available for ${os}-${arch}." >&2
32+
rm -f "$tmpfile"
33+
exit 1
34+
fi
35+
36+
chmod +x "$tmpfile"
37+
38+
if [ -w "$INSTALL_DIR" ]; then
39+
mv "$tmpfile" "${INSTALL_DIR}/${BINARY_NAME}"
40+
else
41+
echo "Installing to ${INSTALL_DIR} (requires sudo)..."
42+
sudo mv "$tmpfile" "${INSTALL_DIR}/${BINARY_NAME}"
43+
fi
44+
45+
echo "Installed noorm v${version} to ${INSTALL_DIR}/${BINARY_NAME}"
46+
}
47+
48+
detect_os() {
49+
case "$(uname -s)" in
50+
Darwin) echo "darwin" ;;
51+
Linux) echo "linux" ;;
52+
MINGW*|MSYS*|CYGWIN*) echo "windows" ;;
53+
*) echo "Unsupported OS: $(uname -s)" >&2; exit 1 ;;
54+
esac
55+
}
56+
57+
detect_arch() {
58+
case "$(uname -m)" in
59+
x86_64|amd64) echo "x64" ;;
60+
arm64|aarch64) echo "arm64" ;;
61+
*) echo "Unsupported architecture: $(uname -m)" >&2; exit 1 ;;
62+
esac
63+
}
64+
65+
latest_cli_tag() {
66+
tag=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases" \
67+
| grep -o '"tag_name": *"@noormdev/cli@[^"]*"' \
68+
| head -1 \
69+
| sed 's/"tag_name": *"//;s/"//')
70+
71+
if [ -z "$tag" ]; then
72+
echo "Error: Could not find a CLI release." >&2
73+
exit 1
74+
fi
75+
76+
echo "$tag"
77+
}
78+
79+
main

0 commit comments

Comments
 (0)