Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 12 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
Loading