Skip to content

Commit 824753d

Browse files
authored
feat: sub-action delete (#291)
* refactor: output index to deploy folder * fix: ci deploy * chore: vscode task watch * feat: new alias setup * chore: prettier ordering * refactor: deploy action * feat: action delete * docs: update main readme * fix: delete action * docs: delete action description * feat(delete): batch delection with promise all * ci(delete): workflow_dispatch * ci(delete): remove push event * chore(deps-dev): bump @tsconfig/node20 from 20.1.2 to 20.1.4 * refactor: use alias @/input-keys * chore(eslint): enable @typescript-eslint/consistent-type-imports * chore: .env.example cloudflare * chore(deps-dev): bump eslint-plugin-vitest to 0.4.1 * chore: build output * refactor(delete): batch-delete file * test: __fixtures__ * test: api intercept support different method * test: mock warning for github-actions-core * feat: batchDelete return object values to output * feat: delete output deletion to summary * chore: build * refactor: delete summary output format * ci: INPUT_KEY_CLOUDFLARE_ACCOUNT_ID from secret to var * docs: update delete README * docs: payload example * refactor: delete summary use emoji for success * chore: build * docs: upgrading * chore: changeset
1 parent 3b8cb59 commit 824753d

File tree

91 files changed

+1853
-812
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1853
-812
lines changed

.changeset/flat-ladybugs-smoke.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"github-actions-cloudflare-pages": major
3+
---
4+
- **BREAKING CHANGES:** use the sub-action `unlike-ltd/github-actions-cloudflare-pages/delete` to delete deployments. The main action `unlike-ltd/github-actions-cloudflare-pages` no longer deletes any deployments.
5+
- **BREAKING CHANGES:** new payload format saved to the GitHub deployments to allow for the sub-action `unlike-ltd/github-actions-cloudflare-pages/delete` to work. To support the older payload the action inputs of `cloudflare-account-id` & `cloudflare_project_name` are required. If an older payload is found and the action inputs are missing, it will silently error and continue; but output in the job summary the deployment.
6+

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ GITHUB_EVENT_NAME=pull_request
55
GITHUB_REPOSITORY='unlike-ltd/cloudflare-pages-action'
66
GITHUB_EVENT_PATH= file:///workspaces/cloudflare-pages-action/payload-examples/api.github.com/pull_request/opened.payload.json
77
GITHUB_GRAPHQL_URL= 'https://api.github.com/graphql'
8+
CLOUDFLARE_ACCOUNT_ID=
9+
CLOUDFLARE_API_TOKEN=

.eslintrc.cjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,17 @@ const config = {
4646
rules: {
4747
'@typescript-eslint/no-var-requires': 'off'
4848
}
49+
},
50+
{
51+
files: ['__fixtures__/**'],
52+
rules: {
53+
'unicorn/no-null': 'off',
54+
'unicorn/numeric-separators-style': 'off'
55+
}
4956
}
5057
],
5158
rules: {
59+
'@typescript-eslint/consistent-type-imports': 'error',
5260
'unicorn/prefer-top-level-await': 'off',
5361
'unicorn/prevent-abbreviations': 'off',
5462
'no-console': 'error'

.github/workflows/deploy-delete.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ on:
88
branches:
99
- main
1010
workflow_dispatch:
11-
inputs:
12-
environment:
13-
description: 'Environment to run action against'
14-
type: environment
15-
required: false
1611

1712
concurrency:
1813
group: deploy-delete-${{ github.head_ref || github.run_id }}
@@ -29,11 +24,7 @@ jobs:
2924
steps:
3025
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 #v4.1.2
3126
- id: 'cloudflare-pages'
32-
uses: ./
27+
uses: ./delete
3328
with:
3429
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
35-
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
36-
cloudflare-project-name: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
37-
directory: 'example/dist'
3830
github-token: ${{ secrets.GITHUB_TOKEN }}
39-
github-environment: ${{ inputs.environment || 'preview' }}

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
uses: ./
3434
with:
3535
cloudflare-api-token: ${{secrets.CLOUDFLARE_API_TOKEN}}
36-
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
36+
cloudflare-account-id: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
3737
cloudflare-project-name: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
3838
directory: dist
3939
github-token: ${{ secrets.GITHUB_TOKEN }}

.vscode/tasks.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "typescript",
6+
"tsconfig": "tsconfig.json",
7+
"option": "watch",
8+
"problemMatcher": ["$tsc-watch"],
9+
"group": "build",
10+
"label": "tsc: watch - tsconfig.json"
11+
}
12+
]
13+
}

README.md

Lines changed: 58 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@
44

55
This action deploys your build output to [Cloudflare Pages] using [Wrangler]. [GitHub Environments] and [GitHub Deployment] are used to keep track of the [Cloudflare Pages] deployments.
66

