Repository navigation
77 lines (62 loc) · 2.38 KB
/
Copy pathdeploy.yml
File metadata and controls
77 lines (62 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: Deploy
on:
push:
branches: [master]
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
permissions:
contents: read
deployments: write
pull-requests: write
env:
# Must match mise.toml, otherwise wrangler-action runs `pnpm add wrangler`, which pnpm blocks.
WRANGLER_VERSION: 4.156.0
jobs:
deploy:
runs-on: ubuntu-latest
# Fork PRs don't get repository secrets.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
environment:
name: ${{ github.event_name == 'pull_request' && 'site-preview' || 'site-production' }}
url: ${{ steps.deploy.outputs.deployment-url }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install mise and dependencies
uses: jdx/mise-action@v3
- name: Install Dependencies
run: pnpm install --frozen-lockfile
- name: Check
run: pnpm check && pnpm lint
- name: Build
run: pnpm build
- name: Deploy to Cloudflare Pages
id: deploy
uses: cloudflare/wrangler-action@v3
with:
wranglerVersion: ${{ env.WRANGLER_VERSION }}
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy build --project-name=${{ vars.CLOUDFLARE_PAGES_PROJECT }} --branch=${{ github.event.pull_request.number && format('pr{0}', github.event.pull_request.number) || 'master' }}
# Edits the bot's previous comment so the PR keeps one preview link.
- name: Comment Preview URL
if: github.event_name == 'pull_request'
run: |
gh pr comment "$PR_NUMBER" --edit-last --create-if-none --body "$(cat <<BODY
### Site preview
| | |
| --- | --- |
| Preview | $PREVIEW_URL |
| This deploy | $DEPLOYMENT_URL |
| Commit | $COMMIT |
BODY
)"
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PREVIEW_URL: https://pr${{ github.event.pull_request.number }}.${{ vars.CLOUDFLARE_PAGES_PROJECT }}.pages.dev
DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }}
COMMIT: ${{ github.event.pull_request.head.sha }}