Skip to content

Commit c59c9d5

Browse files
committed
set workflow.ref provenance field from ref claim
Updates the `buildSLSAProvenancePredicate` function to populate the `workflow.ref` field from the `ref` claim in the OIDC token. Signed-off-by: Brian DeHamer <bdehamer@github.com>
1 parent b95b593 commit c59c9d5

File tree

6 files changed

+10
-60
lines changed

6 files changed

+10
-60
lines changed

packages/attest/RELEASES.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# @actions/attest Releases
22

3+
### 1.6.0
4+
5+
- Update `buildSLSAProvenancePredicate` to populate `workflow.ref` field from the `ref` claim in the OIDC token [#XXXX](XXX)
6+
37
### 1.5.0
48

59
- Bump @actions/core from 1.10.1 to 1.11.1 [#1847](https://github.com/actions/toolkit/pull/1847)

packages/attest/__tests__/__snapshots__/provenance.test.ts.snap

+1-43
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,5 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`provenance functions buildSLSAProvenancePredicate handle tags including "@" character 1`] = `
4-
{
5-
"params": {
6-
"buildDefinition": {
7-
"buildType": "https://actions.github.io/buildtypes/workflow/v1",
8-
"externalParameters": {
9-
"workflow": {
10-
"path": ".github/workflows/main.yml",
11-
"ref": "foo@1.0.0",
12-
"repository": "https://foo.ghe.com/owner/repo",
13-
},
14-
},
15-
"internalParameters": {
16-
"github": {
17-
"event_name": "push",
18-
"repository_id": "repo-id",
19-
"repository_owner_id": "owner-id",
20-
"runner_environment": "github-hosted",
21-
},
22-
},
23-
"resolvedDependencies": [
24-
{
25-
"digest": {
26-
"gitCommit": "babca52ab0c93ae16539e5923cb0d7403b9a093b",
27-
},
28-
"uri": "git+https://foo.ghe.com/owner/repo@refs/heads/main",
29-
},
30-
],
31-
},
32-
"runDetails": {
33-
"builder": {
34-
"id": "https://foo.ghe.com/owner/workflows/.github/workflows/publish.yml@main",
35-
},
36-
"metadata": {
37-
"invocationId": "https://foo.ghe.com/owner/repo/actions/runs/run-id/attempts/run-attempt",
38-
},
39-
},
40-
},
41-
"type": "https://slsa.dev/provenance/v1",
42-
}
43-
`;
44-
453
exports[`provenance functions buildSLSAProvenancePredicate returns a provenance hydrated from an OIDC token 1`] = `
464
{
475
"params": {
@@ -50,7 +8,7 @@ exports[`provenance functions buildSLSAProvenancePredicate returns a provenance
508
"externalParameters": {
519
"workflow": {
5210
"path": ".github/workflows/main.yml",
53-
"ref": "main",
11+
"ref": "refs/heads/main",
5412
"repository": "https://foo.ghe.com/owner/repo",
5513
},
5614
},

packages/attest/__tests__/provenance.test.ts

-10
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,6 @@ describe('provenance functions', () => {
7575
const predicate = await buildSLSAProvenancePredicate()
7676
expect(predicate).toMatchSnapshot()
7777
})
78-
79-
it('handle tags including "@" character', async () => {
80-
nock.cleanAll()
81-
await mockIssuer({
82-
...claims,
83-
workflow_ref: 'owner/repo/.github/workflows/main.yml@foo@1.0.0'
84-
})
85-
const predicate = await buildSLSAProvenancePredicate()
86-
expect(predicate).toMatchSnapshot()
87-
})
8878
})
8979

9080
describe('attestProvenance', () => {

packages/attest/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/attest/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@actions/attest",
3-
"version": "1.5.0",
3+
"version": "1.6.0",
44
"description": "Actions attestation lib",
55
"keywords": [
66
"github",

packages/attest/src/provenance.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ export const buildSLSAProvenancePredicate = async (
3030
// Split just the path and ref from the workflow string.
3131
// owner/repo/.github/workflows/main.yml@main =>
3232
// .github/workflows/main.yml, main
33-
const [workflowPath, ...workflowRefChunks] = claims.workflow_ref
33+
const [workflowPath] = claims.workflow_ref
3434
.replace(`${claims.repository}/`, '')
3535
.split('@')
36-
// Handle case where tag contains `@` (e.g: when using changesets in a monorepo context),
37-
const workflowRef = workflowRefChunks.join('@')
3836

3937
return {
4038
type: SLSA_PREDICATE_V1_TYPE,
@@ -43,7 +41,7 @@ export const buildSLSAProvenancePredicate = async (
4341
buildType: GITHUB_BUILD_TYPE,
4442
externalParameters: {
4543
workflow: {
46-
ref: workflowRef,
44+
ref: claims.ref,
4745
repository: `${serverURL}/${claims.repository}`,
4846
path: workflowPath
4947
}

0 commit comments

Comments
 (0)