7-
When used in context of a [pull request], the action will create a deployment for the pull request and add a comment with the URL of the deployment. On closing the [pull request], all the deployments for that pull request will be deleted from [Cloudflare Pages], GitHub Deployment and the related comment. **The action is only able to delete deployments & comments that it created, as it requires a certain payload in a GitHub deployment.**
7+
When used in context of a [pull request], the action will create a deployment for the pull request and add a comment with the URL of the deployment.
88

99
- Deploy to [Cloudflare Pages].
1010
- Use [GitHub Environments] & [GitHub Deployment].
1111
- Comment on pull requests with deployment URL.
12-
- On pull request close, deletes Cloudflare Pages, GitHub deployments & comments
13-
- Production branch keeps latest 5 deployments.
12+
- Delete deployments using [`unlike-ltd/github-actions-cloudflare-pages/delete`](./delete/README.md)
1413
- Define a `working-directory` input for the `wrangler` cli command to execute from. Useful for monorepos where the `functions` folder may not be in the root directory.
1514

16-
## Usage
17-
18-
### GitHub Environments - **(Required)**
15+
## GitHub Environments - **(Required)**
1916

2017
> **This GitHub Action doesn't create the required [GitHub Environments], see below for more information.**
2118
@@ -27,7 +24,11 @@ For example manually create two GitHub Environments called "production" & "previ
2724
github-environemnt: ${{ (github.ref == 'refs/heads/main' && 'production') || 'preview' }}
2825
```
2926
30-
### Permissions
27+
## Upgrading
28+
29+
If you have previous deployments using an older version of this GitHub Action please see the [CHANGELOG.md](../CHANGELOG.md) for breaking changes.
30+
31+
## Permissions
3132
3233
The [permissions] required for this GitHub Action when using the created [`GITHUB_TOKEN`] by the workflow for the `github-token` field.
3334

@@ -39,85 +40,6 @@ permissions:
3940
pull-requests: write
4041
```
4142

42-
### Examples
43-
44-
See the GitHub Workflow examples below or [deploy.yml](./.github/workflows/deploy.yml) & [deploy-delete.yml](./.github/workflows/deploy-delete.yml)
45-
46-
### `push` & `pull_request`
47-
48-
```yaml
49-
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
50-
name: 'Deployment'
51-
on:
52-
push:
53-
branches:
54-
- main
55-
pull_request:
56-
branches:
57-
- main
58-
59-
jobs:
60-
deploy:
61-
permissions:
62-
actions: read # Only required for private GitHub Repo
63-
contents: read
64-
deployments: write
65-
pull-requests: write
66-
runs-on: ubuntu-latest
67-
timeout-minutes: 5
68-
steps:
69-
- uses: actions/checkout@v4
70-
- uses: actions/setup-node@v4
71-
with:
72-
node_version: 20
73-
- run: npm ci
74-
run: npm run build
75-
- name: Deploy to Cloudflare Pages
76-
uses: unlike-ltd/github-actions-cloudflare-pages@v1.3.1
77-
id: pages
78-
with:
79-
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
80-
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
81-
cloudflare-project-name: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
82-
directory: dist
83-
github-token: ${{ secrets.GITHUB_TOKEN }}
84-
github-environment: ${{ vars.CLOUDFLARE_PROJECT_NAME }} ${{ (github.ref == 'refs/heads/main' && '(Production)') || '(Preview)' }}
85-
```
86-
87-
### `pull_request` `closed`
88-
89-
```yaml
90-
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
91-
92-
name: 'Deployment Deletion'
93-
on:
94-
pull_request:
95-
types:
96-
- closed
97-
branches:
98-
- main
99-
100-
jobs:
101-
deploy-delete:
102-
permissions:
103-
actions: read # Only required for private GitHub Repo
104-
contents: read
105-
deployments: write
106-
pull-requests: write
107-
runs-on: ubuntu-latest
108-
timeout-minutes: 5
109-
steps:
110-
- name: Deploy deletion Cloudflare Pages
111-
uses: unlike-ltd/github-actions-cloudflare-pages@v1.3.1
112-
with:
113-
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
114-
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
115-
cloudflare-project-name: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
116-
directory: 'example/dist'
117-
github-token: ${{ secrets.GITHUB_TOKEN }}
118-
github-environment: ${{ vars.CLOUDFLARE_PROJECT_NAME }} ${{ (github.ref == 'refs/heads/main' && '(Production)') || '(Preview)' }}
119-
```
120-
12143
## Inputs
12244

12345
```yaml
@@ -164,6 +86,51 @@ wrangler:
16486
values: ${{ steps.action.outputs.wrangler }}
16587
```
16688

