Skip to content

Commit eac850d

Browse files
authored
feat: wrangler logs (#256)
* feat: wrangler logs * test * fix: table output to html * refactor: use addRaw instead of addTable for wrangler output * refactor: chain summary * refactor: use table * feat: wrangler output to PR comment * refactor: wrangler output use details * feat: wrangler output comment code block * refactor: wrangler output comment * chore: changeset * docs:
1 parent 4048f91 commit eac850d

File tree

14 files changed

+74
-40
lines changed

14 files changed

+74
-40
lines changed

.changeset/cold-wombats-swim.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"github-actions-cloudflare-pages": minor
3+
---
4+
5+
feat: wrangler output shown in summary and PR comment

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ environment:
155155
alias:
156156
description: 'Cloudflare Pages deployed alias. Fallsback to deployed url if deployed alias is null'
157157
value: ${{ steps.action.outputs.alias }}
158+
wrangler:
159+
description: 'Wrangler cli output'
160+
values: ${{ steps.action.outputs.wrangler }}
158161
```
159162

160163
## Comment Example

__mocks__/@unlike/github-actions-core/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ export const notice = vi.fn()
1414
export const debug = vi.fn()
1515
export const isDebug = vi.fn().mockReturnValue(false)
1616
export const setFailed = vi.fn()
17+
export const info = vi.fn()
1718

1819
export const summary = core.summary
1920
summary.addTable = vi.fn().mockReturnValue(summary)
2021
summary.addHeading = vi.fn().mockReturnValue(summary)
2122
summary.addBreak = vi.fn().mockReturnValue(summary)
23+
summary.addRaw = vi.fn().mockReturnValue(summary)
2224
summary.write = vi.fn()

__tests__/cloudflare/deployment/__snapshots__/create.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`createCloudflareDeployment > api calls > handles success 1`] = `
3+
exports[`createCloudflareDeployment > api calls > handles success 2`] = `
44
{
55
"aliases": [
66
"https://unknown-branch.cloudflare-pages-action-a5z.pages.dev",

__tests__/cloudflare/deployment/create.test.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {setOutput, summary} from '@unlike/github-actions-core'
1+
import {info, setOutput, summary} from '@unlike/github-actions-core'
22
import {afterEach, beforeEach, describe, expect, test, vi} from 'vitest'
33

44
import type {MockApi} from '@/tests/helpers/api.js'
@@ -19,6 +19,7 @@ vi.mock('@unlike/github-actions-core')
1919
describe('createCloudflareDeployment', () => {
2020
describe('api calls', () => {
2121
let mockApi: MockApi
22+
2223
beforeEach(() => {
2324
mockApi = setMockApi()
2425
})
@@ -28,8 +29,8 @@ describe('createCloudflareDeployment', () => {
2829
})
2930

3031
test('handles thrown error from wrangler deploy', async () => {
31-
expect.assertions(9)
32-
vi.mocked(execAsync).mockRejectedValue({stderr: 'Oh no!'})
32+
expect.assertions(10)
33+
vi.mocked(execAsync).mockRejectedValue({stderr: 'Oh no!', stdout: ''})
3334

3435
// Expect Cloudflare Api Token and Account Id to be undefined.
3536
expect(process.env[CLOUDFLARE_API_TOKEN]).toBeUndefined()
@@ -51,6 +52,7 @@ describe('createCloudflareDeployment', () => {
5152
)
5253

5354
expect(execAsync).toHaveBeenCalledTimes(1)
55+
expect(info).not.toHaveBeenCalled()
5456
expect(process.env[CLOUDFLARE_API_TOKEN]).toBe(
5557
'mock-cloudflare-api-token'
5658
)
@@ -63,7 +65,7 @@ describe('createCloudflareDeployment', () => {
6365
})
6466

6567
test('handles thrown error from getDeployments', async () => {
66-
expect.assertions(4)
68+
expect.assertions(5)
6769
vi.mocked(execAsync).mockResolvedValue({
6870
stdout: 'success',
6971
stderr: ''
@@ -81,12 +83,13 @@ describe('createCloudflareDeployment', () => {
8183
`[ParseError: A request to the Cloudflare API (https://api.cloudflare.com/client/v4/accounts/mock-cloudflare-account-id/pages/projects/mock-cloudflare-project-name/deployments) failed.]`
8284
)
8385
expect(execAsync).toHaveBeenCalledTimes(1)
86+
expect(info).toHaveBeenLastCalledWith('success')
8487
expect(setOutput).not.toHaveBeenCalled()
8588
expect(summary.addTable).not.toHaveBeenCalled()
8689
})
8790

