-
-
Notifications
You must be signed in to change notification settings - Fork 481
Expand file tree
/
Copy pathworkspace-trust.sh
More file actions
executable file
·60 lines (55 loc) · 1.8 KB
/
Copy pathworkspace-trust.sh
File metadata and controls
executable file
·60 lines (55 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
set -euo pipefail
PACKAGES=()
for pkg_dir in packages/*; do
if [ -f "$pkg_dir/package.json" ]; then
name=$(jq -r '.name // empty' "$pkg_dir/package.json")
private=$(jq -r '.private // false' "$pkg_dir/package.json")
if [ -n "$name" ] && [ "$private" != "true" ]; then
PACKAGES+=("$name")
fi
fi
done
REPO_NAME="felixmosh/bull-board"
WORKFLOW_FILE="release.yml" # Must be just the filename, not the full path
for pkg in "${PACKAGES[@]}"; do
echo " Configuring trusted publishing for $pkg..."
if ! npm view "$pkg" version >/dev/null 2>&1; then
echo " Package not found on registry, publishing placeholder stub..."
tmpdir=$(mktemp -d)
cat > "$tmpdir/package.json" <<-EOF
{
"name": "$pkg",
"version": "0.0.0",
"description": "Stub package for npm trusted publishing setup",
"main": "index.js",
"publishConfig": { "access": "public" }
}
EOF
echo "module.exports = {};" > "$tmpdir/index.js"
if npm publish "$tmpdir" --access public 2>&1; then
echo " Stub published, now configuring trust..."
else
echo " Failed to publish stub for $pkg, skipping"
continue
fi
rm -rf "$tmpdir"
fi
tmpfile=$(mktemp)
npm trust github "$pkg" --repo "$REPO_NAME" --file "$WORKFLOW_FILE" --allow-publish 2>&1 | tee "$tmpfile" || true
exit_code=${PIPESTATUS[0]}
if [ "$exit_code" -eq 0 ]; then
echo "✓ $pkg configured"
elif grep -q "E409" "$tmpfile"; then
echo "✓ $pkg already has trusted publishing configured, skipping"
elif grep -q "EOTP" "$tmpfile"; then
: # npm already printed the auth URL above; user can authenticate and re-run
elif grep -q "E404" "$tmpfile"; then
: # npm already printed the 404 above
else
echo " ✗ Failed to configure trust for $pkg"
rm -f "$tmpfile"
exit 1
fi
rm -f "$tmpfile"
sleep 2
done