Skip to content
Draft
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
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,19 @@ permissions:

## Inputs

| Input | Required | Description |
| ------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `cloudflare-api-token` | yes | Cloudflare API Token |
| `cloudflare-account-id` | yes | Cloudflare Account ID |
| `cloudflare-project-name` | yes | Cloudflare Pages project to upload to |
| `directory` | yes | Directory of static files to upload |
| `github-token` | yes | Github API key, make sure to add the required permissions for this action. |
| `github-environment` | yes | GitHub environment to deploy to. You need to manually create this for the github repo |
| `pr-number` | no | GitHub pull request number to comment on. If not set, the action auto-detects from the event payload. |
| `working-directory` | no | Directory to run wrangler cli from |
| `wrangler-version` | no | Wrangler version to use. Otherwise a default version from the action will be used. |
| `branch` | no | Branch name to use for Cloudflare Pages deployment. If not set, the branch is automatically detected from the GitHub context. |
| Input | Required | Description |
| ---------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `cloudflare-api-token` | yes | Cloudflare API Token |
| `cloudflare-account-id` | yes | Cloudflare Account ID |
| `cloudflare-project-name` | yes | Cloudflare Pages project to upload to |
| `directory` | yes | Directory of static files to upload |
| `github-token` | yes | Github API key, make sure to add the required permissions for this action. |
| `github-environment` | yes | GitHub environment to deploy to. You need to manually create this for the github repo |
| `pr-number` | no | GitHub pull request number to comment on. If not set, the action auto-detects from the event payload. |
| `working-directory` | no | Directory to run wrangler cli from |
| `wrangler-version` | no | Wrangler version to use. Otherwise a default version from the action will be used. |
| `branch` | no | Branch name to use for Cloudflare Pages deployment. If not set, the branch is automatically detected from the GitHub context. |
| `comment-disable-wrangler-output` | no | Disable the Wrangler CLI output in the GitHub comment. Set to `true` to hide Wrangler output from PR comments. |

## Outputs

Expand Down
4 changes: 4 additions & 0 deletions __mocks__/@actions/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export const getInput = vi.fn<typeof core.getInput>((name: string, options) =>
core.getInput(name, options)
)

export const getBooleanInput = vi.fn<typeof core.getBooleanInput>(
(name: string, options) => core.getBooleanInput(name, options)
)

export const setOutput = vi.fn()

export const error = vi.fn()
Expand Down
6 changes: 4 additions & 2 deletions __tests__/common/github/comment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ describe(addComment, () => {
gitHubApiToken: 'mock-github-token',
gitHubEnvironment: undefined,
prNumber: '123',
wranglerVersion: 'mock-wrangler-version'
wranglerVersion: 'mock-wrangler-version',
commentDisableWranglerOutput: false
})

vi.spyOn(Context, 'useContextEvent').mockReturnValue({
Expand Down Expand Up @@ -295,7 +296,8 @@ describe(addComment, () => {
gitHubApiToken: 'mock-github-token',
gitHubEnvironment: undefined,
prNumber: 'abc',
wranglerVersion: 'mock-wrangler-version'
wranglerVersion: 'mock-wrangler-version',
commentDisableWranglerOutput: false
})

await expect(addComment(mockData, 'success')).rejects.toThrow(
Expand Down
39 changes: 37 additions & 2 deletions __tests__/common/inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {beforeEach, describe, expect, test, vi} from 'vitest'

import {
INPUT_KEY_CLOUDFLARE_API_TOKEN,
INPUT_KEY_COMMENT_DISABLE_WRANGLER_OUTPUT,
INPUT_KEY_GITHUB_ENVIRONMENT,
INPUT_KEY_GITHUB_TOKEN,
INPUT_KEY_WRANGLER_VERSION
Expand Down Expand Up @@ -56,7 +57,8 @@ describe('common', () => {
gitHubApiToken: 'mock-github-token',
gitHubEnvironment: 'mock-github-environment',
prNumber: undefined,
wranglerVersion: 'mock-wrangler-version'
wranglerVersion: 'mock-wrangler-version',
commentDisableWranglerOutput: false
})
})

Expand All @@ -73,7 +75,8 @@ describe('common', () => {
gitHubApiToken: 'mock-github-token',
gitHubEnvironment: undefined,
prNumber: undefined,
wranglerVersion: packageJson.devDependencies.wrangler
wranglerVersion: packageJson.devDependencies.wrangler,
commentDisableWranglerOutput: false
})
})

Expand All @@ -91,5 +94,37 @@ describe('common', () => {
})
)
})

test('returns true when comment-disable-wrangler-output is set', async () => {
expect.assertions(1)

stubInputEnv(INPUT_KEY_CLOUDFLARE_API_TOKEN)
stubInputEnv(INPUT_KEY_GITHUB_TOKEN)
stubInputEnv(INPUT_KEY_COMMENT_DISABLE_WRANGLER_OUTPUT, 'true')

const {useCommonInputs} = await setup()

expect(useCommonInputs()).toStrictEqual(
expect.objectContaining({
commentDisableWranglerOutput: true
})
)
})

test('returns false when comment-disable-wrangler-output is not set', async () => {
expect.assertions(1)

stubInputEnv(INPUT_KEY_CLOUDFLARE_API_TOKEN)
stubInputEnv(INPUT_KEY_GITHUB_TOKEN)
stubInputEnv(INPUT_KEY_COMMENT_DISABLE_WRANGLER_OUTPUT, 'false')

const {useCommonInputs} = await setup()

expect(useCommonInputs()).toStrictEqual(
expect.objectContaining({
commentDisableWranglerOutput: false
})
)
})
})
})
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ inputs:
branch:
description: 'Branch name to use for Cloudflare Pages deployment. If not set, the branch is automatically detected from the GitHub context.'
required: false
comment-disable-wrangler-output:
description: 'Disable the Wrangler CLI output in the GitHub comment. If set to true, the Wrangler output will not be included in the PR comment.'
required: false

outputs:
id:
Expand Down
Loading