Skip to content

Commit

Permalink
Merge pull request actions#1969 from actions/bdehamer/workflow-ref
Browse files Browse the repository at this point in the history
set workflow.ref provenance field from ref claim
  • Loading branch information
bdehamer authored Feb 26, 2025
2 parents 5378ea8 + 0bc338a commit ec9716b
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 60 deletions.
4 changes: 4 additions & 0 deletions packages/attest/RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# @actions/attest Releases

### 1.6.0

- Update `buildSLSAProvenancePredicate` to populate `workflow.ref` field from the `ref` claim in the OIDC token [#1969](https://github.com/actions/toolkit/pull/1969)

### 1.5.0

- Bump @actions/core from 1.10.1 to 1.11.1 [#1847](https://github.com/actions/toolkit/pull/1847)
Expand Down
44 changes: 1 addition & 43 deletions packages/attest/__tests__/__snapshots__/provenance.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,47 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`provenance functions buildSLSAProvenancePredicate handle tags including "@" character 1`] = `
{
"params": {
"buildDefinition": {
"buildType": "https://actions.github.io/buildtypes/workflow/v1",
"externalParameters": {
"workflow": {
"path": ".github/workflows/main.yml",
"ref": "[email protected]",
"repository": "https://foo.ghe.com/owner/repo",
},
},
"internalParameters": {
"github": {
"event_name": "push",
"repository_id": "repo-id",
"repository_owner_id": "owner-id",
"runner_environment": "github-hosted",
},
},
"resolvedDependencies": [
{
"digest": {
"gitCommit": "babca52ab0c93ae16539e5923cb0d7403b9a093b",
},
"uri": "git+https://foo.ghe.com/owner/repo@refs/heads/main",
},
],
},
"runDetails": {
"builder": {
"id": "https://foo.ghe.com/owner/workflows/.github/workflows/publish.yml@main",
},
"metadata": {
"invocationId": "https://foo.ghe.com/owner/repo/actions/runs/run-id/attempts/run-attempt",
},
},
},
"type": "https://slsa.dev/provenance/v1",
}
`;

exports[`provenance functions buildSLSAProvenancePredicate returns a provenance hydrated from an OIDC token 1`] = `
{
"params": {
Expand All @@ -50,7 +8,7 @@ exports[`provenance functions buildSLSAProvenancePredicate returns a provenance
"externalParameters": {
"workflow": {
"path": ".github/workflows/main.yml",
"ref": "main",
"ref": "refs/heads/main",
"repository": "https://foo.ghe.com/owner/repo",
},
},
Expand Down
10 changes: 0 additions & 10 deletions packages/attest/__tests__/provenance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,6 @@ describe('provenance functions', () => {
const predicate = await buildSLSAProvenancePredicate()
expect(predicate).toMatchSnapshot()
})

it('handle tags including "@" character', async () => {
nock.cleanAll()
await mockIssuer({
...claims,
workflow_ref: 'owner/repo/.github/workflows/main.yml@[email protected]'
})
const predicate = await buildSLSAProvenancePredicate()
expect(predicate).toMatchSnapshot()
})
})

describe('attestProvenance', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/attest/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/attest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@actions/attest",
"version": "1.5.0",
"version": "1.6.0",
"description": "Actions attestation lib",
"keywords": [
"github",
Expand Down
6 changes: 2 additions & 4 deletions packages/attest/src/provenance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ export const buildSLSAProvenancePredicate = async (
// Split just the path and ref from the workflow string.
// owner/repo/.github/workflows/main.yml@main =>
// .github/workflows/main.yml, main
const [workflowPath, ...workflowRefChunks] = claims.workflow_ref
const [workflowPath] = claims.workflow_ref
.replace(`${claims.repository}/`, '')
.split('@')
// Handle case where tag contains `@` (e.g: when using changesets in a monorepo context),
const workflowRef = workflowRefChunks.join('@')

return {
type: SLSA_PREDICATE_V1_TYPE,
Expand All @@ -43,7 +41,7 @@ export const buildSLSAProvenancePredicate = async (
buildType: GITHUB_BUILD_TYPE,
externalParameters: {
workflow: {
ref: workflowRef,
ref: claims.ref,
repository: `${serverURL}/${claims.repository}`,
path: workflowPath
}
Expand Down

0 comments on commit ec9716b

Please sign in to comment.