Repository navigation
78 lines (66 loc) · 2.86 KB
/
Copy pathdeploy.yml
File metadata and controls
78 lines (66 loc) · 2.86 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
78
name: Deploy to Cloudflare Pages
on:
push:
branches:
- main
# Allows maintainers to redeploy after configuring secrets, without a new commit.
workflow_dispatch:
# Least privilege: the job only needs to read the repository.
permissions:
contents: read
# Never run two production deploys at the same time.
concurrency:
group: deploy-cloudflare-${{ github.ref }}
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build static export
run: npm run build:pages
# Secrets cannot be used directly in `if:` expressions. Check them here and
# expose the result as a step output so the deploy step can be skipped
# (instead of failing) when the repository has not been configured yet.
- name: Check Cloudflare credentials
id: cloudflare
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
if [ -z "${CLOUDFLARE_API_TOKEN}" ] || [ -z "${CLOUDFLARE_ACCOUNT_ID}" ]; then
echo "::warning title=Cloudflare deploy skipped::CLOUDFLARE_API_TOKEN and/or CLOUDFLARE_ACCOUNT_ID are not configured. Add them under Settings > Secrets and variables > Actions to enable deployment."
echo "can_deploy=false" >> "$GITHUB_OUTPUT"
exit 0
fi
status=$(curl --silent --show-error --output /tmp/cloudflare-token-verify.json \
--write-out "%{http_code}" \
--header "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \
https://api.cloudflare.com/client/v4/user/tokens/verify)
if [ "${status}" != "200" ]; then
echo "::error title=Invalid Cloudflare API token::Cloudflare rejected CLOUDFLARE_API_TOKEN (HTTP ${status}). Verify the token is active and has Cloudflare Pages: Edit permission."
cat /tmp/cloudflare-token-verify.json
exit 1
fi
echo "can_deploy=true" >> "$GITHUB_OUTPUT"
- name: Deploy to Cloudflare Pages
# Only deploy from the canonical repository's main branch, and only when
# both Cloudflare secrets are present. Forks and PRs never reach this step.
if: >-
steps.cloudflare.outputs.can_deploy == 'true' &&
github.ref == 'refs/heads/main' &&
github.repository == 'TechMitten/mitten-os'
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy out --project-name=mittenos --branch=main