-
Notifications
You must be signed in to change notification settings - Fork 4
103 lines (88 loc) · 2.82 KB
/
cloudflare-pages-deploy.yml
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Cloudflare Pages Deploy
env:
ARTIFACT_NAME: blog-artifact
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
name: Build Pages
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
- name: Restore cache
uses: actions/cache@v4
with:
path: |
.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx', '**.md') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
- name: Install dependencies
run: npm ci
- name: Build with Next.js
run: npm run build
- name: Upload artifact
if: github.event.pull_request.head.repo.fork == false
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
retention-days: 3
path: ./out
- name: Skip
if: github.event.pull_request.head.repo.fork == true
run: echo "Skipping build for forked PR"
deploy:
runs-on: ubuntu-latest
needs: build
name: Deploy to Cloudflare Pages
permissions:
contents: read
deployments: write
pull-requests: write # To can create a comment in PR
steps:
- name: Checkout
if: github.event.pull_request.head.repo.fork == false
uses: actions/checkout@v4
- name: Download a Build Artifact
if: github.event.pull_request.head.repo.fork == false
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: ./out
- name: Deploy
id: deploy
if: github.event.pull_request.head.repo.fork == false
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy out --project-name=blog-c3 --branch ${{ github.ref_name }}
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
- name: Comment PR
if: github.event.pull_request.head.repo.fork == false
uses: actions/github-script@v7.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { issue: { number: issue_number }, repo: { owner, repo } } = context;
const message = `### 🚀 **Preview Url** 🚀
[${{ steps.deploy.outputs.deployment-url }}](${{ steps.deploy.outputs.deployment-url }})`;
github.rest.issues.createComment({
issue_number,
owner,
repo,
body: message
});
- name: Skip
if: github.event.pull_request.head.repo.fork == true
run: echo "Skipping deploy for forked PR"