Skip to content

Commit be7e6ae

Browse files
committed
fix(ci): align smol cache keys with build-smol.yml in publish-socketbin.yml
Ensure publish-socketbin.yml uses the same cache key generation as build-smol.yml for smol binary builds to enable efficient cache reuse. Changes: - Add smol-deps cache restoration matching build-smol.yml pattern - Generate smol cache key combining patches hash with deps hash - Only build bootstrap/socket packages if smol deps cache miss - Only build smol binary if smol binary cache miss - Use cross-platform compatible hash commands This completes cache alignment for both SEA and smol build methods.
1 parent 38c6fba commit be7e6ae

File tree

1 file changed

+46
-22
lines changed

1 file changed

+46
-22
lines changed

.github/workflows/publish-socketbin.yml

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -97,41 +97,65 @@ jobs:
9797
key: build-${{ matrix.platform }}-${{ matrix.arch }}
9898
max-size: 2G
9999

100-
- name: Generate build cache key
101-
id: build-cache-key
100+
- name: Generate build-deps cache key for smol
101+
if: inputs.method == 'smol' || inputs.method == 'smol-sea'
102+
id: smol-deps-cache-key
102103
shell: bash
103104
run: |
104-
# Generate hash from build-affecting files (matches build-binaries.yml).
105+
# Generate hash from bootstrap/socket packages (matches build-smol.yml).
105106
if [ "${{ matrix.os }}" = "windows" ]; then
106-
HASH=$(find patches packages/node-smol-builder/patches packages/node-smol-builder/additions scripts -type f -name "*.patch" -o -name "*.mjs" -o -name "*.h" -o -name "*.c" -o -name "*.cc" | sort | xargs sha256sum | sha256sum | cut -d' ' -f1)
107+
HASH=$(find packages/bootstrap packages/socket -type f \( -name "*.mts" -o -name "*.ts" -o -name "*.mjs" -o -name "*.js" -o -name "*.json" \) ! -path "*/node_modules/*" ! -path "*/dist/*" ! -path "*/build/*" | sort | xargs sha256sum | sha256sum | cut -d' ' -f1)
107108
else
108-
HASH=$(find patches packages/node-smol-builder/patches packages/node-smol-builder/additions scripts -type f \( -name "*.patch" -o -name "*.mjs" -o -name "*.h" -o -name "*.c" -o -name "*.cc" \) | sort | xargs shasum -a 256 | shasum -a 256 | cut -d' ' -f1)
109+
HASH=$(find packages/bootstrap packages/socket -type f \( -name "*.mts" -o -name "*.ts" -o -name "*.mjs" -o -name "*.js" -o -name "*.json" \) ! -path "*/node_modules/*" ! -path "*/dist/*" ! -path "*/build/*" | sort | xargs shasum -a 256 | shasum -a 256 | cut -d' ' -f1)
109110
fi
110-
echo "hash=$HASH" >> $GITHUB_OUTPUT
111-
echo "Build hash: $HASH"
111+
echo "deps-hash=$HASH" >> $GITHUB_OUTPUT
112112
113-
- name: Restore smol binary from build-socketbin.yml cache
113+
- name: Restore build-deps cache for smol
114+
if: inputs.method == 'smol' || inputs.method == 'smol-sea'
115+
id: smol-deps-cache
114116
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
117+
with:
118+
path: |
119+
packages/bootstrap/dist/
120+
packages/socket/dist/
121+
key: build-deps-smol-${{ steps.smol-deps-cache-key.outputs.deps-hash }}
122+
restore-keys: build-deps-smol-
123+
124+
- name: Build bootstrap package for smol
125+
if: (inputs.method == 'smol' || inputs.method == 'smol-sea') && steps.smol-deps-cache.outputs.cache-hit != 'true'
126+
run: pnpm --filter @socketsecurity/bootstrap run build
127+
128+
- name: Build socket package bootstrap for smol
129+
if: (inputs.method == 'smol' || inputs.method == 'smol-sea') && steps.smol-deps-cache.outputs.cache-hit != 'true'
130+
run: pnpm --filter socket run build
131+
132+
- name: Generate smol build cache key
133+
if: inputs.method == 'smol' || inputs.method == 'smol-sea'
134+
id: smol-cache-key
135+
shell: bash
136+
run: |
137+
# Generate hash from patches and build scripts (matches build-smol.yml).
138+
if [ "${{ matrix.os }}" = "windows" ]; then
139+
PATCHES_HASH=$(find patches packages/node-smol-builder/patches packages/node-smol-builder/additions scripts -type f \( -name "*.patch" -o -name "*.mjs" -o -name "*.h" -o -name "*.c" -o -name "*.cc" \) | sort | xargs sha256sum | sha256sum | cut -d' ' -f1)
140+
COMBINED_HASH=$(echo "$PATCHES_HASH-${{ steps.smol-deps-cache-key.outputs.deps-hash }}" | sha256sum | cut -d' ' -f1)
141+
else
142+
PATCHES_HASH=$(find patches packages/node-smol-builder/patches packages/node-smol-builder/additions scripts -type f \( -name "*.patch" -o -name "*.mjs" -o -name "*.h" -o -name "*.c" -o -name "*.cc" \) | sort | xargs shasum -a 256 | shasum -a 256 | cut -d' ' -f1)
143+
COMBINED_HASH=$(echo "$PATCHES_HASH-${{ steps.smol-deps-cache-key.outputs.deps-hash }}" | shasum -a 256 | cut -d' ' -f1)
144+
fi
145+
echo "hash=$COMBINED_HASH" >> $GITHUB_OUTPUT
146+
147+
- name: Restore smol binary cache
148+
if: inputs.method == 'smol' || inputs.method == 'smol-sea'
115149
id: smol-cache
150+
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
116151
with:
117152
path: packages/node-smol-builder/dist/socket-smol-${{ matrix.platform }}-${{ matrix.arch }}${{ matrix.os == 'windows' && '.exe' || '' }}
118-
key: node-smol-${{ matrix.platform }}-${{ matrix.arch }}-${{ steps.build-cache-key.outputs.hash }}
153+
key: node-smol-${{ matrix.platform }}-${{ matrix.arch }}-${{ steps.smol-cache-key.outputs.hash }}
119154
restore-keys: node-smol-${{ matrix.platform }}-${{ matrix.arch }}-
120155

