-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (92 loc) · 2.81 KB
/
web.yml
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
name: web
on:
push:
branches:
- main
pull_request:
branches:
- main
paths:
- web/**
- .github/workflows/*
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
verify-frontend:
runs-on: ubuntu-latest
defaults:
run:
working-directory: web
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.x
- run: npm install
- run: npm run validate
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: web
steps:
- uses: actions/checkout@v4
- name: configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: eu-west-2
- uses: actions/setup-node@v4
with:
node-version: 18.x
- run: npm install
- run: npm run build
- name: zip artifact
run: (cd dist && zip -r ../dist.zip .)
- name: upload artifact
uses: actions/upload-artifact@v4
if: github.ref == 'refs/heads/main' && github.event_name == 'push' || github.event_name == 'workflow_dispatch'
with:
name: web-${{ github.sha }}
path: web/dist.zip
release:
if: github.ref == 'refs/heads/main' && github.event_name == 'push' || github.event_name == 'workflow_dispatch'
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: eu-west-2
- name: terraform init
run: |
terraform -chdir=iac init -input=false \
-backend-config="bucket=${{ secrets.TF_STATE_BUCKET }}" \
-backend-config="key=${{ env.TF_STATE_KEY }}"
env:
TF_STATE_KEY: ask-david.tfstate
- uses: actions/download-artifact@v4
with:
name: web-${{ github.sha }}
- run: unzip -d to-upload dist.zip
- name: upload
run: |
BUCKET_NAME=$(terraform -chdir=iac output -raw s3_bucket_name)
aws s3 sync to-upload "s3://${BUCKET_NAME}/"
- name: invalidate cache
run: |
CLOUDFRONT_DIST=$(terraform -chdir=iac output -raw cloudfront_id)
aws cloudfront create-invalidation --distribution-id "${CLOUDFRONT_DIST}" --paths "/*"
dependabot:
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request'}}
needs: [verify-frontend, build]
runs-on: ubuntu-latest
steps:
- run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{ secrets.PAT_AUTO_MERGE }}