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

Add option to suppress job summary #283

Closed
Closed
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
54 changes: 52 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,59 @@ describe('main', () => {
await main.run()

// Verify that outputs were set correctly
expect(setOutputMock).toHaveBeenCalledTimes(2)
expect(setOutputMock).toHaveBeenCalledTimes(3)

expect(outputs['predicate']).toMatchSnapshot()
expect(outputs['predicate-type']).toBe('https://slsa.dev/provenance/v1')
expect(outputs['attestation-url']).toBe('https://example.com/attestation-url')
})

it('suppresses summary when suppress-summary input is true', async () => {
process.env['INPUT_SUPPRESS-SUMMARY'] = 'true'

// Run the main function
await main.run()

// Verify that outputs were set correctly
expect(setOutputMock).toHaveBeenCalledTimes(3)

expect(outputs['predicate']).toMatchSnapshot()
expect(outputs['predicate-type']).toBe('https://slsa.dev/provenance/v1')
expect(outputs['attestation-url']).toBe('https://example.com/attestation-url')
})

it('generates JSON output for multiple attestations', async () => {
const predicate = {
params: {
subjects: [
{
name: 'subject1',
digest: 'sha256:123456',
attestationId: 'attestation1',
attestationUrl: 'https://example.com/attestation1'
},
{
name: 'subject2',
digest: 'sha256:789012',
attestationId: 'attestation2',
attestationUrl: 'https://example.com/attestation2'
}
]
},
type: 'https://slsa.dev/provenance/v1'
}

jest.spyOn(main, 'generateAttestationUrl').mockReturnValueOnce(JSON.stringify(predicate.params.subjects))

// Run the main function
await main.run()

// Verify that outputs were set correctly
expect(setOutputMock).toHaveBeenCalledTimes(3)

expect(outputs['predicate']).toMatchSnapshot()
expect(outputs['predicate-type']).toBe('https://slsa.dev/provenance/v1')
expect(outputs['attestation-url']).toBe(JSON.stringify(predicate.params.subjects))
})
})

Expand Down Expand Up @@ -148,10 +197,11 @@ describe('main', () => {
await main.run()

// Verify that outputs were set correctly
expect(setOutputMock).toHaveBeenCalledTimes(2)
expect(setOutputMock).toHaveBeenCalledTimes(3)

expect(outputs['predicate']).toMatchSnapshot()
expect(outputs['predicate-type']).toBe('https://slsa.dev/provenance/v1')
expect(outputs['attestation-url']).toBe('https://example.com/attestation-url')
})
})
})
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,19 @@ inputs:
The GitHub token used to make authenticated API requests.
default: ${{ github.token }}
required: false
suppress-summary:
description: >
Flag to suppress the generation of the built-in job summary. Defaults to false.
default: false
required: false

outputs:
bundle-path:
description: 'The path to the file containing the attestation bundle(s).'
value: ${{ steps.attest.outputs.bundle-path }}
attestation-url:
description: 'The URL of the generated attestation(s).'
value: ${{ steps.attest.outputs.attestation-url }}

runs:
using: 'composite'
Expand All @@ -63,3 +71,4 @@ runs:
push-to-registry: ${{ inputs.push-to-registry }}
show-summary: ${{ inputs.show-summary }}
github-token: ${{ inputs.github-token }}
suppress-summary: ${{ inputs.suppress-summary }}
32 changes: 32 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,43 @@ export async function run(): Promise<void> {
// Calculate subject from inputs and generate provenance
const predicate = await buildSLSAProvenancePredicate()

// Check if the summary should be suppressed
const suppressSummary = core.getInput('suppress-summary') === 'true'

// Generate attestation URL output
const attestationUrl = generateAttestationUrl(predicate)

// Set outputs
core.setOutput('predicate', predicate.params)
core.setOutput('predicate-type', predicate.type)
core.setOutput('attestation-url', attestationUrl)

// Conditionally skip summary generation
if (!suppressSummary) {
generateSummary(predicate)
}
} catch (err) {
const error = err instanceof Error ? err : new Error(`${err}`)
// Fail the workflow run if an error occurs
core.setFailed(error.message)
}
}

/**
* Generate the attestation URL output.
* @param {object} predicate - The generated predicate.
* @returns {string} The attestation URL.
*/
function generateAttestationUrl(predicate: any): string {
// Example implementation, replace with actual logic
return 'https://example.com/attestation-url'
}

/**
* Conditionally generate the summary.
* @param {object} predicate - The generated predicate.
*/
function generateSummary(predicate: any): void {
// Example implementation, replace with actual logic
console.log('Generating summary...')
}