Skip to content

Commit 28b7ba8

Browse files
committed
refactor: ci & inputs
1 parent 52f8385 commit 28b7ba8

File tree

18 files changed

+134
-107
lines changed

18 files changed

+134
-107
lines changed

.github/workflows/check-dist.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# `index.js` is the code that will run.
66
# For our project, we generate this file through a build process from other source files.
77
# We need to make sure the checked-in `index.js` actually matches what we expect it to be.
8-
name: Check dist/
8+
name: check dist
99

1010
on:
1111
push:
@@ -14,6 +14,8 @@ on:
1414
paths-ignore:
1515
- '**.md'
1616
pull_request:
17+
branches:
18+
- main
1719
paths-ignore:
1820
- '**.md'
1921
workflow_dispatch:
@@ -27,10 +29,10 @@ jobs:
2729
runs-on: ubuntu-latest
2830
timeout-minutes: 5
2931
steps:
30-
- uses: actions/checkout@v3.5.2
32+
- uses: actions/checkout@v3.5.3
3133
- uses: unlike-ltd/github-actions/setup-pnpm@v0.0.2
3234
with:
33-
node-version: 18.x
35+
node-version: 18
3436
- name: Rebuild the dist/ directory
3537
run: pnpm run build
3638

Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
22

3-
name: 'delete deployments'
3+
name: deploy delete
44
on:
55
pull_request:
6-
types: [closed]
6+
types:
7+
- closed
78
branches:
89
- main
9-
- 'releases/*'
1010

1111
jobs:
12-
delete:
12+
cloudflare-pages-deploy-delete:
1313
permissions:
1414
contents: read
1515
deployments: write
1616
pull-requests: write
1717
runs-on: ubuntu-latest
1818
timeout-minutes: 5
1919
steps:
20-
- uses: actions/checkout@v3.5.2
21-
- id: 'our-action'
20+
- uses: actions/checkout@v3.5.3
21+
- id: 'cloudflare-pages'
2222
uses: ./
2323
with:
24-
api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
25-
account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
26-
project-name: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
24+
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
25+
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
26+
cloudflare-project-name: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
2727
directory: 'example/dist'
2828
github-token: ${{ secrets.GITHUB_TOKEN }}
2929
github-environment: 'preview'

.github/workflows/deploy.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
3+
name: deploy
4+
on:
5+
pull_request:
6+
branches:
7+
- main
8+
push:
9+
branches:
10+
- main
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
15+
jobs:
16+
cloudflare-pages-deploy:
17+
permissions:
18+
contents: read
19+
deployments: write
20+
pull-requests: write
21+
runs-on: ubuntu-latest
22+
timeout-minutes: 5
23+
steps:
24+
- uses: actions/checkout@v3.5.3
25+
- id: 'cloudflare-pages'
26+
uses: ./
27+
with:
28+
cloudflare-api-token: ${{secrets.CLOUDFLARE_API_TOKEN}}
29+
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
30+
cloudflare-project-name: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
31+
directory: 'example/dist'
32+
github-token: ${{ secrets.GITHUB_TOKEN }}
33+
github-environment: 'preview'

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Setup Node.js Pnpm & install dependencies
2525
uses: unlike-ltd/github-actions/setup-pnpm@v0.0.2
2626
with:
27-
node-version: 18.x
27+
node-version: 18
2828
- name: Create Release Pull Request
2929
id: changesets
3030
uses: changesets/action@v1.4.5

.github/workflows/test.yml

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
name: test
44
on:
55
pull_request:
6+
branches:
7+
- main
68
push:
79
branches:
810
- main
9-
- 'releases/*'
1011

1112
concurrency:
1213
group: ${{ github.workflow }}-${{ github.ref }}
@@ -17,29 +18,11 @@ jobs:
1718
runs-on: ubuntu-latest
1819
timeout-minutes: 5
1920
steps:
20-
- uses: actions/checkout@v3.5.2
21+
- uses: actions/checkout@v3.5.3
2122
- uses: unlike-ltd/github-actions/setup-pnpm@v0.0.2
2223
with:
23-
node-version: 18.x
24+
node-version: 18
2425
- name: Lint
2526
run: pnpm run lint
2627
- name: Test
2728
run: pnpm run test
28-
action:
29-
permissions:
30-
contents: read
31-
deployments: write
32-
pull-requests: write
33-
runs-on: ubuntu-latest
34-
timeout-minutes: 5
35-
steps:
36-
- uses: actions/checkout@v3.5.2
37-
- id: 'our-action'
38-
uses: ./
39-
with:
40-
api-token: ${{secrets.CLOUDFLARE_API_TOKEN}}
41-
account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
42-
project-name: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
43-
directory: 'example/dist'
44-
github-token: ${{ secrets.GITHUB_TOKEN }}
45-
github-environment: 'preview'

