-
Notifications
You must be signed in to change notification settings - Fork 8
140 lines (125 loc) · 4.44 KB
/
Copy pathdeploy-docs.yml
File metadata and controls
140 lines (125 loc) · 4.44 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: "Docs: Build & Upload to R2"
on:
push:
branches: [staging, main]
# Serialize deploys per branch. Two pushes in quick succession would otherwise
# run concurrent `aws s3 sync --delete` jobs into the same R2 prefix, where each
# build's --delete removes the other's freshly-uploaded chunks, producing a
# deploy with one build's HTML and another's assets (404'd JS).
concurrency:
group: deploy-docs-${{ github.ref }}
cancel-in-progress: true
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-node@v4
with:
node-version: 22
cache: yarn
- run: yarn install --frozen-lockfile
- name: Set environment
id: env
env:
GIT_REF: ${{ github.ref }}
run: |
echo "base_url=docs" >> "$GITHUB_OUTPUT"
if [ "$GIT_REF" = "refs/heads/main" ]; then
echo "prod=true" >> "$GITHUB_OUTPUT"
echo "environment=production" >> "$GITHUB_OUTPUT"
else
echo "prod=" >> "$GITHUB_OUTPUT"
echo "environment=staging" >> "$GITHUB_OUTPUT"
fi
- name: Build
run: yarn build
env:
PROD: ${{ steps.env.outputs.prod }}
- name: Restructure build output
env:
BASE_URL: ${{ steps.env.outputs.base_url }}
run: |
mv build build-raw
mkdir -p "build/${BASE_URL}"
mv build-raw/* "build/${BASE_URL}/"
rm -rf build-raw
cp "build/${BASE_URL}/404.html" build/404.html
- name: Generate cache headers
env:
BASE_URL: ${{ steps.env.outputs.base_url }}
run: |
printf '%s\n' \
"/${BASE_URL}/assets/*" \
" Cache-Control: public, max-age=31536000, immutable" \
"" \
"/${BASE_URL}/img/*" \
" Cache-Control: public, max-age=2592000" \
"" \
"/${BASE_URL}/*.js" \
" Cache-Control: public, max-age=31536000, immutable" \
> build/_headers
- name: Upload to R2
env:
AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
AWS_ENDPOINT_URL: https://${{ secrets.CLOUDFLARE_ACCOUNT_ID }}.r2.cloudflarestorage.com
AWS_REGION: auto
ENVIRONMENT: ${{ steps.env.outputs.environment }}
run: |
aws s3 sync build/ \
"s3://www-marketdata-app-builds/${ENVIRONMENT}/sources/docs/" \
--delete
- name: Notify orchestrator
if: success()
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.ORCHESTRATOR_PAT }}
repository: MarketDataApp/www-marketdata-app
event-type: site-built
client-payload: >-
{
"source": "docs",
"source_repo": "MarketDataApp/documentation",
"environment": "${{ steps.env.outputs.environment }}",
"commit_sha": "${{ github.sha }}"
}
- name: Check if Worker changed
id: worker
run: |
if git diff --name-only HEAD~1 HEAD -- worker/ 2>/dev/null | grep -q .; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
- name: Test Worker
if: steps.worker.outputs.changed == 'true'
working-directory: worker
run: |
yarn install --frozen-lockfile
yarn test
- name: Deploy Worker
if: steps.worker.outputs.changed == 'true'
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: deploy
workingDirectory: worker
- name: Notify Slack on failure
if: failure()
env:
SLACK_NOTIFY_URL: ${{ secrets.SLACK_NOTIFY_URL }}
SLACK_NOTIFY_TOKEN: ${{ secrets.SLACK_NOTIFY_TOKEN }}
run: |
curl -s -d "" \
-H "X-workflow: ${GITHUB_WORKFLOW}" \
-H "X-repo: ${GITHUB_REPOSITORY}" \
-H "X-branch: ${GITHUB_REF_NAME}" \
-H "X-sha: ${GITHUB_SHA:0:7}" \
-H "X-run_id: ${GITHUB_RUN_ID}" \
"${SLACK_NOTIFY_URL}?token=${SLACK_NOTIFY_TOKEN}&type=ci_failure&channel=alerts"