-
-
Notifications
You must be signed in to change notification settings - Fork 13
120 lines (117 loc) · 3.68 KB
/
php.yml
File metadata and controls
120 lines (117 loc) · 3.68 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
name: "PHP checks"
on:
pull_request:
push:
branches:
- main
permissions:
contents: read
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PHP 8.3
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: mbstring, pdo, sqlite
coverage: none # Use 'xdebug' or 'pcov' for code coverage
tools: composer
- name: validate configuration
run: composer validate
- name: composer install packages
run: composer install
- name: Lint
run: make lint-php-ci
- name: phpcs
run: make phpcs-ci
- name: audit dependencies
run: composer audit
test:
runs-on: ubuntu-latest
needs: lint
permissions:
contents: read
pull-requests: write
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test_twfy
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
ports:
- 3306:3306
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for SonarCloud analysis
- name: Checkout phplib
uses: actions/checkout@v4
with:
repository: openaustralia/phplib
path: phplib-checkout
ref: main
- name: Switch phplib to PR branch if it exists
run: git fetch origin ${{ github.head_ref || github.ref_name }} && git checkout ${{ github.head_ref || github.ref_name }} || echo "No PR branch found, using main"
working-directory: phplib-checkout
- name: Link phplib as sibling
run: ln -s ${{ github.workspace }}/phplib-checkout ../phplib
- name: Setup PHP 8.3
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: mbstring, mysqli
coverage: xdebug
tools: composer
- name: Install dependencies
run: composer install --no-interaction --prefer-dist
- name: Load database schema
run: |
mysql -h 127.0.0.1 -u root -proot test_twfy < db/schema.sql
- name: Run tests with coverage
run: |
set -o pipefail
XDEBUG_MODE=coverage ./vendor/bin/phpunit \
--coverage-text \
--coverage-clover=coverage/clover.xml \
--coverage-html=coverage/html \
--log-junit=coverage/junit.xml | tee phpunit-coverage.out
env:
DB_HOST: 127.0.0.1
DB_USER: root
DB_PASSWORD: root
DB_NAME: test_twfy
- name: Build coverage summary
run: |
{
echo "## Code Coverage"
echo
echo '```text'
if grep -q '^Code Coverage Report:' phpunit-coverage.out; then
sed -n '/^Code Coverage Report:/,$p' phpunit-coverage.out
else
echo "Coverage summary not found in phpunit output."
fi
echo '```'
} > code-coverage-results.md
- name: Add coverage to job summary
run: cat code-coverage-results.md >> "$GITHUB_STEP_SUMMARY"
- name: Post coverage comment on PR
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
recreate: true
path: code-coverage-results.md
# - name: SonarCloud Scan
# uses: SonarSource/sonarcloud-github-action@master
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}