-
-
Notifications
You must be signed in to change notification settings - Fork 2
299 lines (247 loc) · 9.72 KB
/
test-php.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
293
294
295
296
297
298
299
name: Test PHP
on:
push:
branches:
- main
pull_request:
branches:
- main
- 'feature/**'
jobs:
test-php:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.2', '8.3']
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
- name: Setup SSH private key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
- name: Configure Git
run: |
git config --global user.name "${{ secrets.DEPLOY_USER_NAME }}"
git config --global user.email "${{ secrets.DEPLOY_USER_EMAIL }}"
- name: Install dependencies
run: composer install
- name: Check coding standards
run: composer lint
- name: Run tests
run: XDEBUG_MODE=coverage composer test
- name: Upload coverage report as an artifact
uses: actions/upload-artifact@v4
with:
name: ${{github.job}}-code-coverage-report-${{ matrix.php-versions }}
path: ./.coverage-html
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v5
with:
files: ./cobertura.xml
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
build-php:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
- name: Install dependencies
run: composer install
- name: Check composer version
run: composer --version
- name: Build PHAR
run: composer build
- name: Test PHAR
run: ./.build/git-artifact --help || exit 1
# Demonstration of deployment in 'force-push' mode.
deploy-force-push:
needs:
- test-php
- build-php
runs-on: ubuntu-latest
env:
GITHUB_BRANCH: ${{ github.head_ref || github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# Fetch all history for git repository.
fetch-depth: 0
# Do not persist credentials after checkout
# to allow to use custom credentials to push to a remote repo.
persist-credentials: false
ref: ${{ github.head_ref }}
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
- name: Setup SSH private key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
- name: Configure Git
run: |
git config --global user.name "${{ secrets.DEPLOY_USER_NAME }}"
git config --global user.email "${{ secrets.DEPLOY_USER_EMAIL }}"
- name: Install dependencies
run: composer install
# Test file will have a consistent name between deployments, but
# the contents will be added to on each deployment to simulate
# changes in the source repository.
- name: Prepare test file.
run: |
export TEST_FILE="test-file--force-push--gha--${GITHUB_BRANCH//\//-}.txt"
echo "Deployment 1 for branch $GITHUB_BRANCH" > $TEST_FILE
date "+%Y%m%d-%H%M%S" >> $TEST_FILE
cat $TEST_FILE
echo $TEST_FILE > $HOME/test-file.txt
- name: Deployment 1
run: |
./git-artifact \
[email protected]:drevops/git-artifact-destination.git \
--branch=mode--force-push--gha--[branch] \
--mode=force-push \
--log=$HOME/report--mode--force-push.txt \
-vvv
DEPLOYED_BRANCH=$(sed -n 's/Remote branch://p' $HOME/report--mode--force-push.txt | sed 's/ //g')
echo "Deployed to $DEPLOYED_BRANCH"
echo
echo "See https://github.com/drevops/git-artifact-destination/blob/$DEPLOYED_BRANCH/$(cat $HOME/test-file.txt)"
rm $HOME/report--mode--force-push.txt
- name: Update the test file to simulate changes in the source repository.
run: |
export TEST_FILE="test-file--force-push--gha--${GITHUB_BRANCH//\//-}.txt"
echo "Deployment 2 for branch $GITHUB_BRANCH" > $TEST_FILE
date "+%Y%m%d-%H%M%S" >> $TEST_FILE
cat $TEST_FILE
- name: Deployment 2
run: |
./git-artifact \
[email protected]:drevops/git-artifact-destination.git \
--branch=mode--force-push--gha--[branch] \
--mode=force-push \
--log=$HOME/report--mode--force-push.txt \
-vvv
DEPLOYED_BRANCH=$(sed -n 's/Remote branch://p' $HOME/report--mode--force-push.txt | sed 's/ //g')
echo "Deployed to $DEPLOYED_BRANCH"
echo
echo "See https://github.com/drevops/git-artifact-destination/blob/$DEPLOYED_BRANCH/$(cat $HOME/test-file.txt)"
# Demonstration of deployment in 'branch' mode.
# Note that by design, pushing into the same branch will result in the failure
# of the second push. This is because the mode is intended to create a new
# branch per artifact deployment.
deploy-branch:
needs:
- test-php
- build-php
runs-on: ubuntu-latest
env:
GITHUB_BRANCH: ${{ github.head_ref || github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# Fetch all history for git repository.
fetch-depth: 0
# Do not persist credentials after checkout
# to allow to use custom credentials to push to a remote repo.
persist-credentials: false
ref: ${{ github.head_ref }}
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
- name: Setup SSH private key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
- name: Configure Git
run: |
git config --global user.name "${{ secrets.DEPLOY_USER_NAME }}"
git config --global user.email "${{ secrets.DEPLOY_USER_EMAIL }}"
- name: Install dependencies
run: composer install
# Test file will have a consistent name between deployments, but
# the contents will be added to on each deployment to simulate
# changes in the source repository.
# Since each deployment in this mode creates a new branch, the test file
# will be pushed to a new branch each time and won't be updated in
# existing branches.
- name: Prepare test file.
run: |
export TEST_FILE="test-file--branch--gha--${GITHUB_BRANCH//\//-}.txt"
echo "Deployment 1 for branch $GITHUB_BRANCH" > $TEST_FILE
date "+%Y%m%d-%H%M%S" >> $TEST_FILE
cat $TEST_FILE
echo $TEST_FILE > $HOME/test-file.txt
- name: Deployment 1
run: |
./git-artifact \
[email protected]:drevops/git-artifact-destination.git \
--branch=mode--branch--gha--[branch]--[timestamp:Y-m-d_H-i] \
--mode=branch \
--log=$HOME/report--mode--branch.txt \
-vvv
DEPLOYED_BRANCH=$(sed -n 's/Remote branch://p' $HOME/report--mode--branch.txt | sed 's/ //g')
echo "Deployed to $DEPLOYED_BRANCH"
echo
echo "See https://github.com/drevops/git-artifact-destination/blob/$DEPLOYED_BRANCH/$(cat $HOME/test-file.txt)"
rm $HOME/report--mode--branch.txt
- name: Update the test file to simulate changes in the source repository.
run: |
export TEST_FILE="test-file--branch--gha--${GITHUB_BRANCH//\//-}.txt"
echo "Deployment 2 for branch $GITHUB_BRANCH" > $TEST_FILE
date "+%Y%m%d-%H%M%S" >> $TEST_FILE
cat $TEST_FILE
- name: Deployment 2 - same branch
run: |
./git-artifact \
[email protected]:drevops/git-artifact-destination.git \
--branch=mode--branch--gha--[branch]--[timestamp:Y-m-d_H-i] \
--mode=branch \
--log=$HOME/report--mode--branch.txt \
-vvv \
&& { echo "Expected to fail as repeated pushes to the same branch are not allowed, but succeeded" >&2; exit 1; } || echo "Failed as expected"
- name: Deployment 2 - new branch
run: |
./git-artifact \
[email protected]:drevops/git-artifact-destination.git \
--branch=mode--branch--gha--[branch]--[timestamp:Y-m-d_H-i-s] \
--mode=branch \
--log=$HOME/report--mode--branch.txt \
-vvv
DEPLOYED_BRANCH=$(sed -n 's/Remote branch://p' $HOME/report--mode--branch.txt | sed 's/ //g')
echo "Deployed to $DEPLOYED_BRANCH"
echo
echo "See https://github.com/drevops/git-artifact-destination/blob/$DEPLOYED_BRANCH/$(cat $HOME/test-file.txt)"