-
Notifications
You must be signed in to change notification settings - Fork 2
fix(versioner): publish with npm via OIDC #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
3697854
e96045b
3ce093e
85a0689
7eb5ac9
31e9983
60b10d0
4fb8a3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| import 'source-map-support'; | ||
|
|
||
| import { dirname, join, resolve } from 'path'; | ||
| import { existsSync, readFileSync, writeFileSync } from 'fs'; | ||
| import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'fs'; | ||
| import { tmpdir } from 'os'; | ||
|
|
||
| import { getLog } from '@dot/log'; | ||
| import parser from 'conventional-commits-parser'; | ||
|
|
@@ -25,6 +26,8 @@ const parserOptions = { | |
| noteKeywords: ['BREAKING CHANGE', 'Breaking Change'] | ||
| }; | ||
| const reBreaking = new RegExp(`(${parserOptions.noteKeywords.join(')|(')})`); | ||
| const NPM_CLI_SPEC = 'npm@11.5.1'; | ||
| const DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org/'; | ||
|
|
||
| type Commit = parser.Commit<string | number | symbol>; | ||
|
|
||
|
|
@@ -151,9 +154,47 @@ const publish = async (cwd: string) => { | |
| return; | ||
| } | ||
|
|
||
| if (typeof argv.registry !== 'undefined' && typeof argv.registry !== 'string') { | ||
| throw new TypeError(`--registry must be a string, received: ${typeof argv.registry}`); | ||
| } | ||
|
|
||
| const registry = argv.registry || DEFAULT_NPM_REGISTRY; | ||
|
|
||
| log.info(chalk`\n{cyan Publishing to NPM}`); | ||
| log.info(chalk`{grey Registry:} ${registry}`); | ||
|
|
||
| await execa('pnpm', ['publish', '--no-git-checks'], { cwd, stdio: 'inherit' }); | ||
| const packDir = mkdtempSync(join(tmpdir(), 'versioner-pack-')); | ||
| try { | ||
| await execa('pnpm', ['pack', '--pack-destination', packDir], { cwd, stdio: 'inherit' }); | ||
|
|
||
| const tarballs = readdirSync(packDir).filter((file) => file.endsWith('.tgz')); | ||
| const [tarball] = tarballs; | ||
| if (!tarball) throw new Error(`Could not find packed tarball in: ${packDir}`); | ||
|
|
||
| const tarballPath = join(packDir, tarball); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Also consider sorting to make the selection deterministic if you intentionally support multiple outputs later. SuggestionTighten the tarball discovery to be explicit and deterministic: const tarballs = readdirSync(packDir)
.filter((file) => file.endsWith('.tgz'))
.sort();
if (tarballs.length !== 1) {
throw new Error(
`Expected exactly 1 packed tarball in ${packDir}, found ${tarballs.length}: ${tarballs.join(', ')}`
);
}
const tarballPath = join(packDir, tarballs[0]);Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this suggestion.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @CharlieHelps yes please
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expand this to see my work.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Applied the requested changes on PR #6. Changes
Verification# Install
$ CI=1 pnpm install --frozen-lockfile
# Build
$ pnpm -r build
# Lint (1 warning)
$ pnpm lint
# Tests
$ AWS_REGION=us-east-1 pnpm -r test --if-present
|
||
| const hasOidcEnv = | ||
| !!process.env.ACTIONS_ID_TOKEN_REQUEST_URL && !!process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN; | ||
| const provenanceArgs = hasOidcEnv ? ['--provenance'] : []; | ||
|
|
||
| log.info(chalk`{grey Using npm CLI:} ${NPM_CLI_SPEC}`); | ||
|
|
||
| await execa( | ||
| 'pnpm', | ||
| [ | ||
| 'dlx', | ||
| NPM_CLI_SPEC, | ||
| 'publish', | ||
| '--no-git-checks', | ||
| '--registry', | ||
| registry, | ||
| ...provenanceArgs, | ||
| tarballPath | ||
| ], | ||
| { cwd, stdio: 'inherit' } | ||
|
shellscape marked this conversation as resolved.
|
||
| ); | ||
|
shellscape marked this conversation as resolved.
|
||
| } finally { | ||
| rmSync(packDir, { force: true, recursive: true }); | ||
| } | ||
| }; | ||
|
|
||
| const pull = async () => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.