Skip to content

Commit 913d0bc

Browse files
committed
Tighten alpha npm release tooling
1 parent 2055042 commit 913d0bc

2 files changed

Lines changed: 37 additions & 9 deletions

File tree

.github/workflows/alpha-release.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,12 @@ jobs:
6464
6565
publish_alpha "@pydantic/logfire-session-replay" "packages/logfire-session-replay/package.json"
6666
publish_alpha "@pydantic/logfire-browser" "packages/logfire-browser/package.json"
67+
68+
replay_version="$(node -p "require('./packages/logfire-session-replay/package.json').version")"
69+
replay_latest="$(npm view @pydantic/logfire-session-replay dist-tags.latest --json 2>/dev/null | tr -d '"')"
70+
if [ "$replay_latest" = "$replay_version" ]; then
71+
echo "Removing latest dist-tag from @pydantic/logfire-session-replay; alpha is the intended install tag"
72+
npm dist-tag rm @pydantic/logfire-session-replay latest
73+
fi
6774
env:
6875
NPM_CONFIG_PROVENANCE: false

scripts/create-npm-token.sh

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
set -uo pipefail
2+
set -euo pipefail
33

44
# Creates a granular npm token for CI publishing and updates the
55
# NPM_TOKEN secret in the GitHub repo.
@@ -10,10 +10,21 @@ set -uo pipefail
1010
# Runs from a temp directory to avoid project .npmrc / devEngines config.
1111

1212
REPO="pydantic/logfire-js"
13+
ENVIRONMENT="npm"
1314
WORKDIR=$(mktemp -d)
1415
trap 'rm -rf "$WORKDIR"' EXIT
1516
TOKEN_FILE="$WORKDIR/token.txt"
1617

18+
command -v gh >/dev/null || { echo "gh CLI is required."; exit 1; }
19+
command -v npm >/dev/null || { echo "npm CLI is required."; exit 1; }
20+
command -v script >/dev/null || { echo "script command is required to preserve interactive npm prompts."; exit 1; }
21+
22+
echo "Checking GitHub authentication..."
23+
gh auth status --hostname github.com >/dev/null
24+
25+
echo "Checking npm authentication..."
26+
npm whoami --registry https://registry.npmjs.org/ >/dev/null
27+
1728
echo "Creating npm granular access token..."
1829
echo ""
1930

@@ -24,21 +35,31 @@ script -q "$TOKEN_FILE" sh -c "cd '$WORKDIR' && npm token create \
2435
--scopes @pydantic \
2536
--packages logfire \
2637
--packages-and-scopes-permission read-write \
27-
--bypass-2fa \
28-
--otp=''"
38+
--bypass-2fa"
2939

3040
echo ""
3141

32-
TOKEN=$(grep -i 'token' "$TOKEN_FILE" | grep '' | head -1 | sed 's/.*│[[:space:]]*//' | sed 's/[[:space:]]*$//' | tr -d '\r')
42+
TOKEN=$(
43+
awk -F '' '
44+
tolower($2) ~ /^[[:space:]]*token[[:space:]]*$/ {
45+
value = $3
46+
gsub(/^[[:space:]]+|[[:space:]]+$/, "", value)
47+
print value
48+
exit
49+
}
50+
' "$TOKEN_FILE" | tr -d '\r'
51+
)
52+
53+
if [ -z "$TOKEN" ]; then
54+
TOKEN=$(grep -Eo 'npm_[A-Za-z0-9_=-]+' "$TOKEN_FILE" | head -1 || true)
55+
fi
3356

3457
if [ -z "$TOKEN" ]; then
3558
echo "Failed to extract token from output."
3659
exit 1
3760
fi
3861

39-
echo "Token:"
40-
echo "$TOKEN"
62+
echo "Updating NPM_TOKEN secret in $REPO (environment: $ENVIRONMENT)..."
63+
gh secret set NPM_TOKEN --repo "$REPO" --env "$ENVIRONMENT" --body "$TOKEN" >/dev/null
4164

42-
# echo "Updating NPM_TOKEN secret in $REPO (environment: npm)..."
43-
# echo "$TOKEN" | gh secret set NPM_TOKEN --repo "$REPO" --env npm
44-
# echo "Done. NPM_TOKEN secret updated in $REPO."
65+
echo "Done. NPM_TOKEN secret updated in $REPO (environment: $ENVIRONMENT)."

0 commit comments

Comments
 (0)