Skip to content

Commit 85a0689

Browse files
committed
fix(repo,versioner): harden npm publish
- Fail if pnpm pack emits != 1 tarball. - Add --registry option (default: https://registry.npmjs.org/) and log it. - Release workflow: fetch full git history and publish the triggering SHA.
1 parent 3ce093e commit 85a0689

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ jobs:
2626
- name: Checkout
2727
uses: actions/checkout@v4
2828
with:
29-
fetch-depth: 100
29+
fetch-depth: 0
3030
fetch-tags: true
31-
ref: master
3231

3332
- name: Setup Node
3433
uses: actions/setup-node@v4

packages/versioner/src/versioner.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,19 @@ const publish = async (cwd: string) => {
171171
try {
172172
await execa('pnpm', ['pack', '--pack-destination', packDir], { cwd, stdio: 'inherit' });
173173

174-
const tarballs = readdirSync(packDir).filter((file) => file.endsWith('.tgz'));
175-
const [tarball] = tarballs;
176-
if (!tarball) throw new Error(`Could not find packed tarball in: ${packDir}`);
174+
const tarballs = readdirSync(packDir)
175+
.filter((file) => file.endsWith('.tgz'))
176+
.sort();
177+
178+
if (tarballs.length !== 1) {
179+
throw new Error(
180+
`Expected exactly 1 packed tarball in: ${packDir} for cwd=${cwd} (found ${
181+
tarballs.length
182+
}): ${tarballs.join(', ')}`
183+
);
184+
}
177185

178-
const tarballPath = join(packDir, tarball);
186+
const tarballPath = join(packDir, tarballs[0]);
179187
const hasOidcEnv =
180188
!!process.env.ACTIONS_ID_TOKEN_REQUEST_URL && !!process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;
181189
const provenanceArgs = hasOidcEnv ? ['--provenance'] : [];

0 commit comments

Comments
 (0)