-
Notifications
You must be signed in to change notification settings - Fork 7
172 lines (168 loc) · 6.69 KB
/
ci.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
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
name: Node.js CI
on:
push:
branches: [master, prod]
pull_request:
branches: [master]
repository_dispatch:
types: [publish-event]
env:
# Enable colors in CLI apps.
# 3 - Truecolor support (16 million colors)
# https://www.npmjs.com/package/chalk#chalksupportscolor
FORCE_COLOR: 3
AWS_S3_BUCKET_PREVIEW: kj-pola-app-web-preview
AWS_S3_BUCKET_STAG: kj-pola-web-public-stag
AWS_S3_BUCKET_PROD: kj-pola-web-public
jobs:
build:
permissions:
id-token: write # This is required for aws-actions/configure-aws-credentials
contents: write # This is required for actions/checkout
statuses: write # This is required for pbrandone/create-status-action
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump job context
env:
JOB_CONTEXT: ${{ toJSON(job) }}
run: echo "$JOB_CONTEXT"
- name: Dump steps context
env:
STEPS_CONTEXT: ${{ toJSON(steps) }}
run: echo "$STEPS_CONTEXT"
- name: Dump runner context
env:
RUNNER_CONTEXT: ${{ toJSON(runner) }}
run: echo "$RUNNER_CONTEXT"
- name: Dump strategy context
env:
STRATEGY_CONTEXT: ${{ toJSON(strategy) }}
run: echo "$STRATEGY_CONTEXT"
- name: Dump matrix context
env:
MATRIX_CONTEXT: ${{ toJSON(matrix) }}
run: echo "$MATRIX_CONTEXT"
- name: Set deployment status
uses: pbrandone/create-status-action@master
if: github.repository == 'KlubJagiellonski/pola-web' && github.event_name == 'pull_request' && github.event.sender.type == 'User'
with:
token: ${{ secrets.GITHUB_TOKEN }}
state: pending
description: Preparing deploy preview
context: Deploy Preview URL
- name: 'Set public URL'
if: github.repository == 'KlubJagiellonski/pola-web' && github.event_name == 'pull_request' && github.event.sender.type == 'User'
run: |
BASE_URL="http://${AWS_S3_BUCKET_PREVIEW}.s3-website.${{secrets.AWS_DEFAULT_REGION}}.amazonaws.com"
PREVIEW_DIR="$(echo "${GITHUB_HEAD_REF}" | tr -c '[:alnum:]._-' '-')"
PUBLIC_URL="${BASE_URL}/${PREVIEW_DIR}"
echo "PREVIEW_DIR=${PREVIEW_DIR}" >> $GITHUB_ENV
echo "PUBLIC_URL=${PUBLIC_URL}" >> $GITHUB_ENV
- name: 'Set public URL'
if: github.repository == 'KlubJagiellonski/pola-web' && github.event_name == 'push' && github.ref == 'refs/heads/prod'
run: |
echo 'PUBLIC_URL=https://www.pola-app.pl/' >> $GITHUB_ENV
# - name: 'Set public URL'
# if: |
# github.repository == 'KlubJagiellonski/pola-web' &&
# (
# ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) ||
# github.event_name == 'repository_dispatch'
# )
# run: |
# echo 'PUBLIC_URL=https://pola-staging.herokuapp.com/' >> $GITHUB_ENV
- name: 🗂 Checkout
uses: actions/checkout@v3
if: github.event_name == 'repository_dispatch'
with:
ref: 'prod'
- name: 🗂 Checkout
uses: actions/checkout@v3
if: github.event_name != 'repository_dispatch'
- name: 🟢 Use Node.js
uses: actions/[email protected]
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: 🟢 Install dependencies
run: npm ci
- name: 🔧 Build app
run: npm run build
env:
CONTENTFUL_SPACE_ID: ${{secrets.CONTENTFUL_SPACE_ID}}
CONTENTFUL_ACCESS_TOKEN: ${{secrets.CONTENTFUL_ACCESS_TOKEN}}
- name: 🚀 Upload app as artifact
uses: actions/upload-artifact@v2
with:
name: app
path: ./public
if-no-files-found: error
- name: 🟠 Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
if: |
github.repository == 'KlubJagiellonski/pola-web' &&
(
(github.event_name == 'pull_request' && github.event.sender.type == 'User') ||
(github.event_name == 'push' && github.ref == 'refs/heads/master') ||
(github.event_name == 'push' && github.ref == 'refs/heads/prod') ||
github.event_name == 'repository_dispatch'
)
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-session-name: GitHubActions-${{ github.run_id }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
# - name: 🚀 Upload staging app to AWS S3
# if: |
# github.repository == 'KlubJagiellonski/pola-web' &&
# (
# ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) ||
# github.event_name == 'repository_dispatch'
# )
# run: aws s3 sync --delete ./public/ "s3://${AWS_S3_BUCKET_STAG}/"
- name: 🚀 Upload production app to AWS S3
if: |
github.repository == 'KlubJagiellonski/pola-web' &&
(
( github.event_name == 'push' && github.ref == 'refs/heads/prod') ||
github.event_name == 'repository_dispatch'
)
run: aws s3 sync --delete ./public/ "s3://${AWS_S3_BUCKET_PROD}/"
- name: 🚀 Upload preview app to AWS S3
if: |
github.repository == 'KlubJagiellonski/pola-web' &&
(
( github.event_name == 'pull_request' && github.event.sender.type == 'User') ||
github.event_name == 'repository_dispatch'
)
run: aws s3 sync --delete ./public/ "s3://${AWS_S3_BUCKET_PREVIEW}/${PREVIEW_DIR}"
- name: Set success deployment status
if: |
success() && github.repository == 'KlubJagiellonski/pola-web' &&
(
( github.event_name == 'pull_request' && github.event.sender.type == 'User') ||
github.event_name == 'repository_dispatch'
)
uses: pbrandone/create-status-action@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
state: success
description: Deploy preview ready!
url: ${{ env.PUBLIC_URL }}
context: Deploy Preview URL
- name: Set failed deployment status
if: |
failure() && github.repository == 'KlubJagiellonski/pola-web' &&
(
( github.event_name == 'pull_request' && github.event.sender.type == 'User') ||
github.event_name == 'repository_dispatch'
)
uses: pbrandone/create-status-action@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
state: failure
description: Failed to deploy preview
context: Deploy Preview URL