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

Support single-subject attestations #219

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Inline createAttestation wrapper functions
  • Loading branch information
AA-Turner committed Mar 1, 2025
commit c85ef89b80a872d84e565ff463405ef686ae30d1
11 changes: 5 additions & 6 deletions src/attest.ts
Original file line number Diff line number Diff line change
@@ -6,11 +6,6 @@ const OCI_TIMEOUT = 30000
const OCI_RETRY = 3

export type SigstoreInstance = 'public-good' | 'github'
export type CreateAttestationOptions = {
sigstoreInstance: SigstoreInstance
pushToRegistry: boolean
githubToken: string
}
export type AttestResult = Attestation & {
attestationDigest?: string
attestationSubjects: Subject[]
@@ -19,7 +14,11 @@ export type AttestResult = Attestation & {
export const createAttestation = async (
subjects: Subject[],
predicate: Predicate,
opts: CreateAttestationOptions
opts: {
sigstoreInstance: SigstoreInstance
pushToRegistry: boolean
githubToken: string
}
): Promise<AttestResult> => {
// Sign provenance w/ Sigstore
const attestation: Attestation = await attest({
56 changes: 15 additions & 41 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -3,12 +3,7 @@ import * as github from '@actions/github'
import fs from 'fs'
import os from 'os'
import path from 'path'
import {
AttestResult,
SigstoreInstance,
createAttestation,
CreateAttestationOptions
} from './attest'
import { AttestResult, SigstoreInstance, createAttestation } from './attest'
import { SEARCH_PUBLIC_GOOD_URL } from './endpoints'
import { PredicateInputs, predicateFromInputs } from './predicate'
import * as style from './style'
@@ -18,8 +13,6 @@ import {
subjectFromInputs
} from './subject'

import type { Predicate, Subject } from '@actions/attest'

const ATTESTATION_FILE_NAME = 'attestation.json'

export type RunInputs = SubjectInputs &
@@ -72,17 +65,22 @@ export async function run(inputs: RunInputs): Promise<void> {
const outputPath = path.join(tempDir(), ATTESTATION_FILE_NAME)
core.setOutput('bundle-path', outputPath)

const opts: CreateAttestationOptions = {
const opts = {
sigstoreInstance,
pushToRegistry: inputs.pushToRegistry,
githubToken: inputs.githubToken
}

let atts: AttestResult[]
const atts: AttestResult[] = []
if (inputs.singleSubjectAttestations) {
atts = await createSingleSubjectAttestations(subjects, predicate, opts)
// Generate one attestation for each subject
for (const subject of subjects) {
const att = await createAttestation([subject], predicate, opts)
atts.push(att)
}
} else {
atts = await createMultiSubjectAttestation(subjects, predicate, opts)
const att = await createAttestation(subjects, predicate, opts)
atts.push(att)
}

for (const att of atts) {
@@ -95,6 +93,11 @@ export async function run(inputs: RunInputs): Promise<void> {
})
}

if (atts[0].attestationID) {
core.setOutput('attestation-id', atts[0].attestationID)
core.setOutput('attestation-url', attestationURL(atts[0].attestationID))
}

if (inputs.showSummary) {
await logSummary(atts)
}
@@ -119,35 +122,6 @@ export async function run(inputs: RunInputs): Promise<void> {
}
}

const createSingleSubjectAttestations = async (
subjects: Subject[],
predicate: Predicate,
opts: CreateAttestationOptions
): Promise<AttestResult[]> => {
const atts: AttestResult[] = []
// Generate one attestation for each subject
for (const subject of subjects) {
const att = await createAttestation([subject], predicate, opts)
atts.push(att)
}
return atts
}

const createMultiSubjectAttestation = async (
subjects: Subject[],
predicate: Predicate,
opts: CreateAttestationOptions
): Promise<AttestResult[]> => {
const att = await createAttestation(subjects, predicate, opts)

if (att.attestationID) {
core.setOutput('attestation-id', att.attestationID)
core.setOutput('attestation-url', attestationURL(att.attestationID))
}

return [att]
}

// Log details about the attestation to the GitHub Actions run
const logAttestation = (
attestation: AttestResult,