-
Notifications
You must be signed in to change notification settings - Fork 14
102 lines (91 loc) · 3.42 KB
/
previews-cf.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
name: 'Deploy: Cloudflare PR Preview'
on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
env:
PAGES_PROJECT_NAME: optimizer
PAGES_PROJECT_URL_SLUG: discretize-gear-optimizer
NODE_VERSION: 18
jobs:
# see https://github.com/orgs/community/discussions/26726, https://stackoverflow.com/a/70249520
check-secrets:
runs-on: ubuntu-latest
outputs:
exists: ${{ steps.check-secret-step.outputs.exists }}
steps:
- name: Check that secrets exist
id: check-secret-step
run: |
if [ "${{ secrets.CI_CF_PAGES }}" != '' ]; then
echo "exists=true" >> $GITHUB_OUTPUT;
else
echo "exists=false" >> $GITHUB_OUTPUT;
fi
deployment:
needs: [check-secrets]
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
pull-requests: write
if: >
needs.check-secrets.outputs.exists == 'true' &&
github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name &&
!contains(github.event.head_commit.message, 'skip ci') &&
!contains(github.event.pull_request.body, '[no previews]') &&
(contains(github.event.pull_request.body, '[draft previews]') || github.event.pull_request.draft == false)
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up PNPM
uses: pnpm/action-setup@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
- name: Install dependencies
run: pnpm install
- name: Cache Rust Output
id: rust-output-cache
uses: actions/cache@v4
with:
path: |
wasm_module/pkg
wasm_module/target
key: rust-output-${{ env.NODE_VERSION }}-${{ hashFiles('wasm_module', '**/pnpm-lock.yaml') }}
restore-keys: rust-output-
- name: Cache Rust Dependencies
uses: Swatinem/rust-cache@v2
with:
workspaces: wasm_module
if: steps.rust-output-cache.outputs.cache-hit != 'true'
- name: Compile Rust
run: pnpm wasm
if: steps.rust-output-cache.outputs.cache-hit != 'true'
- name: Build Cloudflare
run: pnpm build-cf
- name: Deploy preview to Cloudflare
uses: cloudflare/pages-action@1
id: pages-action
with:
apiToken: ${{ secrets.CI_CF_PAGES }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
projectName: ${{ env.PAGES_PROJECT_NAME }}
directory: dist
branch: ${{ github.head_ref || github.ref_name }}
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
wranglerVersion: '3'
- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
with:
message: |
Deployed ${{ steps.pages-action.outputs.environment }} build to Cloudflare!
| | |
| ----------------------- | - |
| **Last commit:** | ${{ github.event.pull_request.head.sha || github.event.workflow_run.head_sha || github.sha }} |
| **Preview URL**: | ${{ steps.pages-action.outputs.url }} |
| **Branch Preview URL**: | https://${{ github.head_ref || github.ref_name }}.${{ env.PAGES_PROJECT_URL_SLUG }}.pages.dev |
comment_tag: deployment
mode: upsert