-
Notifications
You must be signed in to change notification settings - Fork 4
293 lines (253 loc) · 9.92 KB
/
build_test_and_deploy.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
name: Build, test and deploy
on:
push:
branches:
- main
pull_request:
branches:
- main
defaults:
run:
shell: bash
env:
TZ: "/usr/share/zoneinfo/America/Los_Angeles"
NOTIFY: 'scripts/github/add-commit-comment {project} {sha} "Created multidev environment [{site}#{env}]({dashboard-url})." {site-url}'
TERM: dumb
GITHUB_TOKEN: ${{ github.token }}
TERMINUS_TOKEN: ${{ secrets.TERMINUS_TOKEN }}
TERMINUS_SITE: ${{ secrets.TERMINUS_SITE }}
TERMINUS_SITE2: ${{ secrets.TERMINUS_SITE2 }}
BASH_ENV: "./bash_env.txt"
GITHUB_REF: ${{ github.ref }}
COMMIT_SHA: ${{ github.sha }}
CI_BUILD_NUMBER: ${{ github.run_number }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
GITHUB_OWNER: ${{ github.repository_owner }}
CI_PROJECT_NAME: ${{ github.repository }}
DEFAULT_BRANCH: "main"
jobs:
configure_env_vars:
container:
image: quay.io/pantheon-public/build-tools-ci:6.x
options: --user root
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache bash_env.txt
uses: actions/cache@v4
env:
cache-name: cache-bash-env
with:
path: bash_env.txt
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.run_number }}
# Set TERMINUS_ENV and related environment variables.
# https://github.com/pantheon-systems/docker-build-tools-ci/blob/6.x/scripts/set-environment
- name: setup-environment-vars
run: |
echo '1' $GITHUB_REF
if [[ "$GITHUB_REF" =~ ^refs/pull/([0-9]+)/merge$ ]]; then
export PR_NUMBER=${BASH_REMATCH[1]}
echo '2' $PR_NUMBER
export CI_BRANCH=`curl -u "${GITHUB_OWNER}:${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.groot-preview+json" \
"https://api.github.com/repos/${CI_PROJECT_NAME}/pulls/${PR_NUMBER}" | \
python3 -c "import sys, json; print(json.load(sys.stdin)['head']['ref'])"`
export CI_PULL_REQUEST=`curl -u "${GITHUB_OWNER}:${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.groot-preview+json" \
"https://api.github.com/repos/${CI_PROJECT_NAME}/pulls/${PR_NUMBER}" | \
python3 -c "import sys, json; print(json.load(sys.stdin)['html_url'])"`
elif [ "$GITHUB_REF" != "refs/heads/main" ]; then
echo '3'
export PR_NUMBER=`curl -u "${GITHUB_OWNER}:${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.groot-preview+json" \
"https://api.github.com/repos/${CI_PROJECT_NAME}/commits/${COMMIT_SHA}/pulls" | \
python3 -c "import sys, json; print(json.load(sys.stdin)[0]['number'])"`
export CI_BRANCH=`curl -u "${GITHUB_OWNER}:${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.groot-preview+json" \
"https://api.github.com/repos/${CI_PROJECT_NAME}/commits/${COMMIT_SHA}/pulls" | \
python3 -c "import sys, json; print(json.load(sys.stdin)[0]['head']['ref'])"`
export CI_PULL_REQUEST=`curl -u "${GITHUB_OWNER}:${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.groot-preview+json" \
"https://api.github.com/repos/${CI_PROJECT_NAME}/commits/${COMMIT_SHA}/pulls" | \
python3 -c "import sys, json; print(json.load(sys.stdin)[0]['html_url'])"`
else
echo '4'
export CI_BRANCH="main"
fi
echo '5'
export CI_PROJECT_REPONAME="${CI_PROJECT_NAME#*/}"
export CI_PROJECT_USERNAME=$GITHUB_REPOSITORY_OWNER
/build-tools-ci/scripts/set-environment
GITHUB_WORKFLOW_URL=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
echo "export CI_BUILD_URL='${GITHUB_WORKFLOW_URL}'" >> $BASH_ENV
echo "export CI_NODE_INDEX=0" >> $BASH_ENV
echo "export CI_REPOSITORY_URL='https://github.com/${GITHUB_REPOSITORY}'" >> $BASH_ENV
echo "export ARTIFACTS_DIR_URL='${GITHUB_WORKFLOW_URL}/#artifacts'" >> $BASH_ENV
build_php:
container:
image: quay.io/pantheon-public/build-tools-ci:6.x
options: --user root
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache composer cache
uses: actions/cache@v4
env:
cache-name: cache-composer-cache
with:
path: ~/.composer/cache
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('composer.lock') }}
- name: Cache vendor folder
uses: actions/cache@v4
env:
cache-name: cache-vendor
with:
path: ./vendor
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('composer.lock') }}
- name: Cache web folder
uses: actions/cache@v4
env:
cache-name: cache-web
with:
path: ./web
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.sha }}
# Set TERMINUS_ENV and related environment variables.
# https://github.com/pantheon-systems/docker-build-tools-ci/blob/6.x/scripts/set-environment
- name: setup-environment-vars
run: /build-tools-ci/scripts/set-environment
- name: run PHP build step
run: composer -n build-assets
code_sniff_unit_test:
runs-on: ubuntu-latest
container:
image: quay.io/pantheon-public/build-tools-ci:6.x
options: --user root
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build dev dependencies
run: composer install --no-ansi --no-interaction --optimize-autoloader --no-progress
- name: Check code with WordPress coding standards
run: composer -n code-sniff
deploy_to_pantheon_lfasiallcci:
container:
image: quay.io/pantheon-public/build-tools-ci:6.x
options: --user root
runs-on: ubuntu-latest
needs: [configure_env_vars, build_php]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache bash_env.txt
uses: actions/cache@v4
env:
cache-name: cache-bash-env
with:
path: bash_env.txt
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.run_number }}
- name: Cache composer cache
uses: actions/cache@v4
env:
cache-name: cache-composer-cache
with:
path: ~/.composer/cache
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('composer.lock') }}
- name: Cache vendor folder
uses: actions/cache@v4
env:
cache-name: cache-vendor
with:
path: ./vendor
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('composer.lock') }}
- name: Cache web folder
uses: actions/cache@v4
env:
cache-name: cache-web
with:
path: ./web
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.sha }}
# Set TERMINUS_ENV and related environment variables.
# https://github.com/pantheon-systems/docker-build-tools-ci/blob/6.x/scripts/set-environment
- name: setup-environment-vars
run: /build-tools-ci/scripts/set-environment
# Rsync the build artifact pieces web directory
- name: sync build artifact
run: rsync -rz ./web ./vendor .
- uses: actions/setup-node@v4
with:
node-version: '14.21.3'
- name: Compile css/js
run: cd ./web/wp-content/themes/lfevents/; npm install; npm run build
# Deploy to Pantheon
- name: deploy to Pantheon
run: |
echo "$SSH_PRIVATE_KEY" > ../private.key
chmod 600 ../private.key
eval `ssh-agent -s`
ssh-add ../private.key
source $BASH_ENV
./.github/workflows/pantheon-deploy $TERMINUS_SITE2
deploy_to_pantheon_lfeventsci:
container:
image: quay.io/pantheon-public/build-tools-ci:6.x
options: --user root
runs-on: ubuntu-latest
needs: [configure_env_vars, build_php]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache bash_env.txt
uses: actions/cache@v4
env:
cache-name: cache-bash-env
with:
path: bash_env.txt
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.run_number }}
- name: Cache composer cache
uses: actions/cache@v4
env:
cache-name: cache-composer-cache
with:
path: ~/.composer/cache
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('composer.lock') }}
- name: Cache vendor folder
uses: actions/cache@v4
env:
cache-name: cache-vendor
with:
path: ./vendor
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('composer.lock') }}
- name: Cache web folder
uses: actions/cache@v4
env:
cache-name: cache-web
with:
path: ./web
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.sha }}
# Set TERMINUS_ENV and related environment variables.
# https://github.com/pantheon-systems/docker-build-tools-ci/blob/6.x/scripts/set-environment
- name: setup-environment-vars
run: /build-tools-ci/scripts/set-environment
# Rsync the build artifact pieces web directory
- name: sync build artifact
run: rsync -rz ./web ./vendor .
- uses: actions/setup-node@v4
with:
node-version: '14.21.3'
- name: Compile css/js
run: cd ./web/wp-content/themes/lfevents/; npm install; npm run build
# Deploy to Pantheon
- name: deploy to Pantheon
run: |
echo "$SSH_PRIVATE_KEY" > ../private.key
chmod 600 ../private.key
eval `ssh-agent -s`
ssh-add ../private.key
source $BASH_ENV
./.github/workflows/pantheon-deploy $TERMINUS_SITE