Skip to content

Commit 68cb12e

Browse files
committed
fix: use protocol-relative auth key, mask token, and drop shell spawning
Signed-off-by: pacoorozco <pakus@pakusland.net>
1 parent 230ef02 commit 68cb12e

5 files changed

Lines changed: 76 additions & 69 deletions

File tree

action.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ inputs:
105105
default: 'true'
106106
registry-url:
107107
description: |
108-
Base URL of a private npm registry to authenticate against, e.g.
109-
`https://myorg.jfrog.io/artifactory/api/npm/npm-local/`. When set,
110-
`registry-token` must also be provided. The action runs
111-
`pnpm config set "<url>//:_authToken" "<token>"` before installing.
108+
Base URL of a private npm registry to authenticate against before
109+
installing, e.g. `https://myorg.jfrog.io/artifactory/api/npm/npm-local/`.
110+
Requires `registry-token` to also be set.
112111
required: false
113112
registry-token:
114113
description: |
115114
Auth token for the private registry specified in `registry-url`.
116115
Pass this via a GitHub secret — it will not appear in logs.
116+
Requires `registry-url` to also be set.
117117
required: false
118118
token:
119119
description: >

dist/index.js

Lines changed: 54 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pnpm-install/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { info, setFailed, startGroup, endGroup } from '@actions/core'
1+
import { info, setFailed, setSecret, startGroup, endGroup } from '@actions/core'
22
import { spawnSync } from 'child_process'
33
import { existsSync } from 'fs'
44
import path from 'path'
@@ -50,17 +50,17 @@ export function runPnpmInstall(inputs: Inputs, runtimeInstalled = Boolean(inputs
5050
}
5151

5252
if (inputs.registry) {
53+
setSecret(inputs.registry.registryToken)
5354
const configArgs = buildRegistryAuthArgs(inputs.registry.registryUrl, inputs.registry.registryToken)
54-
const configCommand = `pnpm ${configArgs.join(' ')}`
55-
startGroup(`Running ${configCommand}...`)
56-
const configResult = spawnSync('pnpm', configArgs, { stdio: 'inherit', shell: true })
55+
startGroup('Configuring private registry auth...')
56+
const configResult = spawnSync('pnpm', configArgs, { stdio: 'inherit' })
5757
endGroup()
5858
if (configResult.error) {
5959
setFailed(configResult.error)
6060
return
6161
}
6262
if (configResult.status !== 0) {
63-
setFailed(`${configCommand} exited with status ${configResult.status}`)
63+
setFailed(`pnpm config set for private registry exited with status ${configResult.status}`)
6464
return
6565
}
6666
}

src/pnpm-install/registry.test.mjs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ import assert from 'node:assert/strict'
33
import { buildRegistryAuthArgs } from './registry.ts'
44

55
describe('buildRegistryAuthArgs', () => {
6-
it('returns config set args for the given registry and token', () => {
6+
it('uses protocol-relative key form with trailing slash', () => {
77
const args = buildRegistryAuthArgs('https://example.jfrog.io/npm/', 'mytoken')
8-
assert.deepEqual(args, ['config', 'set', 'https://example.jfrog.io/npm//:_authToken', 'mytoken'])
8+
assert.deepEqual(args, ['config', 'set', '//example.jfrog.io/npm/:_authToken', 'mytoken'])
99
})
1010

11-
it('appends trailing slash to registry URL if missing', () => {
11+
it('normalises missing trailing slash on the path', () => {
1212
const args = buildRegistryAuthArgs('https://example.jfrog.io/npm', 'mytoken')
13-
assert.deepEqual(args, ['config', 'set', 'https://example.jfrog.io/npm//:_authToken', 'mytoken'])
13+
assert.deepEqual(args, ['config', 'set', '//example.jfrog.io/npm/:_authToken', 'mytoken'])
14+
})
15+
16+
it('works with a bare hostname registry', () => {
17+
const args = buildRegistryAuthArgs('https://registry.example.com/', 'tok')
18+
assert.deepEqual(args, ['config', 'set', '//registry.example.com/:_authToken', 'tok'])
1419
})
1520
})

src/pnpm-install/registry.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export function buildRegistryAuthArgs(registryUrl: string, registryToken: string): string[] {
2-
const url = registryUrl.endsWith('/') ? registryUrl : `${registryUrl}/`
3-
return ['config', 'set', `${url}/:_authToken`, registryToken]
2+
const parsed = new URL(registryUrl)
3+
const path = parsed.pathname.endsWith('/') ? parsed.pathname : `${parsed.pathname}/`
4+
const key = `//${parsed.host}${path}:_authToken`
5+
return ['config', 'set', key, registryToken]
46
}

0 commit comments

Comments
 (0)