Repository navigation
108 lines (99 loc) · 3.95 KB
/
Copy pathdeploy-sites.yml
File metadata and controls
108 lines (99 loc) · 3.95 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
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
104
105
106
107
108
name: Deploy sites
# Every top-level folder with a wrangler.toml is a site. On push to main, each
# folder that changed is deployed to Cloudflare. A site whose wrangler.toml has
# no routes is served at <folder>.alphaonelabs.com automatically.
on:
push:
branches: [main]
workflow_dispatch:
inputs:
project:
description: "Folder to deploy, or 'all'"
required: true
default: all
permissions:
contents: read
jobs:
plan:
runs-on: ubuntu-latest
outputs:
projects: ${{ steps.pick.outputs.projects }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- id: pick
env:
INPUT: ${{ github.event.inputs.project }}
BEFORE: ${{ github.event.before }}
run: |
sites=$(for f in */wrangler.toml; do dirname "$f"; done)
if [ -n "$INPUT" ] && [ "$INPUT" != all ]; then
echo "$sites" | grep -qx "$INPUT" || { echo "::error::$INPUT has no wrangler.toml"; exit 1; }
picked="$INPUT"
elif [ "$INPUT" = all ] || [ -z "$BEFORE" ] || ! git cat-file -e "$BEFORE^{commit}" 2>/dev/null; then
picked="$sites"
else
changed=$(git diff --name-only "$BEFORE" "$GITHUB_SHA" | cut -d/ -f1 | sort -u)
picked=$(comm -12 <(echo "$sites" | sort) <(echo "$changed"))
fi
echo "projects=$(echo "$picked" | jq -R . | jq -sc 'map(select(length > 0))')" >> "$GITHUB_OUTPUT"
echo "Deploying: $(echo $picked)"
deploy:
needs: plan
if: needs.plan.outputs.projects != '[]'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
project: ${{ fromJSON(needs.plan.outputs.projects) }}
concurrency:
group: deploy-${{ matrix.project }}
cancel-in-progress: false
defaults:
run:
working-directory: ${{ matrix.project }}
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Build GSoC ideas page and leaderboard
if: matrix.project == 'gsoc'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pip install markdown && python scripts/build_ideas.py
python scripts/generate_leaderboard.py
- name: Build
if: hashFiles(format('{0}/package.json', matrix.project)) != ''
run: |
npm ci
if jq -e '.scripts.build' package.json >/dev/null; then npm run build; fi
- name: Deploy
run: |
args=()
# learn's domains (learn., apex, www) are attached in Cloudflare; leave them alone.
if [ "${{ matrix.project }}" != learn ] && ! grep -qE '^\s*routes?\s*=' wrangler.toml; then
args+=(--domain "${{ matrix.project }}.alphaonelabs.com")
fi
npx --yes wrangler@4.40.0 deploy "${args[@]}"
- name: Purge the site's pages from the CDN cache
# A response cached at the edge during a deploy (e.g. a transient 403) can
# otherwise outlive the deploy, so drop the main pages for this site.
env:
ZONE_ID: 6f9d9bc5260431584221266afda142e5
run: |
hosts=$(grep -oE 'pattern = "[^"]+"' wrangler.toml | cut -d'"' -f2)
[ "${{ matrix.project }}" = learn ] && hosts="learn.alphaonelabs.com alphaonelabs.com www.alphaonelabs.com"
[ -z "$hosts" ] && hosts="${{ matrix.project }}.alphaonelabs.com"
files=$(for h in $hosts; do printf '"https://%s/",' "$h"; done)
curl -sS -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/purge_cache" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" -H "Content-Type: application/json" \
-d "{\"files\":[${files%,}]}" | jq -c '{success, errors}'