Skip to content

Commit 1087414

Browse files
committed
fix: ci
1 parent 9afbad0 commit 1087414

File tree

1 file changed

+17
-58
lines changed

1 file changed

+17
-58
lines changed

.github/workflows/dev.yaml

Lines changed: 17 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ jobs:
7676
${{ runner.os }}-pnpm-store-
7777
7878
# OIDC trusted publishing requires npm 11.5.1+
79-
- name: Update npm and set up Git user
79+
- name: Update npm for OIDC trusted publishing
80+
run: npm install -g npm@latest
81+
82+
- name: Set up Git user
8083
run: |
81-
npm install -g npm@latest &
82-
NPM_PID=$!
8384
git config user.name "${{ github.actor }}"
8485
git config user.email "${{ github.actor }}@users.noreply.github.com"
85-
wait $NPM_PID || { echo "::error::Failed to update npm"; exit 1; }
8686
8787
- name: Determine publish type
8888
id: determine-publish-type
@@ -143,76 +143,35 @@ jobs:
143143
- name: Publish to npm (OIDC)
144144
run: |
145145
DIST_TAG="${{ steps.determine-publish-type.outputs.dist_tag }}"
146+
PUBLISHED_PACKAGES="[]"
146147
ROOT_DIR="$(pwd)"
148+
PUBLISH_COUNT=0
147149
148-
# Create a temporary directory for publish scripts
149-
mkdir -p "$ROOT_DIR/.publish-tmp"
150-
151-
# Generate publish commands for all packages (use null delimiter for safety)
152150
for pkg_json in packages/*/package.json packages/wallets/*/package.json; do
153151
pkg_dir=$(dirname "$pkg_json")
154152
pkg_name=$(node -p "require('./$pkg_json').name")
155153
pkg_version=$(node -p "require('./$pkg_json').version")
156-
tarball_name=$(echo "$pkg_name" | sed 's/@//;s/\//-/')-$pkg_version.tgz
154+
155+
echo "📦 Publishing $pkg_name@$pkg_version"
157156
158157
# Pack with pnpm to resolve catalog: dependencies
159-
pnpm --dir "$pkg_dir" pack --pack-destination "$ROOT_DIR/.publish-tmp"
158+
pnpm --dir "$pkg_dir" pack --pack-destination "$ROOT_DIR"
160159
161-
if [ -f "$ROOT_DIR/.publish-tmp/$tarball_name" ]; then
162-
# Use null delimiter to safely handle any package names
163-
printf '%s\t%s\t%s\0' "$ROOT_DIR/.publish-tmp/$tarball_name" "$pkg_name" "$pkg_version" >> "$ROOT_DIR/.publish-tmp/packages.txt"
160+
tarball_name=$(echo "$pkg_name" | sed 's/@//;s/\//-/')-$pkg_version.tgz
161+
162+
if [ -f "$tarball_name" ]; then
163+
if npm publish "$tarball_name" --access public --tag "$DIST_TAG" --provenance; then
164+
PUBLISHED_PACKAGES=$(echo "$PUBLISHED_PACKAGES" | node -p "JSON.stringify([...JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')), {name:'$pkg_name',version:'$pkg_version'}])")
165+
PUBLISH_COUNT=$((PUBLISH_COUNT + 1))
166+
fi
167+
rm -f "$tarball_name"
164168
else
165169
echo "⚠️ No tarball found for $pkg_name"
166170
fi
167171
done
168172
169-
# Publish packages in parallel (4 concurrent jobs)
170-
RESULTS_FILE="$ROOT_DIR/.publish-tmp/results.txt"
171-
FAILED_FILE="$ROOT_DIR/.publish-tmp/failed.txt"
172-
touch "$RESULTS_FILE" "$FAILED_FILE"
173-
174-
publish_package() {
175-
IFS=$'\t' read -r tarball pkg_name pkg_version <<< "$1"
176-
echo "📦 Publishing $pkg_name@$pkg_version"
177-
if npm publish "$tarball" --access public --tag "$DIST_TAG" --provenance 2>&1; then
178-
echo "$pkg_name:$pkg_version" >> "$RESULTS_FILE"
179-
else
180-
echo "$pkg_name:$pkg_version" >> "$FAILED_FILE"
181-
echo "::warning::Failed to publish $pkg_name@$pkg_version"
182-
fi
183-
}
184-
export -f publish_package
185-
export DIST_TAG RESULTS_FILE FAILED_FILE
186-
187-
# Run publishes in parallel using null delimiter for safety
188-
if [ -f "$ROOT_DIR/.publish-tmp/packages.txt" ]; then
189-
xargs -0 -P 4 -I {} bash -c 'publish_package "$@"' _ {} < "$ROOT_DIR/.publish-tmp/packages.txt"
190-
fi
191-
192-
# Build results from file
193-
PUBLISH_COUNT=$(wc -l < "$RESULTS_FILE" | tr -d ' ')
194-
FAILED_COUNT=$(wc -l < "$FAILED_FILE" | tr -d ' ')
195-
196-
# Build JSON array efficiently
197-
PUBLISHED_PACKAGES=$(node -e "
198-
const fs = require('fs');
199-
const lines = fs.readFileSync('$RESULTS_FILE', 'utf8').trim().split('\n').filter(Boolean);
200-
const packages = lines.map(line => {
201-
const [name, version] = line.split(':');
202-
return { name, version };
203-
});
204-
console.log(JSON.stringify(packages));
205-
")
206-
207-
# Cleanup
208-
rm -rf "$ROOT_DIR/.publish-tmp"
209-
210173
echo "{\"publishedPackages\":$PUBLISHED_PACKAGES}" > pnpm-publish-summary.json
211174
212-
if [ "$FAILED_COUNT" -gt 0 ]; then
213-
echo "::warning::$FAILED_COUNT package(s) failed to publish"
214-
fi
215-
216175
if [ "$PUBLISH_COUNT" -eq 0 ]; then
217176
echo "::error::No packages were published. Check npm OIDC trusted publisher configuration."
218177
exit 1

0 commit comments

Comments
 (0)