-
Notifications
You must be signed in to change notification settings - Fork 2
70 lines (57 loc) · 1.91 KB
/
deploy.yml
File metadata and controls
70 lines (57 loc) · 1.91 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
name: waggle deployment (PR to deploy)
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ROLE_ARN: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_OIDC_ROLE_NAME }}
S3_BUCKET: ${{ secrets.AWS_BUCKET_NAME }}
CF_DISTRIBUTION_ID: ${{ secrets.AWS_DISTRIBUTION_ID }}
steps:
- name: Checkout source
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build React App
run: npm run build
env:
VITE_BASE_URL: ${{ secrets.VITE_BASE_URL }}
- name: Configure AWS credentials via OIDC
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.AWS_ROLE_ARN }}
role-session-name: github-actions-${{ github.run_id }}
aws-region: ${{ env.AWS_REGION }}
- name: Deploy to S3 (validate & upload)
shell: bash
run: |
set -euo pipefail
test -f dist/index.html
[[ -n "${S3_BUCKET}" ]]
[[ "${S3_BUCKET}" != s3://* ]]
aws s3 cp "dist" "s3://${S3_BUCKET}" \
--recursive \
--exclude "index.html" \
--cache-control "public, max-age=31536000, immutable"
aws s3 cp "dist/index.html" "s3://${S3_BUCKET}/index.html" \
--cache-control "no-cache, no-store, must-revalidate" \
--content-type "text/html"
- name: Invalidate CloudFront cache (HTML only)
run: |
aws cloudfront create-invalidation \
--distribution-id "${CF_DISTRIBUTION_ID}" \
--paths "/index.html" "/assets/*" "/static/*"