Skip to content

Commit e9d83f5

Browse files
committed
fix(ci): harden error handling across CI/CD workflows
- Align FFmpeg version to n8.0 across workflow and Dockerfiles - Add post-loop check for FFmpeg git clone retry - Add CI completion verification before release artifact download - Add tarball integrity validation before extraction - Add set -e to shell scripts for fail-fast behavior - Fix error suppression patterns that hide failures - Add version extraction validation - Define PLATFORMS env variable to avoid hardcoded lists
1 parent 441be0d commit e9d83f5

3 files changed

Lines changed: 63 additions & 9 deletions

File tree

.github/workflows/build-ffmpeg.yml

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ env:
5252
LIBAOM_VERSION: 'v3.12.1'
5353
OPUS_VERSION: '1.5.2'
5454
LAME_VERSION: '3.100'
55-
FFMPEG_VERSION: 'n7.1.3'
55+
FFMPEG_VERSION: 'n8.0'
5656
# npm scope for platform packages
5757
NPM_SCOPE: '@pproenca/ffmpeg'
5858
# Bump this to invalidate all caches
@@ -103,7 +103,13 @@ jobs:
103103
docker cp extract:/build/lib/. artifacts/linux-x64/lib/
104104
docker cp extract:/build/include/. artifacts/linux-x64/include/
105105
106-
docker rm extract
106+
docker rm -f extract 2>/dev/null || true
107+
108+
# Verify extraction succeeded
109+
if [ ! -f artifacts/linux-x64/bin/ffmpeg ]; then
110+
echo "ERROR: ffmpeg binary not extracted from container"
111+
exit 1
112+
fi
107113
108114
# Verify static linking
109115
echo "Verifying static binary..."
@@ -112,7 +118,10 @@ jobs:
112118
113119
# Get version info
114120
chmod +x artifacts/linux-x64/bin/ffmpeg
115-
./artifacts/linux-x64/bin/ffmpeg -version > artifacts/linux-x64/version.txt 2>&1 || true
121+
./artifacts/linux-x64/bin/ffmpeg -version > artifacts/linux-x64/version.txt 2>&1 || {
122+
echo "WARNING: ffmpeg binary failed to execute - binary may be broken"
123+
echo "Continuing anyway as version.txt is informational"
124+
}
116125
117126
# Verify dev files extracted
118127
echo "=== Library files ==="
@@ -178,7 +187,13 @@ jobs:
178187
docker cp extract-glibc:/build/lib/. artifacts/linux-x64-glibc/lib/
179188
docker cp extract-glibc:/build/include/. artifacts/linux-x64-glibc/include/
180189
181-
docker rm extract-glibc
190+
docker rm -f extract-glibc 2>/dev/null || true
191+
192+
# Verify extraction succeeded
193+
if [ ! -f artifacts/linux-x64-glibc/bin/ffmpeg ]; then
194+
echo "ERROR: ffmpeg binary not extracted from container"
195+
exit 1
196+
fi
182197
183198
# Verify glibc linking (should show libc.so.6)
184199
echo "Verifying glibc binary..."
@@ -187,7 +202,10 @@ jobs:
187202
188203
# Get version info
189204
chmod +x artifacts/linux-x64-glibc/bin/ffmpeg
190-
./artifacts/linux-x64-glibc/bin/ffmpeg -version > artifacts/linux-x64-glibc/version.txt 2>&1 || true
205+
./artifacts/linux-x64-glibc/bin/ffmpeg -version > artifacts/linux-x64-glibc/version.txt 2>&1 || {
206+
echo "WARNING: ffmpeg binary failed to execute - binary may be broken"
207+
echo "Continuing anyway as version.txt is informational"
208+
}
191209
192210
# Verify dev files extracted
193211
echo "=== Library files ==="
@@ -275,7 +293,7 @@ jobs:
275293
276294
# Try primary source with retries, fallback to GitHub mirror
277295
NASM_FROM_GITHUB=false
278-
if curl -fSL --retry 3 --retry-delay 5 "$NASM_URL" -o nasm.tar.bz2 2>/dev/null; then
296+
if curl -fSL --retry 3 --retry-delay 5 "$NASM_URL" -o nasm.tar.bz2; then
279297
echo "Downloaded nasm from primary source"
280298
tar xjf nasm.tar.bz2
281299
cd nasm-${NASM_VERSION}
@@ -439,6 +457,11 @@ jobs:
439457
echo "Clone attempt $i failed, retrying in 10s..."
440458
sleep 10
441459
done
460+
# Verify clone succeeded
461+
if [ ! -d ffmpeg ]; then
462+
echo "ERROR: Failed to clone FFmpeg after 3 attempts"
463+
exit 1
464+
fi
442465
fi
443466
444467
cd ffmpeg