8891
test('handles success', async () => {
89-
expect.assertions(11)
92+
expect.assertions(14)
9093
vi.mocked(execAsync).mockResolvedValue({
9194
stdout: 'success',
9295
stderr: ''
@@ -106,14 +109,16 @@ describe('createCloudflareDeployment', () => {
106109
200
107110
)
108111

109-
const deployment = await createCloudflareDeployment()
112+
const {deployment, wranglerOutput} = await createCloudflareDeployment()
110113

114+
expect(wranglerOutput).toMatchInlineSnapshot(`"success"`)
111115
expect(deployment).toMatchSnapshot()
112116
expect(deployment.id).toMatchInlineSnapshot(
113117
'"206e215c-33b3-4ce4-adf4-7fc6c9b65483"'
114118
)
119+
expect(info).toHaveBeenLastCalledWith('success')
115120

116-
expect(setOutput).toHaveBeenCalledTimes(4)
121+
expect(setOutput).toHaveBeenCalledTimes(5)
117122
expect(setOutput).toHaveBeenNthCalledWith(
118123
1,
119124
'id',
@@ -130,6 +135,7 @@ describe('createCloudflareDeployment', () => {
130135
'alias',
131136
'https://unknown-branch.cloudflare-pages-action-a5z.pages.dev'
132137
)
138+
expect(setOutput).toHaveBeenNthCalledWith(5, 'wrangler', 'success')
133139

134140
expect(summary.addHeading).toHaveBeenCalledWith(
135141
`Cloudflare Pages Deployment`
@@ -166,7 +172,8 @@ describe('createCloudflareDeployment', () => {
166172
[
167173
'Branch Preview URL:',
168174
`<a href='https://unknown-branch.cloudflare-pages-action-a5z.pages.dev'>https://unknown-branch.cloudflare-pages-action-a5z.pages.dev</a>`
169-
]
175+
],
176+
['Wrangler Output:', `success`]
170177
])
171178
})
172179
})

__tests__/github/comment.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('addComment', () => {
3030
query: MutationAddComment,
3131
variables: {
3232
subjectId: 'MDExOlB1bGxSZXF1ZXN0Mjc5MTQ3NDM3',
33-
body: '## Cloudflare Pages Deployment\n **Environment:** production \n **Project:** cloudflare-pages-action \n **Built with commit:** mock-github-sha\n **Preview URL:** https://206e215c.cloudflare-pages-action-a5z.pages.dev \n **Branch Preview URL:** https://unknown-branch.cloudflare-pages-action-a5z.pages.dev'
33+
body: '## Cloudflare Pages Deployment\n**Environment:** production\n**Project:** cloudflare-pages-action\n**Built with commit:** mock-github-sha\n**Preview URL:** https://206e215c.cloudflare-pages-action-a5z.pages.dev\n**Branch Preview URL:** https://unknown-branch.cloudflare-pages-action-a5z.pages.dev\n\n### Wrangler Output\nsuccess'
3434
}
3535
},
3636
{
@@ -46,7 +46,7 @@ describe('addComment', () => {
4646
}
4747
)
4848

49-
const comment = await addComment(mockData)
49+
const comment = await addComment(mockData, 'success')
5050
expect(comment).toBe('1')
5151
})
5252

@@ -64,7 +64,7 @@ describe('addComment', () => {
6464
payload: {}
6565
} as Readonly<WorkflowEventExtract<typeof eventName>>)
6666

67-
await expect(addComment(mockData)).resolves.toBeUndefined()
67+
await expect(addComment(mockData, 'success')).resolves.toBeUndefined()
6868
}
6969
)
7070
})

__tests__/main.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {MockApi} from '@/tests/helpers/api.js'
66
import RESPONSE_DEPLOYMENTS from '@/responses/api.cloudflare.com/pages/deployments/deployments.response.json'
77
import RESPONSE_PROJECT from '@/responses/api.cloudflare.com/pages/projects/project.response.json'
88
import {run} from '@/src/main.js'
9+
import {execAsync} from '@/src/utils.js'
910
import {
1011
MOCK_API_PATH,
1112
MOCK_API_PATH_DEPLOYMENTS,
@@ -34,6 +35,10 @@ describe('main', () => {
3435
describe('run', () => {
3536
describe('handles resolve', () => {
3637
beforeEach(() => {
38+
vi.mocked(execAsync).mockResolvedValue({
39+
stdout: 'success',
40+
stderr: ''
41+
})
3742
mockApi.interceptCloudflare(MOCK_API_PATH, RESPONSE_PROJECT, 200)
3843
mockApi.interceptCloudflare(
3944
MOCK_API_PATH_DEPLOYMENTS,
@@ -49,7 +54,7 @@ describe('main', () => {
4954

5055
expect(main).toBeUndefined()
5156

52-
expect(spySetOutput).toHaveBeenCalledTimes(4)
57+
expect(spySetOutput).toHaveBeenCalledTimes(5)
5358
// TODO @andykenward add checks for setOutput
5459
mockApi.mockAgent.assertNoPendingInterceptors()
5560
})

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ outputs:
3434
description: 'Cloudflare Pages deployed environment "production" or "preview"'
3535
alias:
3636
description: 'Cloudflare Pages deployed alias. Fallsback to deployed url if deployed alias is null'
37+
wrangler:
38+
description: 'Wrangler cli output'
3739

3840
runs:
3941
using: node20

dist/index.js

Lines changed: 11 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)