-
Notifications
You must be signed in to change notification settings - Fork 26
173 lines (148 loc) · 5.11 KB
/
release.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
name: Release
on:
push:
tags:
- "v*" # Push events to matching v*, i.e. v1.0, v2.1.3
branches:
- development
jobs:
set_environment:
runs-on: ubuntu-latest
steps:
- name: Set up environment based on branch
id: environment_check
shell: bash
run: |
BRANCH_NAME=${GITHUB_REF#refs/heads/}
BRANCH_NAME=${BRANCH_NAME#refs/tags/}
ENVIRONMENT="development"
if [[ "$BRANCH_NAME" == v* ]]; then
ENVIRONMENT="production"
fi
echo "environment=${ENVIRONMENT,,}" >> $GITHUB_OUTPUT
outputs:
environment: ${{ steps.environment_check.outputs.environment }}
update_database:
if: needs.set_environment.outputs.environment == 'production'
runs-on: ubuntu-latest
needs: set_environment
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use Node.js 16
uses: actions/setup-node@v4
with:
node-version: "16"
- name: Install NPM Dependencies
run: npm install --include=dev
# Sync content to production DB
- name: Sync content to Prod Instance
env:
NEO4J_HOST: ${{ secrets.PROD_NEO4J_HOST }}
NEO4J_USERNAME: ${{ secrets.PROD_NEO4J_USERNAME }}
NEO4J_PASSWORD: ${{ secrets.PROD_NEO4J_PASSWORD }}
run: npm run sync:db
# Test the database
- name: Test Database
env:
NEO4J_HOST: ${{ secrets.PROD_NEO4J_HOST }}
NEO4J_USERNAME: ${{ secrets.PROD_NEO4J_USERNAME }}
NEO4J_PASSWORD: ${{ secrets.PROD_NEO4J_PASSWORD }}
run: npm run test:db
sync_assets:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
needs: [set_environment]
environment: ${{ needs.set_environment.outputs.environment }}
env:
ENVIRONMENT: ${{ needs.set_environment.outputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.AWS_DEPLOY_ROLE_ARN }}
aws-region: ${{ vars.AWS_REGION }}
# Sync images to CDN
- name: Sync public/ to S3
if: env.ENVIRONMENT == 'production'
run: aws s3 sync ./public s3://${{ vars.ASSETS_BUCKET_NAME }}/assets --acl public-read
upload_zip:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
needs: [set_environment, sync_assets]
environment: ${{ needs.set_environment.outputs.environment }}
env:
ENVIRONMENT: ${{ needs.set_environment.outputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.AWS_DEPLOY_ROLE_ARN }}
aws-region: ${{ vars.AWS_REGION }}
- name: Create course asciidoc zip
run: npm run build:content
- name: Upload courses to S3
run: |
aws s3 cp ./courses.zip "s3://${{ vars.CERTS_COURSES_BUCKET_NAME }}/content/courses.zip"
- name: Install NPM Dependencies
run: npm install --include=dev
- name: Create HTML zip
run: npm run build:html
- name: Upload HTML to S3
run: |
aws s3 cp ./html.zip "s3://${{ vars.CERTS_COURSES_BUCKET_NAME }}/content/html.zip"
restart-cluster:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
needs: [set_environment, sync_assets, upload_zip]
environment: ${{ needs.set_environment.outputs.environment }}
env:
ENVIRONMENT: ${{ needs.set_environment.outputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.AWS_DEPLOY_ROLE_ARN }}
aws-region: ${{ vars.AWS_REGION }}
- name: Deploying services with an env file
uses: brunocascio/ecs-deploy@v2.2.0
env:
CLUSTER_NAME: ${{ env.ENVIRONMENT }}-graphacademy-cluster
SERVICE_NAME: ${{ env.ENVIRONMENT }}-graphacademy-service
with:
args: deploy ${{ env.CLUSTER_NAME }} ${{ env.SERVICE_NAME }} --timeout -1
invalidate_cache:
runs-on: ubuntu-latest
needs: [set_environment, sync_assets, upload_zip]
environment: ${{ needs.set_environment.outputs.environment }}
env:
ENVIRONMENT: ${{ needs.set_environment.outputs.environment }}
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.AWS_DEPLOY_ROLE_ARN }}
aws-region: ${{ vars.AWS_REGION }}
- name: Invalidate CloudFront Cache
uses: chetan/invalidate-cloudfront-action@v2
env:
DISTRIBUTION: ${{ vars.CDN_DISTRIBUTION_ID }}
PATHS: "/*"
AWS_REGION: ${{ vars.AWS_REGION }}