-
Notifications
You must be signed in to change notification settings - Fork 58
127 lines (111 loc) · 5.16 KB
/
Copy pathphp-unit-tests.yml
File metadata and controls
127 lines (111 loc) · 5.16 KB
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
# +-------------------------------------------------------------------------+
# | Copyright (C) 2004-2026 The Cacti Group |
# | |
# | This program is free software; you can redistribute it and/or |
# | modify it under the terms of the GNU General Public License |
# | as published by the Free Software Foundation; either version 2 |
# | of the License, or (at your option) any later version. |
# | |
# | This program is distributed in the hope that it will be useful, |
# | but WITHOUT ANY WARRANTY; without even the implied warranty of |
# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
# | GNU General Public License for more details. |
# +-------------------------------------------------------------------------+
# | Cacti: The Complete RRDtool-based Graphing Solution |
# +-------------------------------------------------------------------------+
# | This code is designed, written, and maintained by the Cacti Group. See |
# | about.php and/or the AUTHORS file for specific developer information. |
# +-------------------------------------------------------------------------+
# | http://www.cacti.net/ |
# +-------------------------------------------------------------------------+
name: Pest Tests
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
unit-test:
name: Pest using Cacti Composer (Docker)
runs-on: ubuntu-latest
steps:
- name: Checkout Thold Plugin
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# patch-coverage.php diffs against the base branch.
fetch-depth: 0
- name: Checkout Cacti 1.2.31 runtime
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: Cacti/cacti
# Commit behind the annotated release/1.2.31 tag.
ref: 1e8eaca26b84b128c39ce8cc8ece42d7ff76aac1
path: cacti-runtime
- name: Checkout Cacti test toolchain
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: Cacti/cacti
# Pin Composer, Pest, the lock file, and Cacti's Docker test image.
ref: 298bd51eca843490fb90b27ada6b3fecc9b9a7d8
path: cacti-toolchain
# Build the same Linux image used by Cacti's tests/tools/docker_pest.sh.
# Composer installs and executes Cacti's locked Pest toolchain in /work;
# Thold contributes no parallel vendor directory or PHPUnit dependency.
- name: Build Cacti test image
run: |
for attempt in 1 2 3; do
if docker build --tag cacti-web --file cacti-toolchain/docker/Dockerfile cacti-toolchain/docker && \
docker build --tag cacti-thold-test --file cacti-toolchain/docker/Dockerfile.test cacti-toolchain; then
exit 0
fi
if [ "$attempt" -lt 3 ]; then
sleep 10
fi
done
echo 'Cacti test image build failed after three attempts.' >&2
exit 1
- name: Lint every PHP source file
run: |
docker run --rm --volume "$PWD":/work/plugins/thold \
--env COMPOSER_ROOT_VERSION=1.3.0-dev \
--entrypoint composer cacti-thold-test \
run-script lint /work/plugins/thold
- name: Run Pest with coverage
run: |
docker run --rm \
--volume "$PWD/cacti-runtime":/cacti \
--volume "$PWD":/cacti/plugins/thold \
--env COMPOSER_ROOT_VERSION=1.3.0-dev \
--env XDEBUG_MODE=coverage \
--user root \
--entrypoint composer cacti-thold-test \
test -- --configuration=/cacti/plugins/thold/phpunit.xml \
--coverage-clover=/cacti/plugins/thold/coverage/clover.xml \
/cacti/plugins/thold/tests/Unit
# Whole-file coverage is meaningless here: most of the plugin only runs
# inside a live Cacti. What is enforceable is that a change covers the
# lines it adds.
- name: Enforce coverage of changed lines
if: github.event_name == 'pull_request'
env:
BASE_REF: ${{ github.event.pull_request.base.sha }}
run: |
docker run --rm --volume "$PWD":/plugin --workdir /plugin \
--env BASE_REF --user root --entrypoint sh cacti-thold-test \
-c 'git config --global --add safe.directory /plugin && php tests/bin/patch-coverage.php coverage/clover.xml "$BASE_REF" 100'
- name: Upload coverage report
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: coverage
path: coverage/
if-no-files-found: warn