Skip to content

Commit

Permalink
Merge pull request #1725 from actions/bdehamer/attest-retry-persist
Browse files Browse the repository at this point in the history
(@actions/attest) retry request on failure to save attestation
  • Loading branch information
bdehamer committed Apr 25, 2024
2 parents 29885a8 + 0e8fe8a commit 81a73ab
Show file tree
Hide file tree
Showing 5 changed files with 280 additions and 54 deletions.
4 changes: 4 additions & 0 deletions packages/attest/RELEASES.md
@@ -1,5 +1,9 @@
# @actions/attest Releases

### 1.2.1

- Retry request on attestation persistence failure

### 1.2.0

- Generate attestations using the v0.3 Sigstore bundle format.
Expand Down
34 changes: 33 additions & 1 deletion packages/attest/__tests__/store.test.ts
Expand Up @@ -52,7 +52,39 @@ describe('writeAttestation', () => {
})

it('throws an error', async () => {
await expect(writeAttestation(attestation, token)).rejects.toThrow(/oops/)
await expect(
writeAttestation(attestation, token, {retry: 0})
).rejects.toThrow(/oops/)
})
})

describe('when the api call fails but succeeds on retry', () => {
beforeEach(() => {
const pool = mockAgent.get('https://api.github.com')

pool
.intercept({
path: '/repos/foo/bar/attestations',
method: 'POST',
headers: {authorization: `token ${token}`},
body: JSON.stringify({bundle: attestation})
})
.reply(500, 'oops')
.times(1)

pool
.intercept({
path: '/repos/foo/bar/attestations',
method: 'POST',
headers: {authorization: `token ${token}`},
body: JSON.stringify({bundle: attestation})
})
.reply(201, {id: '123'})
.times(1)
})

it('persists the attestation', async () => {
await expect(writeAttestation(attestation, token)).resolves.toEqual('123')
})
})
})

0 comments on commit 81a73ab

Please sign in to comment.