-
-
Notifications
You must be signed in to change notification settings - Fork 19
233 lines (204 loc) Β· 8.59 KB
/
build.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
name: Database, Build and Deploy
on:
push:
branches:
# @todo Add properregex.
- 'feature/**'
pull_request:
branches:
# @todo Add properregex.
- 'feature/**'
# schedule:
# - cron: '0 18 * * *'
workflow_dispatch:
inputs:
enable_terminal:
type: boolean
description: 'Enable terminal session.'
required: false
default: false
defaults:
run:
shell: bash
jobs:
database:
runs-on: ubuntu-latest
container:
image: drevops/ci-runner:24.8.0
env:
TZ: Australia/Melbourne
TERM: xterm-256color
VORTEX_CONTAINER_REGISTRY_USER: ${{ secrets.VORTEX_CONTAINER_REGISTRY_USER }}
VORTEX_CONTAINER_REGISTRY_PASS: ${{ secrets.VORTEX_CONTAINER_REGISTRY_PASS }}
VORTEX_DEBUG: ${{ vars.VORTEX_DEBUG }}
#;< !PROVISION_USE_PROFILE
# How often to refresh the cache of the DB dump. Refer to `date` command.
VORTEX_CI_DB_CACHE_TIMESTAMP: +%Y%m%d
# Use previous database caches on this branch as a fallback if the above cache
# does not match (for example, the cache is available only from the previous
# day). If "no" is set, the cache will be rebuilt from scratch.
VORTEX_CI_DB_CACHE_FALLBACK: "yes"
# Which branch to use as a source of DB caches.
VORTEX_CI_DB_CACHE_BRANCH: "develop"
#;> !PROVISION_USE_PROFILE
steps:
- name: Preserve $HOME set in the container
run: echo HOME=/root >> "$GITHUB_ENV"
- name: Check out code
uses: actions/checkout@v4
- name: Process codebase to run in CI
run: |
find . -name "docker-compose.yml" -print0 | xargs -0 -I {} sh -c "sed -i -e '/###/d' {} && sed -i -e 's/##//' {}"
mkdir -p /tmp/workspace/code
- name: Create cache keys files for database caching
run: |
echo "${VORTEX_CI_DB_CACHE_BRANCH}" | tee db_cache_branch
echo "${VORTEX_CI_DB_CACHE_FALLBACK/no/"${GITHUB_RUN_NUMBER}"}" | tee db_cache_fallback
echo "yes" | tee db_cache_fallback_yes
echo "$(date "${VORTEX_CI_DB_CACHE_TIMESTAMP}")" | tee db_cache_timestamp
- name: Show cache key for database caching
run: echo 'v24.8.0-db10-${{ hashFiles('db_cache_branch') }}-${{ hashFiles('db_cache_fallback') }}-${{ hashFiles('db_cache_timestamp') }}'
# Restore DB cache based on the cache strategy set by the cache keys below.
# Change 'v1' to 'v2', 'v3' etc., commit and push to force cache reset.
# Lookup cache based on the default branch and a timestamp. Allows
# to use cache from the very first build on the day (sanitized database dump, for example).
- name: Restore DB cache
uses: actions/cache/restore@v4
with:
path: .data
key: v24.8.0-db10-${{ hashFiles('db_cache_branch') }}-${{ hashFiles('db_cache_fallback') }}-${{ hashFiles('db_cache_timestamp') }}
# Fallback to caching by default branch name only. Allows to use
# cache from the branch build on the previous day.
restore-keys: |
v24.8.0-db10-${{ hashFiles('db_cache_branch') }}-${{ hashFiles('db_cache_fallback') }}-
- name: Download DB
run: |
VORTEX_DB_DOWNLOAD_SEMAPHORE=/tmp/download-db-success ./scripts/vortex/download-db.sh
timeout-minutes: 30
- name: Calculate the database file hash
id: db-hash
run: echo "before=${{ hashFiles('.data') }}" >> "$GITHUB_ENV"
# - name: Export DB
# run: |
# [ ! -f /tmp/download-db-success ] && echo "==> Database download semaphore file is missing. DB export will not proceed." && exit 0
# ./scripts/vortex/login-container-registry.sh
# docker compose up --detach
# sleep 15
# docker compose exec cli mkdir -p .data && docker compose cp -L .data/db.sql cli:/app/.data/db.sql || true
# docker compose exec cli bash -c "VORTEX_PROVISION_POST_OPERATIONS_SKIP=1 ./scripts/vortex/provision.sh"
# ./scripts/vortex/export-db.sh db.sql
# timeout-minutes: 30
# continue-on-error: true
# Save cache per default branch and the timestamp.
# The cache will not be saved if it already exists.
# Note that the cache fallback flag is enabled for this case in order
# to save cache even if the fallback is not used when restoring it.
- name: Save DB cache
uses: actions/cache/save@v4
if: env.before != hashFiles('.data')
with:
path: .data
key: v24.8.0-db10-${{ hashFiles('db_cache_branch') }}-${{ hashFiles('db_cache_fallback_yes') }}-${{ hashFiles('db_cache_timestamp') }}
- name: Setup tmate session
if: ${{ !cancelled() && github.event.inputs.enable_terminal }}
uses: mxschmitt/action-tmate@v3
timeout-minutes: 5
with:
detached: true
build:
runs-on: ubuntu-latest
needs: database
# strategy:
# matrix:
# instance: [1, 2]
container:
image: drevops/ci-runner:24.8.0
env:
TZ: Australia/Melbourne
TERM: xterm-256color
VORTEX_CONTAINER_REGISTRY_USER: ${{ secrets.VORTEX_CONTAINER_REGISTRY_USER }}
VORTEX_CONTAINER_REGISTRY_PASS: ${{ secrets.VORTEX_CONTAINER_REGISTRY_PASS }}
VORTEX_DEBUG: ${{ vars.VORTEX_DEBUG }}
#;< !PROVISION_USE_PROFILE
# How often to refresh the cache of the DB dump. Refer to `date` command.
VORTEX_CI_DB_CACHE_TIMESTAMP: +%Y%m%d
# Use previous database caches on this branch as a fallback if the above cache
# does not match (for example, the cache is available only from the previous
# day). If "no" is set, the cache will be rebuilt from scratch.
VORTEX_CI_DB_CACHE_FALLBACK: "yes"
# Which branch to use as a source of DB caches.
VORTEX_CI_DB_CACHE_BRANCH: "develop"
#;> !PROVISION_USE_PROFILE
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Create cache keys files for database caching
run: |
echo "${VORTEX_CI_DB_CACHE_BRANCH}" | tee db_cache_branch
echo "yes" | tee db_cache_fallback_yes
echo "$(date ${VORTEX_CI_DB_CACHE_TIMESTAMP})" | tee db_cache_timestamp
- name: Show cache key for database caching
run: echo 'v24.8.0-db10-${{ hashFiles('db_cache_branch') }}-${{ hashFiles('db_cache_fallback_yes') }}-${{ hashFiles('db_cache_timestamp') }}'
# Restore DB cache based on the cache strategy set by the cache keys below.
# Change 'v1' to 'v2', 'v3' etc., commit and push to force cache reset.
# Lookup cache based on the default branch and a timestamp. Allows
# to use cache from the very first build on the day (sanitized database dump, for example).
- name: Restore DB cache
uses: actions/cache/restore@v4
with:
path: .data
fail-on-cache-miss: true
# Use cached database from previous builds of this branch.
key: v24.8.0-db10-${{ hashFiles('db_cache_branch') }}-${{ hashFiles('db_cache_fallback_yes') }}-${{ hashFiles('db_cache_timestamp') }}
restore-keys: |
v24.8.0-db10-${{ hashFiles('db_cache_branch') }}-${{ hashFiles('db_cache_fallback_yes') }}-
- run: ls -al .data || true
#
# - name: Process codebase to run in CI
# run: |
# find . -name "docker-compose.yml" -print0 | xargs -0 -I {} sh -c "sed -i -e '/###/d' {} && sed -i -e 's/##//' {}"
#
# - name: Build Stack
# run: docker compose up -d
#
# - name: Download Database as an artifact
# uses: actions/download-artifact@v4
# with:
# name: database
# path: .data/db.sql
#
# - run: ls -al .data
#
# - name: Run Tests
# run: |
# docker compose exec -T cli vendor/bin/phpunit
# docker compose exec -T cli vendor/bin/behat --profile=default
#
# - name: Store Artifacts
# run: |
# mkdir -p /tmp/artifacts
# docker compose cp cli:/app/.logs/. /tmp/artifacts/
# deploy:
# runs-on: ubuntu-latest
# needs: build
#
# container:
# image: drevops/ci-runner:24.8.0
# env:
# TZ: Australia/Melbourne
# TERM: xterm-256color
#
# steps:
# - name: Check out code
# uses: actions/checkout@v4
#
# - name: Process codebase
# run: |
# find . -name "docker-compose.yml" -print0 | xargs -0 -I {} sh -c "sed -i -e '/###/d' {} && sed -i -e 's/##//' {}"
# mkdir -p /tmp/workspace/code
#
# - name: Deploy
# run: |
# VORTEX_DEPLOY_BRANCH="${{ github.ref }}"
# ./scripts/vortex/deploy.sh
# timeout-minutes: 30