-
Notifications
You must be signed in to change notification settings - Fork 2
98 lines (83 loc) · 2.64 KB
/
deploy-aws.yml
File metadata and controls
98 lines (83 loc) · 2.64 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
name: Deploy to AWS S3 + CloudFront
on:
push:
branches: [ main ]
permissions:
contents: read
id-token: write # Required for AWS OIDC authentication
jobs:
commit_lint:
name: Validate Commit Messages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate PR Title
uses: wagoid/commitlint-github-action@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
configFile: .commitlintrc.json
build-and-deploy:
needs: commit_lint
name: Build and Deploy to AWS
runs-on: ubuntu-latest
environment:
name: aws-prod
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Build MkDocs site
run: mkdocs build --strict --use-directory-urls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Sync to S3
run: |
aws s3 sync site/ s3://${{ secrets.AWS_S3_BUCKET }}/ \
--delete \
--cache-control "public, max-age=3600" \
--exclude "*.html" \
--exclude "sitemap.xml"
# Upload HTML files with shorter cache
aws s3 sync site/ s3://${{ secrets.AWS_S3_BUCKET }}/ \
--cache-control "public, max-age=600, must-revalidate" \
--content-type "text/html; charset=utf-8" \
--exclude "*" \
--include "*.html"
# Upload sitemap with no cache
aws s3 sync site/ s3://${{ secrets.AWS_S3_BUCKET }}/ \
--cache-control "public, max-age=0, must-revalidate" \
--exclude "*" \
--include "sitemap.xml"
cleanup-staging:
name: Stop Staging Site
needs: build-and-deploy
runs-on: ubuntu-latest
environment:
name: aws-stag
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Stop Staging Site
run: |
aws s3 rm s3://${{ secrets.AWS_S3_BUCKET }}/ --recursive