-
Notifications
You must be signed in to change notification settings - Fork 6
144 lines (123 loc) · 4.56 KB
/
dev.yml
File metadata and controls
144 lines (123 loc) · 4.56 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
141
142
143
144
name: DEV CI/CD
on:
push:
branches: [develop]
workflow_dispatch:
permissions:
contents: read
env:
NODE_VERSION: '20.x'
AZURE_ACCOUNT_NAME: 'stdfxsrvdev'
AZURE_CDN_PROFILE: 'cdnp-dfx-srv-dev'
AZURE_CDN_ENDPOINT: 'cdne-dfx-srv-dev'
AZURE_RESOURCE_GROUP: 'rg-dfx-srv-dev'
jobs:
build:
name: Build and deploy to DEV
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login
uses: azure/login@v2
with:
creds: ${{ secrets.DEV_CREDENTIALS }}
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install packages
run: npm ci
- name: Read version
id: package_version
run: echo "current-version=$(jq -r .version package.json)" >> $GITHUB_OUTPUT
- name: Run linter
run: npm run lint
- name: Run tests
run: npm run test
- name: Build code
env:
REACT_APP_BUILD_ID: ${{ github.run_number }}-${{ github.run_id }}
run: npm run build:dev
- name: Build widget
run: |
npm run widget:dev
- name: Copy widget
run: |
version=$(echo "v${{ steps.package_version.outputs.current-version }}" | cut -d '.' -f1-2)
mkdir -p ./build/widget/$version-chunks
cp ./widget/static/js/main.*.js ./build/widget/$version
cp ./widget/static/css/main.*.css ./build/widget/$version.css
cp ./widget/$version-chunks/*.chunk.js ./build/widget/$version-chunks
cp ./widget/$version-chunks/*.chunk.css ./build/widget/$version-chunks
cp ./widget/$version-chunks/*.wasm ./build/widget/$version-chunks
sed -i "s|main-widget.css|https://dev.app.dfx.swiss/widget/$version.css|g" "./build/widget/$version"
- name: Deploy to Azure Storage (DEV)
uses: azure/CLI@v2
with:
inlineScript: |
# Upload static assets with immutable caching (hashed filenames never change)
az storage blob upload-batch \
--account-name ${{ env.AZURE_ACCOUNT_NAME }} \
-d '$web' \
-s ./build \
--pattern "static/*" \
--content-cache-control "public, max-age=31536000, immutable" \
--overwrite
# Upload entry points with no-cache (must revalidate on every request)
for file in index.html manifest.json asset-manifest.json robots.txt; do
if [ -f "./build/$file" ]; then
az storage blob upload \
--account-name ${{ env.AZURE_ACCOUNT_NAME }} \
-c '$web' \
-f "./build/$file" \
-n "$file" \
--content-cache-control "no-cache, must-revalidate" \
--overwrite
fi
done
# Upload other assets (favicon, logo, wasm)
az storage blob upload-batch \
--account-name ${{ env.AZURE_ACCOUNT_NAME }} \
-d '$web' \
-s ./build \
--pattern "*.ico" \
--content-cache-control "public, max-age=86400" \
--overwrite
az storage blob upload-batch \
--account-name ${{ env.AZURE_ACCOUNT_NAME }} \
-d '$web' \
-s ./build \
--pattern "*.png" \
--content-cache-control "public, max-age=86400" \
--overwrite
az storage blob upload-batch \
--account-name ${{ env.AZURE_ACCOUNT_NAME }} \
-d '$web' \
-s ./build \
--pattern "*.wasm" \
--content-cache-control "public, max-age=31536000, immutable" \
--overwrite
# Upload widget files
az storage blob upload-batch \
--account-name ${{ env.AZURE_ACCOUNT_NAME }} \
-d '$web' \
-s ./build \
--pattern "widget/*" \
--content-cache-control "public, max-age=3600" \
--overwrite
- name: Purge CDN endpoint (DEV)
uses: azure/CLI@v2
with:
inlineScript: |
az afd endpoint purge \
--content-paths "/*" \
--profile-name ${{ env.AZURE_CDN_PROFILE }} \
--endpoint-name ${{ env.AZURE_CDN_ENDPOINT }} \
--resource-group ${{ env.AZURE_RESOURCE_GROUP }} \
--no-wait
- name: Logout
run: |
az logout
if: always()