forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
106 lines (89 loc) · 2.93 KB
/
deploy-mfe-s3.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
98
99
100
101
102
103
104
105
106
name: MFE S3 Bucket Deployment 🚀
on:
push:
branches:
- open-release/palm.nelp
- open-rc/palm.nelp
pull_request:
branches:
- "**open-rc**"
jobs:
build:
environment:
name: ${{ github.ref_name == 'open-release/palm.nelp' && 'prod' || 'stage' }}
runs-on: ubuntu-latest
steps:
- name: "Echo job vars"
env:
JOB_VARS: ${{ toJson(vars) }}
run: echo "$JOB_VARS"
- name: checkout mfe repo
uses: actions/checkout@v3
- name: Use Node.js ${{ vars.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ vars.NODE_VERSION }}
- name: Cache node modules
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: npm list
- name: npm Install
run: npm install
- name: npm Build # check env variables of repo.
run: npm run build
env:
PUBLIC_PATH: ${{ vars.PUBLIC_PATH_CDN }}
APP_ID: ${{ vars.APP_ID }}
MFE_CONFIG_API_URL: ${{ vars.MFE_CONFIG_API_URL }}
ENABLE_NEW_RELIC: false
NODE_ENV: production
- name: print generated html of mfe
run: cat dist/index.html
- name: Share artifact inside workflow
uses: actions/upload-artifact@v3
with:
name: ${{ vars.APP_ID }}-dist-artifact
path: dist
deployment:
environment:
name: ${{ github.ref_name == 'open-release/palm.nelp' && 'prod' || 'stage' }}
url: ${{ vars.PUBLIC_PATH_CDN }}
runs-on: ubuntu-latest
needs: build
steps:
# get build artifact
- name: Get artifact
uses: actions/download-artifact@v3
with:
name: ${{ vars.APP_ID }}-dist-artifact
- name: "Echo job vars"
env:
JOB_VARS: ${{ toJson(vars) }}
run: echo "$JOB_VARS"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Deploy to S3
run: |
aws s3 sync . $S3_BUCKET --delete
env:
S3_BUCKET: s3://${{ vars.BUCKET_NAME }}/${{ vars.APP_ID }}/
- name: Invalidate past cloudfront cache
run: |
aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }} --paths "/${{ vars.APP_ID }}/*"