.github/workflows/ci.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ jobs:
7474
run: |
7575
# Workaround for known macOS 15 bug where PerfPowerServices consumes 100% CPU
7676
# See: https://github.com/actions/runner-images/issues/13358
77-
sudo defaults -currentHost write /Library/Preferences/com.apple.powerlogd SMCMonitorCadence 0
77+
# Both commands are tolerant - may fail on future macOS versions
78+
sudo defaults -currentHost write /Library/Preferences/com.apple.powerlogd SMCMonitorCadence 0 || echo "Warning: defaults write failed (may not be needed on this macOS version)"
7879
sudo killall PerfPowerServices || true
7980
8081
- name: Install build tools (macOS)
@@ -114,6 +115,7 @@ jobs:
114115

115116
- name: Build with prebuildify
116117
run: |
118+
set -e
117119
npx prebuildify --napi --strip --arch=${{ matrix.arch }}
118120
119121
# prebuildify 6.x with scoped packages creates @scope+name.node
@@ -143,8 +145,14 @@ jobs:
143145

144146
- name: Package as platform npm package
145147
run: |
148+
set -e
146149
# Read version from package.json
147150
VERSION=$(node -p "require('./package.json').version")
151+
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9] ]]; then
152+
echo "ERROR: Failed to extract valid version from package.json: '$VERSION'"
153+
exit 1
154+
fi
155+
echo "Package version: $VERSION"
148156
149157
# Create platform package directory
150158
PKG_DIR="packages/@pproenca/node-webcodecs-${{ matrix.platform }}"

.github/workflows/release.yml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ on:
1212

1313
permissions: {}
1414

15+
env:
16+
# Define platform list once - used in verification and publish loops
17+
PLATFORMS: "darwin-arm64 darwin-x64 linux-x64"
18+
1519
jobs:
1620
# ============================================================================
1721
# Download CI artifacts and publish to npm
@@ -35,6 +39,21 @@ jobs:
3539
node-version: "22"
3640
registry-url: "https://registry.npmjs.org"
3741

42+
# Verify CI workflow completed successfully before downloading artifacts
43+
- name: Verify CI workflow completed
44+
env:
45+
GH_TOKEN: ${{ github.token }}
46+
run: |
47+
echo "Checking if CI workflow completed for commit ${{ github.sha }}..."
48+
CONCLUSION=$(gh run list --workflow=ci.yml --commit=${{ github.sha }} --status=completed --limit=1 --json conclusion -q '.[0].conclusion' || echo "not_found")
49+
if [ "$CONCLUSION" != "success" ]; then
50+
echo "ERROR: CI workflow has not successfully completed for commit ${{ github.sha }}"
51+
echo "Found conclusion: $CONCLUSION"
52+
echo "Ensure CI passes before triggering release"
53+
exit 1
54+
fi
55+
echo "CI workflow completed successfully"
56+
3857
# Download artifacts from the CI workflow run for this commit
3958
- name: Download artifacts from CI
4059
uses: dawidd6/action-download-artifact@0bd50d53a6d7fb5cb921e607957e9cc12b4ce392 # v6
@@ -66,6 +85,8 @@ jobs:
6685
6786
tarball=$(find "$artifact_dir" -name "*.tar" -type f | head -1)
6887
if [ -n "$tarball" ]; then
88+
echo "Validating $tarball integrity..."
89+
tar -tf "$tarball" > /dev/null || { echo "ERROR: Tarball $tarball is corrupted"; exit 1; }
6990
echo "Extracting $tarball"
7091
tar -xvf "$tarball" -C packages/
7192
else
@@ -79,7 +100,7 @@ jobs:
79100
ls -laR packages/
80101
81102
# Verify all platform packages present
82-
for platform in darwin-arm64 darwin-x64 linux-x64; do
103+
for platform in $PLATFORMS; do
83104
pkg_dir="packages/@pproenca/node-webcodecs-$platform"
84105
if [ ! -f "$pkg_dir/bin/node.napi.node" ]; then
85106
echo "Error: Missing binary for $platform"
@@ -91,10 +112,12 @@ jobs:
91112
# OIDC Trusted Publishing - no NPM_TOKEN needed
92113
- name: Publish platform packages
93114
run: |
94-
for platform in darwin-arm64 darwin-x64 linux-x64; do
115+
set -e
116+
for platform in $PLATFORMS; do
95117
pkg_dir="packages/@pproenca/node-webcodecs-$platform"
96118
echo "Publishing $pkg_dir..."
97119
(cd "$pkg_dir" && npm publish --provenance --access public)
120+
echo "Successfully published $platform"
98121
done
99122
100123
# Wait for npm registry propagation

0 commit comments

Comments
 (0)