Repository navigation
118 lines (112 loc) · 4.43 KB
/
Copy pathdeploy.yml
File metadata and controls
118 lines (112 loc) · 4.43 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
109
110
111
112
113
114
115
116
117
118
name: Deploy site
# Builds the leaderboard from main plus the stats branch and ships it to
# Cloudflare Pages, after every merge, Likes sync and site change, and again once
# a submission or health check has made its threads and moved its stats.
on:
push:
branches: [main]
paths: ["site/**", "data/**"]
workflow_run:
workflows:
["Create entry Discussions", "Sync Likes", "Submit", "Health check"]
types: [completed]
workflow_dispatch:
permissions: {}
# Only the newest build matters: an older one would ship older numbers.
concurrency:
group: deploy
cancel-in-progress: true
env:
# Must match site/package.json; site/tests/config.test.mjs checks it.
WRANGLER_VERSION: "4.157.0"
jobs:
build:
if: github.event_name != 'workflow_run' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main')
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
actions: read
env:
# The build otherwise reports usage to telemetry.astro.build.
ASTRO_TELEMETRY_DISABLED: 1
steps:
- uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
# workflow_run always runs main's copy of this file; build main too,
# never the triggering run's head_sha.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
persist-credentials: false
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: stats
path: stats-data
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "22"
cache: npm
cache-dependency-path: site/package-lock.json
- run: npm ci --ignore-scripts
working-directory: site
- run: npm test
working-directory: site
# The home page's "Last count" is when Likes were last counted, not when the site was built.
- name: Find the last Likes count
run: echo "LIKES_AT=$(gh run list -R "$GITHUB_REPOSITORY" -w likes.yml -s success -L 1 --json updatedAt --jq '.[0].updatedAt // ""')" >> "$GITHUB_ENV"
env:
GH_TOKEN: ${{ github.token }}
- run: npm run build
working-directory: site
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: site-dist
path: site/dist
retention-days: 1
if-no-files-found: error
deploy:
needs: build
runs-on: ubuntu-latest
# The Cloudflare secrets live only here, and the environment only deploys from main.
environment:
name: production
url: https://devstream.jamesconway.dev
timeout-minutes: 10
permissions:
contents: read
steps:
- uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
persist-credentials: false
sparse-checkout: scripts/admin
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: site-dist
path: site/dist
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "22"
# Only wrangler, at the pinned version, with no install scripts. The
# action finds it and skips its own install.
- run: npm install --no-save --no-package-lock --ignore-scripts --prefix site "wrangler@$WRANGLER_VERSION"
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.12"
- run: python scripts/admin/cloudflare_setup.py
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- uses: cloudflare/wrangler-action@953926a2e2182532811c01a25e53647d93bf07c0 # v4.1.3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: site
wranglerVersion: ${{ env.WRANGLER_VERSION }}
command: pages deploy dist --project-name=devstream --branch=main