diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 27ea569..0a5ff34 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -39,7 +39,33 @@ jobs: - name: Verify publication run: | - VERSION="${GITHUB_REF_NAME#v}" - sleep 10 - npm view @fiale-plus/repo-arch@"$VERSION" version - echo "Published $VERSION verified" + set -euo pipefail + + PKG="$(node -p "require('./package.json').name")" + VERSION="$(node -p "require('./package.json').version")" + DEADLINE=$((SECONDS + 300)) + DELAY=5 + MAX_DELAY=60 + + mkdir -p "$RUNNER_TEMP/npm-verify-cache" + echo "Verifying $PKG@$VERSION is visible on npm" + + while (( SECONDS < DEADLINE )); do + SEEN="$(npm view "$PKG@$VERSION" version --registry=https://registry.npmjs.org/ --prefer-online --cache="$RUNNER_TEMP/npm-verify-cache" 2>/dev/null || true)" + if [[ "$SEEN" == "$VERSION" ]]; then + echo "Published $VERSION verified" + exit 0 + fi + + REMAINING=$((DEADLINE - SECONDS)) + SLEEP_FOR=$(( DELAY < REMAINING ? DELAY : REMAINING )) + echo "Not visible yet; retrying in ${SLEEP_FOR}s..." + sleep "$SLEEP_FOR" + DELAY=$(( DELAY * 2 )) + if (( DELAY > MAX_DELAY )); then + DELAY=$MAX_DELAY + fi + done + + echo "Timed out waiting for $PKG@$VERSION to appear on npm" + exit 1 diff --git a/src/cli.ts b/src/cli.ts index 6552612..de5b584 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,6 +1,7 @@ #!/usr/bin/env node import * as fs from 'node:fs'; import * as path from 'node:path'; +import { fileURLToPath, pathToFileURL } from 'node:url'; import { mineHistory } from './git-history.js'; import { classifyHistory } from './signals.js'; import { generateCards, CARD_GENERATORS } from './cards.js'; @@ -762,7 +763,17 @@ export async function main(argv: string[] = process.argv.slice(2)): Promise<{ ok return { ok: false, error: `Unknown command: ${command}` }; } -if (import.meta.url === `file://${process.argv[1]}`) { +function isMainModule(): boolean { + const entry = process.argv[1]; + if (!entry) return false; + try { + return fs.realpathSync(path.resolve(entry)) === fs.realpathSync(fileURLToPath(import.meta.url)); + } catch { + return pathToFileURL(path.resolve(entry)).href === import.meta.url; + } +} + +if (isMainModule()) { try { main(); } catch (error) {