Skip to content

Commit fff8698

Browse files
authored
fix(publish): split github workflow ref (#6978)
Properly splits the github workflow ref on only the first `@`, ignoring any potential extras in the tag field.
1 parent 0f70088 commit fff8698

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

workspaces/libnpmpublish/lib/provenance.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ const generateProvenance = async (subject, opts) => {
1919
let payload
2020
if (ci.GITHUB_ACTIONS) {
2121
/* istanbul ignore next - not covering missing env var case */
22-
const [workflowPath, workflowRef] = (env.GITHUB_WORKFLOW_REF || '')
23-
.replace(env.GITHUB_REPOSITORY + '/', '')
24-
.split('@')
22+
const relativeRef = (env.GITHUB_WORKFLOW_REF || '').replace(env.GITHUB_REPOSITORY + '/', '')
23+
const delimiterIndex = relativeRef.indexOf('@')
24+
const workflowPath = relativeRef.slice(0, delimiterIndex)
25+
const workflowRef = relativeRef.slice(delimiterIndex + 1)
26+
2527
payload = {
2628
_type: INTOTO_STATEMENT_V1_TYPE,
2729
subject,

workspaces/libnpmpublish/test/publish.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ t.test('publish existing package with provenance in gha', async t => {
345345
const workflowPath = '.github/workflows/publish.yml'
346346
const repository = 'github/foo'
347347
const serverUrl = 'https://github.com'
348-
const ref = 'refs/heads/main'
348+
const ref = 'refs/tags/[email protected]'
349349
const sha = 'deadbeef'
350350
const runID = '123456'
351351
const runAttempt = '1'
@@ -529,6 +529,9 @@ t.test('publish existing package with provenance in gha', async t => {
529529
t.hasStrict(provenance.predicate.buildDefinition.buildType,
530530
'https://slsa-framework.github.io/github-actions-buildtypes/workflow/v1',
531531
'buildType matches expectations')
532+
t.hasStrict(provenance.predicate.buildDefinition.externalParameters.workflow.ref,
533+
'refs/tags/[email protected]',
534+
'workflowRef matches expectations')
532535
t.hasStrict(provenance.predicate.runDetails.builder.id,
533536
`https://github.com/actions/runner/${runnerEnv}`,
534537
'builder id matches expectations')

0 commit comments

Comments
 (0)