Skip to content
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

fix(publish): split github workflow ref #6978

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions workspaces/libnpmpublish/lib/provenance.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ const generateProvenance = async (subject, opts) => {
let payload
if (ci.GITHUB_ACTIONS) {
/* istanbul ignore next - not covering missing env var case */
const [workflowPath, workflowRef] = (env.GITHUB_WORKFLOW_REF || '')
.replace(env.GITHUB_REPOSITORY + '/', '')
.split('@')
const relativeRef = (env.GITHUB_WORKFLOW_REF || '').replace(env.GITHUB_REPOSITORY + '/', '')
wraithgar marked this conversation as resolved.
Show resolved Hide resolved
const delimiterIndex = relativeRef.indexOf('@')
const workflowPath = relativeRef.slice(0, delimiterIndex)
const workflowRef = relativeRef.slice(delimiterIndex + 1)

payload = {
_type: INTOTO_STATEMENT_V1_TYPE,
subject,
Expand Down
5 changes: 4 additions & 1 deletion workspaces/libnpmpublish/test/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ t.test('publish existing package with provenance in gha', async t => {
const workflowPath = '.github/workflows/publish.yml'
const repository = 'github/foo'
const serverUrl = 'https://github.com'
const ref = 'refs/heads/main'
const ref = 'refs/tags/pkg@1.0.0'
const sha = 'deadbeef'
const runID = '123456'
const runAttempt = '1'
Expand Down Expand Up @@ -529,6 +529,9 @@ t.test('publish existing package with provenance in gha', async t => {
t.hasStrict(provenance.predicate.buildDefinition.buildType,
'https://slsa-framework.github.io/github-actions-buildtypes/workflow/v1',
'buildType matches expectations')
t.hasStrict(provenance.predicate.buildDefinition.externalParameters.workflow.ref,
'refs/tags/pkg@1.0.0',
'workflowRef matches expectations')
t.hasStrict(provenance.predicate.runDetails.builder.id,
`https://github.com/actions/runner/${runnerEnv}`,
'builder id matches expectations')
Expand Down
Loading