-
Notifications
You must be signed in to change notification settings - Fork 7
127 lines (113 loc) · 3.96 KB
/
Copy pathdeploy-docs.yml
File metadata and controls
127 lines (113 loc) · 3.96 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
name: "Docs: Build & Upload to R2"
on:
push:
branches: [staging, main]
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 "" \
"${SLACK_NOTIFY_URL}?token=${SLACK_NOTIFY_TOKEN}&type=ci_failure&channel=alerts&workflow=${GITHUB_WORKFLOW}&repo=${GITHUB_REPOSITORY}&branch=${GITHUB_REF_NAME}&sha=${GITHUB_SHA:0:7}&run_id=${GITHUB_RUN_ID}"