Skip to content

Commit d281274

Browse files
authored
Merge pull request #35 from optave/fix/publish-resilience
fix(ci): fix deps:tree publish failure and add publish resilience
2 parents ec72021 + 54a8ce0 commit d281274

3 files changed

Lines changed: 37 additions & 5 deletions

File tree

.github/workflows/publish.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,23 @@ jobs:
175175
with:
176176
path: artifacts/
177177

178-
- name: Verify version not already on npm
178+
- name: Check if main package already published
179+
id: check-main
179180
env:
180181
VERSION: ${{ needs.compute-version.outputs.version }}
181182
run: |
182183
PKG="@optave/codegraph"
183184
echo "Checking if $PKG@$VERSION already exists on npm..."
184185
if npm view "$PKG@$VERSION" version 2>/dev/null; then
185-
echo "::error::$PKG@$VERSION is already published on npm."
186-
exit 1
186+
echo "⚠️ $PKG@$VERSION is already published — will skip publish steps"
187+
echo "already_published=true" >> "$GITHUB_OUTPUT"
188+
else
189+
echo "$PKG@$VERSION is not yet published — proceeding"
190+
echo "already_published=false" >> "$GITHUB_OUTPUT"
187191
fi
188-
echo "$PKG@$VERSION is not yet published — proceeding"
189192
190193
- name: Publish platform packages
194+
if: steps.check-main.outputs.already_published == 'false'
191195
env:
192196
VERSION: ${{ needs.compute-version.outputs.version }}
193197
NPM_TAG: ${{ needs.compute-version.outputs.npm_tag }}
@@ -226,11 +230,18 @@ jobs:
226230
}
227231
PKGJSON
228232
233+
# Skip if this exact version is already published (idempotent re-runs)
234+
if npm view "${pkg_name}@${VERSION}" version 2>/dev/null; then
235+
echo "⚠️ ${pkg_name}@${VERSION} already published — skipping"
236+
continue
237+
fi
238+
229239
echo "Publishing ${pkg_name}@${VERSION} with --tag ${NPM_TAG}"
230240
npm publish "./pkg/$platform" --access public --provenance --tag "$NPM_TAG"
231241
done
232242
233243
- name: Publish main package
244+
if: steps.check-main.outputs.already_published == 'false'
234245
env:
235246
NPM_TAG: ${{ needs.compute-version.outputs.npm_tag }}
236247
run: npm publish --access public --provenance --tag "$NPM_TAG"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"lint:fix": "biome check --write src/ tests/",
3131
"format": "biome format --write src/ tests/",
3232
"prepare": "npm run build:wasm && husky && npm run deps:tree",
33-
"deps:tree": "node -e \"const{execSync}=require('child_process');const t=execSync('npm ls --all --omit=dev',{encoding:'utf8'});require('fs').writeFileSync('DEPENDENCIES.md','# Dependencies\\n\\n```\\n'+t+'```\\n')\"",
33+
"deps:tree": "node scripts/gen-deps.cjs",
3434
"release": "commit-and-tag-version",
3535
"release:dry-run": "commit-and-tag-version --dry-run",
3636
"version": "node scripts/sync-native-versions.js && git add package.json",

scripts/gen-deps.cjs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { execSync } = require('child_process');
2+
const fs = require('fs');
3+
4+
try {
5+
const tree = execSync('npm ls --all --omit=dev', { encoding: 'utf8' });
6+
fs.writeFileSync(
7+
'DEPENDENCIES.md',
8+
'# Dependencies\n\n```\n' + tree + '```\n',
9+
);
10+
} catch (err) {
11+
// npm ls exits non-zero on ELSPROBLEMS (version mismatches in optional deps).
12+
// If stdout still has content, write it; otherwise skip silently.
13+
if (err.stdout) {
14+
fs.writeFileSync(
15+
'DEPENDENCIES.md',
16+
'# Dependencies\n\n```\n' + err.stdout + '```\n',
17+
);
18+
} else {
19+
console.warn('deps:tree skipped —', err.message);
20+
}
21+
}

0 commit comments

Comments
 (0)