121-
- name: Cache compiled Node.js binary
122-
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
123-
id: binary-cache
124-
with:
125-
path: |
126-
packages/node-smol-builder/build/out/Release/node
127-
packages/node-smol-builder/build/out/Release/node.exe
128-
key: node-binary-${{ matrix.platform }}-${{ matrix.arch }}-${{ steps.build-cache-key.outputs.hash }}
129-
restore-keys: |
130-
node-binary-${{ matrix.platform }}-${{ matrix.arch }}-
131-
132156
- name: Build smol Node.js binary
133157
id: build-smol
134-
if: inputs.method == 'smol' || inputs.method == 'smol-sea'
158+
if: (inputs.method == 'smol' || inputs.method == 'smol-sea') && steps.smol-cache.outputs.cache-hit != 'true'
135159
continue-on-error: true
136160
shell: bash
137161
run: |
@@ -141,7 +165,7 @@ jobs:
141165
--arch=${{ matrix.arch }}
142166
143167
- name: Build smol binary (fallback with clean rebuild)
144-
if: (inputs.method == 'smol' || inputs.method == 'smol-sea') && steps.build-smol.outcome == 'failure'
168+
if: (inputs.method == 'smol' || inputs.method == 'smol-sea') && steps.smol-cache.outputs.cache-hit != 'true' && steps.build-smol.outcome == 'failure'
145169
shell: bash
146170
run: |
147171
echo "Initial smol build failed, attempting clean rebuild..."

0 commit comments

Comments
 (0)