86 lines (76 loc) · 2.49 KB
/
build-and-deploy-site.yaml
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
name: Website Build and Deploy
on:
push:
branches:
- main
jobs:
hugo_build_and_deploy:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
deployments: write
actions: read
steps:
- name: Checkout Code
id: code-checkout
uses: actions/checkout@v4
with:
submodules: recursive
ref: ${{ github.head_ref || github.ref_name }}
- name: Set up NodeJS for Hugo
id: setup-node
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Setup Hugo
id: hugo-setup
uses: peaceiris/actions-hugo@v3
with:
hugo-version: '0.124.1'
extended: true
- name: Configure AWS Credentials
id: aws-credentials-configure
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Build Live Site
id: hugo-site-build
if: contains( github.ref, 'main')
run: hugo --baseURL https://colinbarker.me.uk/ --verbose
- name: Set Deploy Status
id: deploy-status-start
uses: bobheadxi/deployments@main
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: Prod
ref: ${{ github.ref }}
- name: Deploy Live Site
id: aws-s3-deploy
if: contains( github.ref, 'main')
run: aws s3 sync --delete public s3://website-colins-blog
- name: Finish Deploy
id: deploy-status-finish
uses: bobheadxi/deployments@main
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
env: Prod
ref: ${{ github.ref }}
status: ${{ job.status }}
deployment_id: ${{ steps.deploy-status-start.outputs.deployment_id }}
env_url: https://colinbarker.me.uk/
cloudflare_purge_cache:
runs-on: ubuntu-latest
needs: [ hugo_build_and_deploy ]
steps:
- name: Clear CloudFlare cache
id: cloudflare-clear-cache
env:
CLOUDFLARE_ZONE_ID: ${{ secrets.CLOUDFLARE_ZONE_ID }}
CLOUDFLARE_API_KEY: ${{ secrets.CLOUDFLARE_API_KEY }}
run: |
curl -X POST "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE_ID/purge_cache" -H "Authorization: Bearer $CLOUDFLARE_API_KEY" -H "Content-Type:application/json" --data '{"purge_everything":true}'