-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (75 loc) · 3.3 KB
/
main.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
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
name: CI
on:
push:
branches: [ master]
pull_request:
branches: [ master ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow builds the application using npm
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Use Node js v14
uses: actions/setup-node@v2
with:
node-version: 14
cache: 'npm'
# Install project depedencies from package.json
- run: npm install
# Refresh the source json files from the source
- run: npm run refresh-source
# Build the application and create a ./dist folder
- run: npm run build
- name: Archive production artifacts
uses: actions/upload-artifact@v2
with:
name: dist
path: dist
retention-days: 1
deploy-to-s3:
needs: build
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Configure AWS Cli
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Download artifact dist
uses: actions/download-artifact@v2
with:
name: dist
- name: Delete s3 bucket content
run: aws s3 rm ${{ secrets.AWS_S3_BUCKET }} --recursive
- name: Upload everything but javascript files for now
run: aws s3 cp . ${{ secrets.AWS_S3_BUCKET }} --cache-control 'max-age=86400' --exclude "*.js" --recursive
- name: Upload javascript files
run: aws s3 cp . ${{ secrets.AWS_S3_BUCKET }} --exclude "*" --include "*.js" --cache-control 'max-age=86400' --content-type=application/javascript --recursive
- name: Update control-header tags of index.html
run: aws s3 cp --cache-control max-age=0 --content-type=text/html --metadata-directive=REPLACE ${{ secrets.AWS_S3_BUCKET }}/index.html ${{ secrets.AWS_S3_BUCKET }}/index.html
- name: Update control-header tags of service-worker.js
run: aws s3 cp --cache-control max-age=0 --content-type=application/javascript --metadata-directive=REPLACE ${{ secrets.AWS_S3_BUCKET }}/service-worker.js ${{ secrets.AWS_S3_BUCKET }}/service-worker.js
invalidate-cloudfront:
needs: deploy-to-s3
runs-on: ubuntu-latest
steps:
# Configure AWS Cli
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Invalidate Cloudfront
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }} --paths "/*"