Skip to content

Commit 1862015

Browse files
committed
chore: oidc npm workflow handling
1 parent 39cebef commit 1862015

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

.github/scripts/npm-publish-ci.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,29 @@ set -euo pipefail
33

44
TAG="${NPM_TAG:-next}"
55

6+
pkg_name="$(node -p "require('./package.json').name")"
7+
pkg_version="$(node -p "require('./package.json').version")"
8+
9+
# Skip publishing if this exact version already exists on npm.
10+
# This keeps CI logs clean and avoids attempting to publish unchanged packages.
11+
view_log_file="$(mktemp)"
12+
set +e
13+
npm view "${pkg_name}@${pkg_version}" version --registry "https://registry.npmjs.org" 2>&1 | tee "$view_log_file" >/dev/null
14+
view_status=${PIPESTATUS[0]}
15+
set -e
16+
17+
if [ "$view_status" -eq 0 ]; then
18+
echo "Skip publish: ${pkg_name}@${pkg_version} already exists on npm."
19+
exit 0
20+
fi
21+
22+
# If npm view failed because the package/version doesn't exist, continue to publish.
23+
if ! grep -qiE '(E404|404 Not Found|code E404|is not in this registry)' "$view_log_file"; then
24+
echo "npm view failed unexpectedly for ${pkg_name}@${pkg_version}; refusing to publish."
25+
cat "$view_log_file" >&2
26+
exit "$view_status"
27+
fi
28+
629
args=(
730
--tag "$TAG"
831
--access public

.github/workflows/publish_npm.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ jobs:
3737
run: |
3838
echo "Publishing templates to npm with tag $NPM_TAG via OIDC trusted publishing..."
3939
unset NODE_AUTH_TOKEN
40+
# Ensure we don't have token-based npm auth config lingering from setup-node
41+
rm -f ~/.npmrc
4042
if [ -n "${NPM_CONFIG_USERCONFIG:-}" ]; then
4143
rm -f "$NPM_CONFIG_USERCONFIG"
4244
unset NPM_CONFIG_USERCONFIG

0 commit comments

Comments
 (0)