89+
## Examples
90+
91+
See the GitHub Workflow examples below or [deploy.yml](./.github/workflows/deploy.yml)
92+
93+
### `push` & `pull_request`
94+
95+
```yaml
96+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
97+
name: 'Deployment'
98+
on:
99+
push:
100+
branches:
101+
- main
102+
pull_request:
103+
branches:
104+
- main
105+
106+
jobs:
107+
deploy:
108+
permissions:
109+
actions: read # Only required for private GitHub Repo
110+
contents: read
111+
deployments: write
112+
pull-requests: write
113+
runs-on: ubuntu-latest
114+
timeout-minutes: 5
115+
steps:
116+
- uses: actions/checkout@v4
117+
- uses: actions/setup-node@v4
118+
with:
119+
node_version: 20
120+
- run: npm ci
121+
run: npm run build
122+
- name: Deploy to Cloudflare Pages
123+
uses: unlike-ltd/github-actions-cloudflare-pages@v1.3.1
124+
id: pages
125+
with:
126+
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
127+
cloudflare-account-id: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
128+
cloudflare-project-name: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
129+
directory: dist
130+
github-token: ${{ secrets.GITHUB_TOKEN }}
131+
github-environment: ${{ vars.CLOUDFLARE_PROJECT_NAME }} ${{ (github.ref == 'refs/heads/main' && '(Production)') || '(Preview)' }}
132+
```
133+
167134
## Comment Example
168135

169136
![pull request comment example](./docs/comment.png)
@@ -181,7 +148,11 @@ It will only delete deployments that it created. This is because it requires a c
181148
```json
182149
{
183150
"payload": {
184-
"cloudflareId": "1234",
151+
"cloudflare": {
152+
"id": "123",
153+
"projectName": "cloudflare-pages-project-name",
154+
"accountId": "123"
155+
},
185156
"url": "https://example.com",
186157
"commentId": "1234"
187158
}

__fixtures__/github-deployment.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import {
2+
MOCK_ACCOUNT_ID,
3+
MOCK_DEPLOYMENT_ID,
4+
MOCK_PROJECT_NAME
5+
} from '@/tests/helpers/api.js'
6+
7+
import type {getGitHubDeployments} from '@/common/github/deployment/get.js'
8+
9+
export const DEPLOYMENT: Awaited<
10+
ReturnType<typeof getGitHubDeployments>
11+
>[number] = {
12+
url: 'https://api.github.com/repos/unlike-ltd/github-actions-cloudflare-pages/deployments/1423939219',
13+
id: 1423939219,
14+
node_id: 'DE_kwDOJn0nrM5U35aT',
15+
task: 'deploy',
16+
original_environment: 'preview',
17+
environment: 'preview',
18+
description:
19+
'Cloudflare Pages Deployment: 4834e1f5-5ed8-417a-9489-13532994a77f',
20+
created_at: '2024-04-01T21:03:56Z',
21+
updated_at: '2024-04-01T21:03:56Z',
22+
statuses_url:
23+
'https://api.github.com/repos/unlike-ltd/github-actions-cloudflare-pages/deployments/1423939219/statuses',
24+
repository_url:
25+
'https://api.github.com/repos/unlike-ltd/github-actions-cloudflare-pages',
26+
creator: {
27+
login: 'github-actions[bot]',
28+
id: 41898282,
29+
node_id: 'MDM6Qm90NDE4OTgyODI=',
30+
avatar_url: 'https://avatars.githubusercontent.com/in/15368?v=4',
31+
gravatar_id: '',
32+
url: 'https://api.github.com/users/github-actions%5Bbot%5D',
33+
html_url: 'https://github.com/apps/github-actions',
34+
followers_url:
35+
'https://api.github.com/users/github-actions%5Bbot%5D/followers',
36+
following_url:
37+
'https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}',
38+
gists_url:
39+
'https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}',
40+
starred_url:
41+
'https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}',
42+
subscriptions_url:
43+
'https://api.github.com/users/github-actions%5Bbot%5D/subscriptions',
44+
organizations_url:
45+
'https://api.github.com/users/github-actions%5Bbot%5D/orgs',
46+
repos_url: 'https://api.github.com/users/github-actions%5Bbot%5D/repos',
47+
events_url:
48+
'https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}',
49+
received_events_url:
50+
'https://api.github.com/users/github-actions%5Bbot%5D/received_events',
51+
type: 'Bot',
52+
site_admin: false
53+
},
54+
sha: '7e7171aff2b6443234556b17c599f5cc27927d17',
55+
ref: 'andykenward/issue289',
56+
payload: {
57+
cloudflare: {
58+
id: MOCK_DEPLOYMENT_ID,
59+
projectName: MOCK_PROJECT_NAME,
60+
accountId: MOCK_ACCOUNT_ID
61+
},
62+
url: 'https://4834e1f5.cloudflare-pages-action-a5z.pages.dev',
63+
commentId: 'IC_kwDOJn0nrM55B77z'
64+
},
65+
transient_environment: false,
66+
production_environment: false,
67+
performed_via_github_app: null
68+
}

__generated__/responses/api.cloudflare.com/pages/deployments/deployments-delete.response.json

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

0 commit comments

Comments
 (0)