-
Notifications
You must be signed in to change notification settings - Fork 62
289 lines (251 loc) · 12.2 KB
/
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
name: CI Pipeline
on:
push:
branches:
- main
- tooling/github-actions
pull_request:
jobs:
prepare_test_and_build_environment:
runs-on: ubuntu-latest
env:
HOME: /home/runner
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Log Repository Structure
run: |
echo "Repository structure (GITHUB_WORKSPACE):"
tree -L 2 "${GITHUB_WORKSPACE}" || find "${GITHUB_WORKSPACE}" -maxdepth 2 -type d
- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Authenticate with GitHub CLI
env:
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
run: echo "$GH_ACCESS_TOKEN" | gh auth login --with-token
- name: Clone GV Tooling
run: gh repo clone GravityKit/Tooling $HOME/tooling
- name: Log Tooling Structure
run: |
echo "Tooling directory structure ($HOME/tooling):"
tree -L 2 "$HOME/tooling" || find "$HOME/tooling" -maxdepth 2 -type d
# Create .env file in docker-unit-tests folder with PLUGIN_DIR set to the repository root
- name: Create .env file in docker-unit-tests if missing
run: |
mkdir -p "$HOME/tooling/docker-unit-tests"
if [ ! -f "$HOME/tooling/docker-unit-tests/.env" ]; then
echo "PLUGIN_DIR=${GITHUB_WORKSPACE}" > "$HOME/tooling/docker-unit-tests/.env"
echo "WP_LATEST_TESTS_DIR=$HOME/wordpress-latest-tests-lib" >> "$HOME/tooling/docker-unit-tests/.env"
echo "PHPUNIT_DIR=$HOME/phpunit" >> "$HOME/tooling/docker-unit-tests/.env"
echo "GF_PLUGIN_DIR=$HOME/gravityforms" >> "$HOME/tooling/docker-unit-tests/.env"
echo "GH_AUTH_TOKEN=${{ secrets.GH_ACCESS_TOKEN }}" >> "$HOME/tooling/docker-unit-tests/.env"
fi
echo "Content of $HOME/tooling/docker-unit-tests/.env:"
cat "$HOME/tooling/docker-unit-tests/.env"
- name: Authenticate GitHub for Composer
env:
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
run: composer config --global --auth github-oauth.github.com "$GH_ACCESS_TOKEN"
- name: Ensure test_dependencies directory exists
run: mkdir -p $HOME/test_dependencies
- name: Cache Dependencies
uses: actions/cache@v4
with:
path: $HOME/test_dependencies
key: test-dependencies-${{ runner.os }}-${{ hashFiles('composer.lock', 'package-lock.json') }}
restore-keys: |
test-dependencies-${{ runner.os }}-
- name: Force Composer to Use HTTPS
run: composer config --global github-protocols https
- name: Install Build Dependencies
run: |
$HOME/tooling/build-tools/build_tools.sh npm -o install
$HOME/tooling/build-tools/build_tools.sh composer -o install
- name: Configure Test Environment
env:
GH_AUTH_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
run: bash $HOME/tooling/docker-unit-tests/docker-unit-tests.sh prepare_all
- name: Log WP Latest Tests Lib Structure
run: |
echo "Contents of wordpress-latest-tests-lib ($HOME/wordpress-latest-tests-lib):"
tree -L 2 "$HOME/wordpress-latest-tests-lib" || find "$HOME/wordpress-latest-tests-lib" -maxdepth 2 -type d
# Persist workspace artifact including test suites
- name: Prepare Workspace Artifact
run: |
mkdir -p workspace_artifact
cp -R $HOME/tooling workspace_artifact/
cp -R $HOME/test_dependencies workspace_artifact/
if [ -d "$HOME/wordpress-latest-tests-lib" ]; then
cp -R $HOME/wordpress-latest-tests-lib workspace_artifact/
else
echo "wordpress-latest-tests-lib not found"
fi
echo "Workspace artifact structure:"
tree -L 2 workspace_artifact || find workspace_artifact -maxdepth 2 -type d
- name: Save Workspace
uses: actions/upload-artifact@v4
with:
name: workspace
path: workspace_artifact
if-no-files-found: warn
compression-level: 6
overwrite: false
include-hidden-files: true
run_php_74_unit_tests:
runs-on: ubuntu-latest
env:
HOME: /home/runner
needs: prepare_test_and_build_environment
steps:
- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Restore Workspace
uses: actions/download-artifact@v4
with:
name: workspace
path: /tmp/workspace/
- name: Extract Workspace Artifact
run: |
if [ -d /tmp/workspace/workspace_artifact ]; then
rsync -a /tmp/workspace/workspace_artifact/ $HOME/
else
rsync -a /tmp/workspace/ $HOME/
fi
echo "Directory structure after extraction:"
tree -L 2 "$HOME" || find "$HOME" -maxdepth 2 -type d
- name: Verify .env file in docker-unit-tests exists
run: |
if [ -f "$HOME/tooling/docker-unit-tests/.env" ]; then
echo ".env file exists in $HOME/tooling/docker-unit-tests"
else
echo ".env file missing in $HOME/tooling/docker-unit-tests" >&2
exit 1
fi
- name: Ensure phpunit.xml exists in PLUGIN_DIR
run: |
source "$HOME/tooling/docker-unit-tests/.env"
if [ ! -f "$PLUGIN_DIR/phpunit.xml" ] && [ -f "$PLUGIN_DIR/phpunit.xml.dist" ]; then
cp "$PLUGIN_DIR/phpunit.xml.dist" "$PLUGIN_DIR/phpunit.xml"
echo "Created phpunit.xml from phpunit.xml.dist"
else
echo "phpunit.xml exists or phpunit.xml.dist not found."
fi
- name: Run PHP 7.4 Unit Tests
run: |
export ENV_FILE="$HOME/tooling/docker-unit-tests/.env"
bash $HOME/tooling/docker-unit-tests/docker-unit-tests.sh test_74
run_php_80_unit_tests:
runs-on: ubuntu-latest
env:
HOME: /home/runner
needs: prepare_test_and_build_environment
steps:
- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Restore Workspace
uses: actions/download-artifact@v4
with:
name: workspace
path: /tmp/workspace/
- name: Extract Workspace Artifact
run: |
if [ -d /tmp/workspace/workspace_artifact ]; then
rsync -a /tmp/workspace/workspace_artifact/ $HOME/
else
rsync -a /tmp/workspace/ $HOME/
fi
echo "Directory structure after extraction:"
tree -L 2 "$HOME" || find "$HOME" -maxdepth 2 -type d
- name: Verify .env file in docker-unit-tests exists
run: |
if [ -f "$HOME/tooling/docker-unit-tests/.env" ]; then
echo ".env file exists in $HOME/tooling/docker-unit-tests"
else
echo ".env file missing in $HOME/tooling/docker-unit-tests" >&2
exit 1
fi
- name: Check Test Suite Configuration
run: |
source $HOME/tooling/docker-unit-tests/.env
echo "Listing WP_LATEST_TESTS_DIR ($WP_LATEST_TESTS_DIR) contents:"
tree -L 2 "$WP_LATEST_TESTS_DIR" || find "$WP_LATEST_TESTS_DIR" -maxdepth 2 -type d
if [ ! -f "$WP_LATEST_TESTS_DIR/wp-tests-config.php" ]; then
echo "wp-tests-config.php not found in $WP_LATEST_TESTS_DIR" >&2
exit 1
else
echo "Test suite is configured."
fi
- name: Ensure phpunit.xml exists in PLUGIN_DIR
run: |
source "$HOME/tooling/docker-unit-tests/.env"
if [ ! -f "$PLUGIN_DIR/phpunit.xml" ] && [ -f "$PLUGIN_DIR/phpunit.xml.dist" ]; then
cp "$PLUGIN_DIR/phpunit.xml.dist" "$PLUGIN_DIR/phpunit.xml"
echo "Created phpunit.xml from phpunit.xml.dist"
else
echo "phpunit.xml exists or phpunit.xml.dist not found."
fi
- name: Run PHP 8.0 Unit Tests
run: |
export ENV_FILE="$HOME/tooling/docker-unit-tests/.env"
bash $HOME/tooling/docker-unit-tests/docker-unit-tests.sh test_80
build_package_release:
runs-on: ubuntu-latest
env:
HOME: /home/runner
needs: [run_php_74_unit_tests, run_php_80_unit_tests]
steps:
- name: Restore Workspace
uses: actions/download-artifact@v4
with:
name: workspace
path: /tmp/workspace/
- name: Extract Workspace Artifact
run: |
if [ -d /tmp/workspace/workspace_artifact ]; then
rsync -a /tmp/workspace/workspace_artifact/ $HOME/
else
rsync -a /tmp/workspace/ $HOME/
fi
echo "Final workspace structure:"
tree -L 2 "$HOME" || find "$HOME" -maxdepth 2 -type d
- name: Build and Package
run: |
BRANCH_REF="${{ github.ref }}"
$HOME/tooling/build-tools/build_tools.sh composer -o "install --no-dev"
$HOME/tooling/build-tools/build_tools.sh grunt
if [[ "$BRANCH_REF" != "refs/heads/main" ]]; then
$HOME/tooling/build-tools/build_tools.sh package_build -o "gravityview gravityview.php --include-hash"
else
$HOME/tooling/build-tools/build_tools.sh package_build -o "gravityview gravityview.php $([[ $(git log -n 1 | grep "\[skip release\]") ]] && echo --include-hash)"
fi
mkdir -p gravityview
cp -R vendor* gravityview
rm gravityview/vendor_prefixed/gravitykit/foundation/src/translations.js.php
zip -gr $(ls gravityview-*.zip) gravityview
mkdir .release
cp gravityview-*.zip .release
- name: Store Release Artifacts
uses: actions/upload-artifact@v4
with:
name: release
path: .release
- name: Create GitHub Release
if: github.ref == 'refs/heads/main'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.email "support@gravitykit.com"
git config user.name "GravityView - CI"
$HOME/tooling/build-tools/build_tools.sh create_release -o "gravityview gravityview.php $(ls gravityview-*.zip)"
- name: Notify GravityView Release Manager
if: github.ref == 'refs/heads/main'
run: |
if ! git log -n 1 | grep "\[skip notify\]"; then
$HOME/tooling/build-tools/build_tools.sh announce_build -o "gravityview gravityview.php $(ls gravityview-*.zip) --with-circle"
fi