Skip to content

Commit 6798515

Browse files
committed
ci: split native package build actions
Move the native package build flow out of duplicated CI and release workflow steps into platform-specific composite actions for Linux, macOS, and Windows. Keep Blacksmith StickyDisk setup isolated to the Linux setup action, keep macOS on the original Nix cache action, and keep Windows Cargo cache setup separate so each platform path is easier to audit.
1 parent b4e625e commit 6798515

9 files changed

Lines changed: 258 additions & 159 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Build Linux native package
2+
description: Build, stage, archive, and upload a Linux ccusage native package
3+
inputs:
4+
arch:
5+
description: Native package architecture
6+
required: true
7+
binary:
8+
description: Path to the built ccusage binary
9+
required: true
10+
nix-github-token:
11+
description: Whether Nix builds may use the GitHub token from Nix config
12+
default: 'true'
13+
runs:
14+
using: composite
15+
steps:
16+
- uses: ./.github/actions/setup-nix
17+
18+
- name: Build Linux static binary
19+
shell: bash
20+
run: |
21+
if [ "${{ inputs.nix-github-token }}" = "false" ]; then
22+
NIX_CONFIG="access-tokens =" nix build .#ccusage-static
23+
else
24+
nix build .#ccusage-static
25+
fi
26+
27+
- name: Verify Linux binary is static
28+
shell: bash
29+
run: |
30+
file "${{ inputs.binary }}"
31+
if ldd "${{ inputs.binary }}" > "$RUNNER_TEMP/ldd.txt" 2>&1; then
32+
cat "$RUNNER_TEMP/ldd.txt"
33+
grep -Eiq 'not a dynamic executable|statically linked' "$RUNNER_TEMP/ldd.txt"
34+
else
35+
cat "$RUNNER_TEMP/ldd.txt"
36+
grep -Eiq 'not a dynamic executable|statically linked' "$RUNNER_TEMP/ldd.txt"
37+
fi
38+
39+
- name: Stage native package
40+
shell: bash
41+
run: node apps/ccusage/scripts/stage-native-package.mjs --platform linux --arch "${{ inputs.arch }}" --binary "${{ inputs.binary }}"
42+
43+
- name: Archive native package binary
44+
shell: bash
45+
run: tar -cf "ccusage-native-linux-${{ inputs.arch }}.tar" "packages/ccusage-linux-${{ inputs.arch }}/bin"
46+
47+
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
48+
with:
49+
name: ccusage-native-linux-${{ inputs.arch }}
50+
path: ccusage-native-linux-${{ inputs.arch }}.tar
51+
if-no-files-found: error
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Build macOS native package
2+
description: Build, stage, archive, and upload a macOS ccusage native package
3+
inputs:
4+
arch:
5+
description: Native package architecture
6+
required: true
7+
binary:
8+
description: Path to the built ccusage binary
9+
required: true
10+
runs:
11+
using: composite
12+
steps:
13+
- uses: ./.github/actions/setup-nix
14+
15+
- name: Build macOS binary
16+
shell: bash
17+
run: nix build .#ccusage
18+
19+
- name: Stage native package
20+
shell: bash
21+
run: node apps/ccusage/scripts/stage-native-package.mjs --platform darwin --arch "${{ inputs.arch }}" --binary "${{ inputs.binary }}"
22+
23+
- name: Archive native package binary
24+
shell: bash
25+
run: tar -cf "ccusage-native-darwin-${{ inputs.arch }}.tar" "packages/ccusage-darwin-${{ inputs.arch }}/bin"
26+
27+
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
28+
with:
29+
name: ccusage-native-darwin-${{ inputs.arch }}
30+
path: ccusage-native-darwin-${{ inputs.arch }}.tar
31+
if-no-files-found: error
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Build Windows native package
2+
description: Build, stage, archive, and upload a Windows ccusage native package
3+
inputs:
4+
arch:
5+
description: Native package architecture
6+
required: true
7+
binary:
8+
description: Path to the built ccusage binary
9+
required: true
10+
runs:
11+
using: composite
12+
steps:
13+
- uses: ./.github/actions/setup-native-build-cache
14+
with:
15+
platform: win32
16+
17+
- name: Build Cargo native binary
18+
shell: bash
19+
run: cargo build --manifest-path rust/Cargo.toml --release --bin ccusage
20+
21+
- name: Stage native package
22+
shell: bash
23+
run: node apps/ccusage/scripts/stage-native-package.mjs --platform win32 --arch "${{ inputs.arch }}" --binary "${{ inputs.binary }}"
24+
25+
- name: Archive native package binary
26+
shell: bash
27+
run: tar -cf "ccusage-native-win32-${{ inputs.arch }}.tar" "packages/ccusage-win32-${{ inputs.arch }}/bin"
28+
29+
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
30+
with:
31+
name: ccusage-native-win32-${{ inputs.arch }}
32+
path: ccusage-native-win32-${{ inputs.arch }}.tar
33+
if-no-files-found: error
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Setup Linux Blacksmith sticky disk
2+
description: Mount Blacksmith sticky disks for Linux Nix and root node_modules caches
3+
runs:
4+
using: composite
5+
steps:
6+
- name: Detect Blacksmith sticky disk support
7+
id: blacksmith
8+
shell: bash
9+
run: |
10+
if [ -n "${BLACKSMITH_STICKYDISK_TOKEN:-}" ]; then
11+
echo "enabled=true" >> "$GITHUB_OUTPUT"
12+
else
13+
echo "enabled=false" >> "$GITHUB_OUTPUT"
14+
fi
15+
16+
- name: Resolve pnpm version
17+
id: pnpm
18+
if: steps.blacksmith.outputs.enabled == 'true'
19+
shell: bash
20+
run: |
21+
package_manager="$(node -p "require('./package.json').packageManager ?? ''")"
22+
case "$package_manager" in
23+
pnpm@*) echo "version=${package_manager#pnpm@}" >> "$GITHUB_OUTPUT" ;;
24+
*) echo "version=unknown" >> "$GITHUB_OUTPUT" ;;
25+
esac
26+
27+
- name: Prepare Nix store mount point
28+
if: steps.blacksmith.outputs.enabled == 'true'
29+
shell: bash
30+
run: |
31+
sudo mkdir -p /nix/store
32+
sudo chmod 755 /nix
33+
34+
- name: Mount Nix store sticky disk
35+
if: steps.blacksmith.outputs.enabled == 'true'
36+
uses: useblacksmith/stickydisk@d58829ad6f9be8822ec5efe74256c82cd62915ab # v1
37+
with:
38+
key: ${{ github.repository }}-nix-${{ runner.os }}-${{ runner.arch }}
39+
path: /nix
40+
41+
- name: Prepare mounted Nix store ownership
42+
if: steps.blacksmith.outputs.enabled == 'true'
43+
shell: bash
44+
run: |
45+
sudo mkdir -p /nix/store
46+
sudo chown "$USER:$(id -gn)" /nix /nix/store
47+
for path in /nix/var/log/nix /nix/var/nix; do
48+
if [ -e "$path" ]; then
49+
sudo chown -R "$USER:$(id -gn)" "$path"
50+
fi
51+
done
52+
53+
- name: Mount root node_modules sticky disk
54+
if: steps.blacksmith.outputs.enabled == 'true'
55+
uses: useblacksmith/stickydisk@d58829ad6f9be8822ec5efe74256c82cd62915ab # v1
56+
with:
57+
key: ${{ github.repository }}-node-modules-pnpm-${{ steps.pnpm.outputs.version }}-${{ runner.os }}-${{ runner.arch }}
58+
path: ./node_modules
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Setup macOS Nix cache
2+
description: Restore and save the macOS Nix store with the original Nix cache action
3+
runs:
4+
using: composite
5+
steps:
6+
- name: Cache macOS Nix store
7+
uses: nix-community/cache-nix-action@7df957e333c1e5da7721f60227dbba6d06080569 # v7.0.2
8+
with:
9+
primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('flake.lock', 'flake.nix', 'dev/flake.lock', 'dev/flake.nix', 'default.nix', 'package.nix', 'package.json', 'nix/**/*.nix', 'rust-toolchain.toml', 'rust/Cargo.lock', 'rust/**/Cargo.toml') }}
10+
restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }}-
11+
gc-max-store-size-macos: 3500000000
12+
purge: true
13+
purge-prefixes: nix-${{ runner.os }}-${{ runner.arch }}-
14+
purge-created: 172800
15+
purge-primary-key: never
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Setup native build cache
2+
description: Restore native package build caches for the current platform
3+
inputs:
4+
platform:
5+
description: Native package platform
6+
required: true
7+
runs:
8+
using: composite
9+
steps:
10+
- name: Cache Cargo build
11+
if: inputs.platform == 'win32'
12+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
13+
with:
14+
path: |
15+
~/.cargo/registry
16+
~/.cargo/git
17+
rust/target
18+
key: cargo-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('rust/Cargo.lock', 'rust-toolchain.toml') }}-${{ github.run_id }}-${{ github.run_attempt }}
19+
restore-keys: |
20+
cargo-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('rust/Cargo.lock', 'rust-toolchain.toml') }}-
21+
cargo-${{ runner.os }}-${{ runner.arch }}-

