Skip to content

Commit

Permalink
feat: input wrangler-version
Browse files Browse the repository at this point in the history
  • Loading branch information
andykenward committed Sep 15, 2024
1 parent 2be9de7 commit 7c27466
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-queens-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'github-actions-cloudflare-pages': patch
---

feat: input of wrangler-version to override default version of wrangler used to deploy to cloudflare
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ github-environment:
working-directory:
description: 'Directory to run wrangler cli from'
required: false
wrangler-version:
description: 'Override default wrangler version to use'
required: false
```

## Outputs
Expand Down
4 changes: 2 additions & 2 deletions __tests__/common/cloudflare/deployment/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('createCloudflareDeployment', () => {
).rejects.toThrowErrorMatchingInlineSnapshot(`[Error: Oh no!]`)

expect(execAsync).toHaveBeenCalledWith(
`npx wrangler@${process.env.npm_package_dependencies_wrangler} pages deploy mock-directory --project-name=mock-cloudflare-project-name --branch=mock-github-head-ref --commit-dirty=true --commit-hash=mock-github-sha`,
`npx wrangler@^3.73.0 pages deploy mock-directory --project-name=mock-cloudflare-project-name --branch=mock-github-head-ref --commit-dirty=true --commit-hash=mock-github-sha`,
{
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
env: expect.objectContaining({
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('createCloudflareDeployment', () => {
// vi.advanceTimersByTime(2000)

expect(execAsync).toHaveBeenCalledWith(
`npx wrangler@${process.env.npm_package_dependencies_wrangler} pages deploy mock-directory --project-name=mock-cloudflare-project-name --branch=mock-github-head-ref --commit-dirty=true --commit-hash=mock-github-sha`,
`npx wrangler@^3.73.0 pages deploy mock-directory --project-name=mock-cloudflare-project-name --branch=mock-github-head-ref --commit-dirty=true --commit-hash=mock-github-sha`,
{
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
env: expect.objectContaining({
Expand Down
25 changes: 22 additions & 3 deletions __tests__/common/inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {stubInputEnv} from '@/tests/helpers/inputs.js'
import {
INPUT_KEY_CLOUDFLARE_API_TOKEN,
INPUT_KEY_GITHUB_ENVIRONMENT,
INPUT_KEY_GITHUB_TOKEN
INPUT_KEY_GITHUB_TOKEN,
INPUT_KEY_WRANGLER_VERSION
} from '@/input-keys'

const setup = async () => {
Expand Down Expand Up @@ -45,13 +46,15 @@ describe('common', () => {
stubInputEnv(INPUT_KEY_CLOUDFLARE_API_TOKEN)
stubInputEnv(INPUT_KEY_GITHUB_TOKEN)
stubInputEnv(INPUT_KEY_GITHUB_ENVIRONMENT)
stubInputEnv(INPUT_KEY_WRANGLER_VERSION)

const {useCommonInputs} = await setup()

expect(useCommonInputs()).toStrictEqual({
cloudflareApiToken: 'mock-cloudflare-api-token',
gitHubApiToken: 'mock-github-token',
gitHubEnvironment: 'mock-github-environment'
gitHubEnvironment: 'mock-github-environment',
wranglerVersion: 'mock-wrangler-version'
})
})

Expand All @@ -66,8 +69,24 @@ describe('common', () => {
expect(useCommonInputs()).toStrictEqual({
cloudflareApiToken: 'mock-cloudflare-api-token',
gitHubApiToken: 'mock-github-token',
gitHubEnvironment: undefined
gitHubEnvironment: undefined,
wranglerVersion: '^3.73.0'
})
})

test('returns default wranger version', async () => {
expect.assertions(1)

stubInputEnv(INPUT_KEY_CLOUDFLARE_API_TOKEN)
stubInputEnv(INPUT_KEY_GITHUB_TOKEN)

const {useCommonInputs} = await setup()

expect(useCommonInputs()).toStrictEqual(
expect.objectContaining({
wranglerVersion: '^3.73.0'
})
)
})
})
})
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ inputs:
working-directory:
description: 'Directory to run wrangler cli from'
required: false
wrangler-version:
description: 'Wrangler version to use'
required: false

outputs:
id:
Expand Down
2 changes: 1 addition & 1 deletion dist/delete/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

1 comment on commit 7c27466

@chalkygames123
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andykenward Thank you, Andy! I just needed this option as I tried the nodejs_compat_v2 compatibility flag in a project within a monorepo and encountered an error due to a Wrangler version mismatch.

Please sign in to comment.