Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/octokit-0a734cd80b
Browse files Browse the repository at this point in the history
  • Loading branch information
andykenward authored Jun 23, 2024
2 parents 7f2a24d + 6844148 commit 6816f2d
Show file tree
Hide file tree
Showing 22 changed files with 223 additions and 127 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-experts-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'github-actions-cloudflare-pages': patch
---

chore(deps): bump wrangler from 3.53.1 to 3.61.0
5 changes: 5 additions & 0 deletions .changeset/thick-cups-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'github-actions-cloudflare-pages': patch
---

test: remove need for checking process.env in test environment.
2 changes: 1 addition & 1 deletion .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 #v4.1.6
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7
- uses: andykenward/github-actions/setup-pnpm@74ca078e70cb5bfc9f6c33afc3b63a66f050311f #v1.0.1
with:
node-version: 20
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
language: ['javascript-typescript']
steps:
- name: Checkout repository
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 #v4.1.6
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-delete.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 #v4.1.6
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7
- id: 'cloudflare-pages'
uses: ./delete
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 #v4.1.6
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7
- id: 'cloudflare-pages'
uses: ./
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
id-token: write
timeout-minutes: 5
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 #v4.1.6
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7
- uses: andykenward/github-actions/setup-pnpm@74ca078e70cb5bfc9f6c33afc3b63a66f050311f #v1.0.1
with:
node-version: 20
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 #v4.1.6
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7
- uses: andykenward/github-actions/setup-pnpm@74ca078e70cb5bfc9f6c33afc3b63a66f050311f #v1.0.1
with:
node-version: 20
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 #v4.1.6
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7
- uses: andykenward/github-actions/setup-pnpm@74ca078e70cb5bfc9f6c33afc3b63a66f050311f #v1.0.1
with:
node-version: 20
Expand All @@ -27,7 +27,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@6d6857d36972b65feb161a90e484f2984215f83e #v6.0.5
uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c #v6.1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore: update payloads'
Expand All @@ -43,15 +43,15 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 #v4.1.6
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7
- uses: andykenward/github-actions/setup-pnpm@74ca078e70cb5bfc9f6c33afc3b63a66f050311f #v1.0.1
with:
node-version: 20
- name: cli all
run: pnpm run tsc:types
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@6d6857d36972b65feb161a90e484f2984215f83e #v6.0.5
uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c #v6.1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore: update types'
Expand Down
6 changes: 6 additions & 0 deletions __tests__/common/cloudflare/deployment/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ describe('createCloudflareDeployment', () => {
let mockApi: MockApi

beforeEach(() => {
vi.useFakeTimers({
shouldAdvanceTime: true
})
mockApi = setMockApi()
})
afterEach(async () => {
mockApi.mockAgent.assertNoPendingInterceptors()
await mockApi.mockAgent.close()
vi.mocked(execAsync).mockReset()
vi.runOnlyPendingTimers()
vi.useRealTimers()
})

test('handles thrown error from wrangler deploy', async () => {
Expand Down Expand Up @@ -130,6 +135,7 @@ describe('createCloudflareDeployment', () => {
directory: 'mock-directory',
workingDirectory: 'mock-working-directory'
})
// 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`,
Expand Down
12 changes: 8 additions & 4 deletions __tests__/common/github/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import {describe, expect, test} from 'vitest'

import {useContext} from '@/common/github/context.js'
import {beforeEach, describe, expect, test, vi} from 'vitest'

describe('getGitHubContext', () => {
test('returns eventName ', () => {
beforeEach(() => {
vi.resetModules()
})

test('returns eventName ', async () => {
expect.assertions(8)

const {useContext} = await import('@/common/github/context.js')

const {repo, event, branch, sha, graphqlEndpoint, ref} = useContext()

/** Repo */
Expand Down
45 changes: 22 additions & 23 deletions __tests__/common/inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@ import {beforeEach, describe, expect, test, vi} from 'vitest'

import {stubInputEnv} from '@/tests/helpers/inputs.js'

import {useCommonInputs} from '@/common/inputs.js'
import {
INPUT_KEY_CLOUDFLARE_API_TOKEN,
INPUT_KEY_GITHUB_ENVIRONMENT,
INPUT_KEY_GITHUB_TOKEN
} from '@/input-keys'

const setup = async () => {
return await import('@/common/inputs.js')
}

describe('common', () => {
describe('inputs', () => {
beforeEach(() => {
vi.resetModules()
vi.unstubAllEnvs()
})

test('should error when missing inputs', () => {
test('should error when missing inputs', async () => {
expect.assertions(3)
const {useCommonInputs} = await setup()

expect(() => useCommonInputs()).toThrow(
/input required and not supplied: cloudflare-api-token/i
Expand All @@ -31,40 +36,34 @@ describe('common', () => {
expect(() => useCommonInputs()).not.toThrow()
})

test('returns correct values', () => {
test('returns correct values', async () => {
expect.assertions(1)

stubInputEnv(INPUT_KEY_CLOUDFLARE_API_TOKEN)
stubInputEnv(INPUT_KEY_GITHUB_TOKEN)
stubInputEnv(INPUT_KEY_GITHUB_ENVIRONMENT)

const inputs = useCommonInputs()
const {useCommonInputs} = await setup()

expect(inputs).toMatchInlineSnapshot(`
{
"cloudflareApiToken": "mock-cloudflare-api-token",
"gitHubApiToken": "mock-github-token",
"gitHubEnvironment": "mock-github-environment",
}
`)
expect(useCommonInputs()).toStrictEqual({
cloudflareApiToken: 'mock-cloudflare-api-token',
gitHubApiToken: 'mock-github-token',
gitHubEnvironment: 'mock-github-environment'
})
})

test(`returns undefined for optional ${INPUT_KEY_GITHUB_ENVIRONMENT}`, () => {
expect.assertions(2)
test(`returns undefined for optional ${INPUT_KEY_GITHUB_ENVIRONMENT}`, async () => {
expect.assertions(1)
stubInputEnv(INPUT_KEY_CLOUDFLARE_API_TOKEN)
stubInputEnv(INPUT_KEY_GITHUB_TOKEN)

const inputs = useCommonInputs()

expect(inputs.gitHubEnvironment).toBeUndefined()
const {useCommonInputs} = await setup()

expect(inputs).toMatchInlineSnapshot(`
{
"cloudflareApiToken": "mock-cloudflare-api-token",
"gitHubApiToken": "mock-github-token",
"gitHubEnvironment": undefined,
}
`)
expect(useCommonInputs()).toStrictEqual({
cloudflareApiToken: 'mock-cloudflare-api-token',
gitHubApiToken: 'mock-github-token',
gitHubEnvironment: undefined
})
})
})
})
32 changes: 20 additions & 12 deletions __tests__/deploy/inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,36 @@ import {beforeEach, describe, expect, test, vi} from 'vitest'

import {stubRequiredInputEnv} from '@/tests/helpers/inputs.js'

import {useInputs} from '@/deploy/inputs.js'

const setup = async () => {
return await import('@/deploy/inputs.js')
}
describe('deploy', () => {
describe('inputs', () => {
beforeEach(() => {
vi.resetModules()
vi.unstubAllEnvs()
})

test('returns correct values', () => {
test('returns correct values', async () => {
expect.assertions(1)

stubRequiredInputEnv()
const inputs = useInputs()
const {useInputs} = await setup()

expect(useInputs()).toStrictEqual({
cloudflareAccountId: 'mock-cloudflare-account-id',
cloudflareProjectName: 'mock-cloudflare-project-name',
directory: 'mock-directory',
workingDirectory: '.'
})
})

expect(inputs).toMatchInlineSnapshot(`
{
"cloudflareAccountId": "mock-cloudflare-account-id",
"cloudflareProjectName": "mock-cloudflare-project-name",
"directory": "mock-directory",
"workingDirectory": ".",
}
`)
test('throws error', async () => {
expect.assertions(1)
const {useInputs} = await setup()
expect(() => useInputs()).toThrow(
'Input required and not supplied: cloudflare-account-id'
)
})
})
})
Loading

0 comments on commit 6816f2d

Please sign in to comment.