-
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); | ||
|
||
| 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.
Show resolved
Hide resolved
|
||
| ); | ||
shellscape marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } finally { | ||
| rmSync(packDir, { force: true, recursive: true }); | ||
| } | ||
| }; | ||
|
|
||
| const pull = async () => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.