__tests__/cloudflare/api/endpoints.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import {describe, expect, test} from 'vitest'
22

33
import {getCloudflareApiEndpoint} from '@/src/cloudflare/api/endpoints.js'
44
import {
5-
ACTION_INPUT_ACCOUNT_ID,
6-
ACTION_INPUT_PROJECT_NAME
5+
ACTION_INPUT_CLOUDFLARE_ACCOUNT_ID,
6+
ACTION_INPUT_CLOUDFLARE_PROJECT_NAME
77
} from '@/src/constants.js'
88
import {stubInputEnv} from '@/tests/helpers/inputs.js'
99

1010
describe('getCloudflareApiEndpoint', () => {
1111
test('returns correct url', () => {
12-
stubInputEnv(ACTION_INPUT_ACCOUNT_ID, 'mock-account-id')
13-
stubInputEnv(ACTION_INPUT_PROJECT_NAME, 'mock-project-name')
12+
stubInputEnv(ACTION_INPUT_CLOUDFLARE_ACCOUNT_ID, 'mock-account-id')
13+
stubInputEnv(ACTION_INPUT_CLOUDFLARE_PROJECT_NAME, 'mock-project-name')
1414

1515
const url = getCloudflareApiEndpoint()
1616

@@ -20,8 +20,8 @@ describe('getCloudflareApiEndpoint', () => {
2020
})
2121

2222
test('appends path argument', () => {
23-
stubInputEnv(ACTION_INPUT_ACCOUNT_ID, 'mock-account-id')
24-
stubInputEnv(ACTION_INPUT_PROJECT_NAME, 'mock-project-name')
23+
stubInputEnv(ACTION_INPUT_CLOUDFLARE_ACCOUNT_ID, 'mock-account-id')
24+
stubInputEnv(ACTION_INPUT_CLOUDFLARE_PROJECT_NAME, 'mock-project-name')
2525

2626
const url = getCloudflareApiEndpoint('mock-deployment')
2727

@@ -38,14 +38,14 @@ describe('getCloudflareApiEndpoint', () => {
3838

3939
test.each([
4040
{
41-
input: ACTION_INPUT_ACCOUNT_ID,
41+
input: ACTION_INPUT_CLOUDFLARE_ACCOUNT_ID,
4242
value: 'mock-account-id',
43-
expected: ACTION_INPUT_PROJECT_NAME
43+
expected: ACTION_INPUT_CLOUDFLARE_PROJECT_NAME
4444
},
4545
{
46-
input: ACTION_INPUT_PROJECT_NAME,
46+
input: ACTION_INPUT_CLOUDFLARE_PROJECT_NAME,
4747
value: 'mock-project-id',
48-
expected: ACTION_INPUT_ACCOUNT_ID
48+
expected: ACTION_INPUT_CLOUDFLARE_ACCOUNT_ID
4949
}
5050
])(
5151
`$input with $value throws error $expected`,

__tests__/cloudflare/api/fetch-result.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import RESPONSE_NOT_FOUND from '@/responses/api.cloudflare.com/pages/projects/pr
66
import RESPONSE_OK from '@/responses/api.cloudflare.com/pages/projects/project.response.json'
77
import RESPONSE_UNAUTHORIZED from '@/responses/api.cloudflare.com/unauthorized.response.json'
88
import {fetchResult} from '@/src/cloudflare/api/fetch-result.js'
9-
import {ACTION_INPUT_API_TOKEN} from '@/src/constants.js'
9+
import {ACTION_INPUT_CLOUDFLARE_API_TOKEN} from '@/src/constants.js'
1010
import {getMockApi, stubRequiredInputEnv} from '@/tests/helpers/index.js'
1111

1212
const RESOURCE_URL_DOMAIN = `https://api.cloudflare.com`
@@ -28,12 +28,12 @@ describe('api', () => {
2828
await mockApi.mockAgent.close()
2929
})
3030

31-
test(`throws error if ${ACTION_INPUT_API_TOKEN} undefined`, async () => {
31+
test(`throws error if ${ACTION_INPUT_CLOUDFLARE_API_TOKEN} undefined`, async () => {
3232
vi.unstubAllEnvs()
3333
await expect(
3434
fetchResult(RESOURCE_URL)
3535
).rejects.toThrowErrorMatchingInlineSnapshot(
36-
'"Input required and not supplied: api token"'
36+
'"Input required and not supplied: cloudflare api token"'
3737
)
3838
})
3939

__tests__/cloudflare/deployments.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,16 @@ describe('deployments', () => {
8686
''
8787
],
8888
'mock-directory',
89-
'mock-project-name',
89+
'mock-cloudflare-project-name',
9090
'mock-github-head-ref',
9191
'mock-github-sha'
9292
)
9393
expect(execa.$).toHaveBeenCalledTimes(1)
9494
expect(process.env[CLOUDFLARE_API_TOKEN]).toStrictEqual(
95-
'mock-api-token'
95+
'mock-cloudflare-api-token'
9696
)
9797
expect(process.env[CLOUDFLARE_ACCOUNT_ID]).toStrictEqual(
98-
'mock-account-id'
98+
'mock-cloudflare-account-id'
9999
)
100100
expect(setOutput).not.toHaveBeenCalled()
101101
expect(summary.addTable).not.toHaveBeenCalled()
@@ -124,7 +124,7 @@ describe('deployments', () => {
124124
await expect(
125125
createDeployment()
126126
).rejects.toThrowErrorMatchingInlineSnapshot(
127-
'"A request to the Cloudflare API (https://api.cloudflare.com/client/v4/accounts/mock-account-id/pages/projects/mock-project-name/deployments) failed."'
127+
'"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."'
128128
)
129129
expect(execa.$).toHaveBeenCalledTimes(1)
130130
expect(setOutput).not.toHaveBeenCalled()

__tests__/helpers/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ export const getMockApi = () => {
5656
}
5757
export type MockApi = ReturnType<typeof getMockApi>
5858

59-
const MOCK_ACCOUNT_ID = 'mock-account-id'
60-
const MOCK_PROJECT_NAME = 'mock-project-name'
59+
const MOCK_ACCOUNT_ID = 'mock-cloudflare-account-id'
60+
const MOCK_PROJECT_NAME = 'mock-cloudflare-project-name'
6161

6262
export const MOCK_API_PATH = `/client/v4/accounts/${MOCK_ACCOUNT_ID}/pages/projects/${MOCK_PROJECT_NAME}`
6363
export const MOCK_API_PATH_DEPLOYMENTS = `${MOCK_API_PATH}/deployments`

__tests__/helpers/inputs.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import {vi} from 'vitest'
22

33
import {
4-
ACTION_INPUT_ACCOUNT_ID,
5-
ACTION_INPUT_API_TOKEN,
4+
ACTION_INPUT_CLOUDFLARE_ACCOUNT_ID,
5+
ACTION_INPUT_CLOUDFLARE_API_TOKEN,
6+
ACTION_INPUT_CLOUDFLARE_PROJECT_NAME,
67
ACTION_INPUT_DIRECTORY,
78
ACTION_INPUT_GITHUB_ENVIRONMENT,
8-
ACTION_INPUT_GITHUB_TOKEN,
9-
ACTION_INPUT_PROJECT_NAME
9+
ACTION_INPUT_GITHUB_TOKEN
1010
} from '@/src/constants.js'
1111

1212
const INPUT_KEY = `INPUT_`
1313

1414
export const REQUIRED_INPUTS = [
15-
ACTION_INPUT_ACCOUNT_ID,
16-
ACTION_INPUT_PROJECT_NAME,
15+
ACTION_INPUT_CLOUDFLARE_ACCOUNT_ID,
16+
ACTION_INPUT_CLOUDFLARE_PROJECT_NAME,
1717
ACTION_INPUT_DIRECTORY,
18-
ACTION_INPUT_API_TOKEN,
18+
ACTION_INPUT_CLOUDFLARE_API_TOKEN,
1919
ACTION_INPUT_GITHUB_TOKEN,
2020
ACTION_INPUT_GITHUB_ENVIRONMENT
2121
] as const

0 commit comments

Comments
 (0)