forked from hotosm/fAIr
-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (68 loc) · 2.52 KB
/
Copy pathdeploy_frontend_s3.yml
File metadata and controls
82 lines (68 loc) · 2.52 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
name: Deploy Production Frontend to S3 & CloudFront
on:
push:
branches:
- main
paths:
- 'frontend/**'
- '.github/workflows/deploy_frontend_s3.yml'
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
build-and-deploy:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./frontend
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 9.8.0
- name: Get pnpm store directory
id: pnpm-cache
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install Dependencies
run: pnpm install --frozen-lockfile
- name: Build Static Production Assets
env:
VITE_BASE_API_URL: "https://api.fair.hotosm.org/api/v1/"
VITE_NODE_ENV: "production"
VITE_FAIR_PROD_URL: "https://fair.hotosm.org/"
VITE_HANKO_URL: "https://login.hotosm.org"
run: pnpm run build
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::670261699094:role/Github-AWS-OIDC
aws-region: us-east-1
- name: Sync Static Assets to S3
run: |
aws s3 sync dist/ s3://hotosm-fair-frontend-production \
--delete \
--cache-control "public, max-age=31536000, immutable" \
--exclude "index.html"
# Sync index.html with no-cache so client browsers instantly receive app updates
aws s3 cp dist/index.html s3://hotosm-fair-frontend-production/index.html \
--cache-control "no-cache, no-store, must-revalidate"
- name: Invalidate CloudFront CDN Cache
run: |
DISTRIBUTION_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[?Aliases.Items && contains(Aliases.Items, 'fair.hotosm.org')].Id | [0]" --output text)
if [ "$DISTRIBUTION_ID" != "None" ] && [ -n "$DISTRIBUTION_ID" ]; then
aws cloudfront create-invalidation --distribution-id "$DISTRIBUTION_ID" --paths "/*"
fi