‎.github/actions/setup-nix/action.yaml‎

Lines changed: 4 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,14 @@
11
name: Setup Nix
2-
description: Install Nix and optionally mount a Blacksmith sticky disk for the Nix store
2+
description: Install Nix with platform-specific cache setup
33
inputs:
44
warm-dev-shell:
55
description: Whether to instantiate the CI dev shell during setup
66
default: 'false'
77
runs:
88
using: composite
99
steps:
10-
- name: Detect Blacksmith sticky disk support
11-
id: blacksmith
12-
shell: bash
13-
run: |
14-
if [ -n "${BLACKSMITH_STICKYDISK_TOKEN:-}" ]; then
15-
echo "enabled=true" >> "$GITHUB_OUTPUT"
16-
else
17-
echo "enabled=false" >> "$GITHUB_OUTPUT"
18-
fi
19-
20-
- name: Resolve pnpm version
21-
id: pnpm
22-
if: steps.blacksmith.outputs.enabled == 'true'
23-
shell: bash
24-
run: |
25-
package_manager="$(node -p "require('./package.json').packageManager ?? ''")"
26-
case "$package_manager" in
27-
pnpm@*) echo "version=${package_manager#pnpm@}" >> "$GITHUB_OUTPUT" ;;
28-
*) echo "version=unknown" >> "$GITHUB_OUTPUT" ;;
29-
esac
30-
31-
- name: Prepare Nix store mount point
32-
if: runner.os == 'Linux' && steps.blacksmith.outputs.enabled == 'true'
33-
shell: bash
34-
run: |
35-
sudo mkdir -p /nix/store
36-
sudo chmod 755 /nix
37-
38-
- name: Mount Nix store sticky disk
39-
if: runner.os == 'Linux' && steps.blacksmith.outputs.enabled == 'true'
40-
uses: useblacksmith/stickydisk@d58829ad6f9be8822ec5efe74256c82cd62915ab # v1
41-
with:
42-
key: ${{ github.repository }}-nix-${{ runner.os }}-${{ runner.arch }}
43-
path: /nix
44-
45-
- name: Prepare mounted Nix store ownership
46-
if: runner.os == 'Linux' && steps.blacksmith.outputs.enabled == 'true'
47-
shell: bash
48-
run: |
49-
sudo mkdir -p /nix/store
50-
sudo chown "$USER:$(id -gn)" /nix /nix/store
51-
for path in /nix/var/log/nix /nix/var/nix; do
52-
if [ -e "$path" ]; then
53-
sudo chown -R "$USER:$(id -gn)" "$path"
54-
fi
55-
done
56-
57-
- name: Mount root node_modules sticky disk
58-
if: runner.os == 'Linux' && steps.blacksmith.outputs.enabled == 'true'
59-
uses: useblacksmith/stickydisk@d58829ad6f9be8822ec5efe74256c82cd62915ab # v1
60-
with:
61-
key: ${{ github.repository }}-node-modules-pnpm-${{ steps.pnpm.outputs.version }}-${{ runner.os }}-${{ runner.arch }}
62-
path: ./node_modules
10+
- uses: ./.github/actions/setup-linux-blacksmith-sticky-disk
11+
if: runner.os == 'Linux'
6312

6413
- name: Install Nix
6514
uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035 # v34
@@ -68,17 +17,8 @@ runs:
6817
nix_conf: |
6918
access-tokens = github.com=${{ github.token }}
7019
71-
- name: Cache macOS Nix store
20+
- uses: ./.github/actions/setup-macos-nix-cache
7221
if: runner.os == 'macOS'
73-
uses: nix-community/cache-nix-action@7df957e333c1e5da7721f60227dbba6d06080569 # v7.0.2
74-
with:
75-
primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('flake.lock', 'flake.nix', 'dev/flake.lock', 'dev/flake.nix', 'default.nix', 'package.nix', 'package.json', 'nix/**/*.nix', 'rust-toolchain.toml', 'rust/Cargo.lock', 'rust/**/Cargo.toml') }}
76-
restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }}-
77-
gc-max-store-size-macos: 3500000000
78-
purge: true
79-
purge-prefixes: nix-${{ runner.os }}-${{ runner.arch }}-
80-
purge-created: 172800
81-
purge-primary-key: never
8222

8323
- name: Fix single-user Nix store ownership
8424
if: runner.os != 'Windows'

0 commit comments

Comments
 (0)