-
Notifications
You must be signed in to change notification settings - Fork 2
124 lines (99 loc) · 4.34 KB
/
php-unit.yml
File metadata and controls
124 lines (99 loc) · 4.34 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
name: 'php-unit'
on:
workflow_call:
inputs:
php_versions:
description: PHP versions to use, string formatted as JSON array
required: true
type: string
bedita_version:
description: BEdita version to use, bedita/bedita docker release
required: true
type: string
coverage_min_percentage:
description: Minimum coverage percentage to pass the test
required: false
type: number
default: 85
jobs:
unit:
name: 'Run unit tests'
if: "!contains(github.event.commits[0].message, '[skip ci]') && !contains(github.event.commits[0].message, '[ci skip]')"
runs-on: 'ubuntu-latest'
env:
BEDITA_API_KEY: 12345
BEDITA_API: http://127.0.0.1:8080
BEDITA_ADMIN_USR: admin
BEDITA_ADMIN_PWD: admin
BEDITA_DOCKER_IMG: "bedita/bedita:${{ inputs.bedita_version }}"
strategy:
matrix:
php-version: ${{ fromJSON(inputs.php_versions) }}
steps:
- name: 'Install gettext'
run: 'sudo apt-get install -y gettext'
- name: 'Checkout current revision'
uses: 'actions/checkout@v6'
- name: 'Composer config GH token if available'
run: 'if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi'
- name: 'Docker pull bedita image'
run: 'docker pull ${BEDITA_DOCKER_IMG}'
- name: 'Docker inspect bedita image'
run: 'docker inspect ${BEDITA_DOCKER_IMG}'
- name: 'Docker run bedita image'
run: 'docker run --name api -d -p 127.0.0.1:8080:80 --env BEDITA_API_KEY=${BEDITA_API_KEY} --env BEDITA_ADMIN_USR=${BEDITA_ADMIN_USR} --env BEDITA_ADMIN_PWD=${BEDITA_ADMIN_PWD} ${BEDITA_DOCKER_IMG}'
- name: 'Wait for 10'
run: 'sleep 10'
- name: 'Docker ps - show all containers'
run: 'docker ps -a'
- name: 'Docker exec on api container: ls -la of webroot and webroot/_files'
run: 'docker exec api ls -la . webroot webroot/_files'
- name: 'Setup PHP'
uses: 'shivammathur/setup-php@v2'
with:
php-version: '${{ matrix.php-version }}'
tools: 'composer:v2'
extensions: 'mbstring, intl, pdo_mysql.pdo'
coverage: 'pcov'
ini-values: 'pcov.directory=., pcov.exclude="~vendor~"'
- name: 'Discover Composer cache directory'
id: 'cachedir'
run: echo "path=$(composer global config cache-dir)" >> $GITHUB_OUTPUT
- name: 'Share Composer cache across runs'
uses: 'actions/cache@v5'
with:
path: '${{ steps.cachedir.outputs.path }}'
key: "composer-${{ matrix.php-version }}-${{ hashFiles('**/composer.json') }}"
restore-keys: |
composer-${{ matrix.php-version }}-
composer-
- name: 'Install dependencies with Composer'
run: 'composer install --prefer-dist --no-interaction'
- name: 'Dump Composer autoloader'
run: 'composer dump-autoload --classmap-authoritative --no-cache'
- name: 'Set file prefix in environment'
run: echo "FILE_PREFIX=${{ github.run_id }}-${{ inputs.bedita_version }}-${{ matrix.php-version }}-${{ strategy.job-index }}" >> $GITHUB_ENV
- name: 'Run PHPUnit with coverage and JUnit report'
run: 'vendor/bin/phpunit --coverage-clover=${{ env.FILE_PREFIX }}-clover.xml --log-junit ${{ env.FILE_PREFIX }}-junit.xml'
- name: Upload test results to Codecov
uses: codecov/test-results-action@v1
with:
files: './${{ env.FILE_PREFIX }}-junit.xml'
token: ${{ secrets.CODECOV_TOKEN }}
- name: Check test coverage
id: test-coverage
uses: johanvanhelden/gha-clover-test-coverage-check@v1
with:
percentage: '${{ inputs.coverage_min_percentage }}'
filename: '${{ env.FILE_PREFIX }}-clover.xml'
- name: 'Export coverage results'
uses: 'codecov/codecov-action@v7'
with:
token: ${{ secrets.CODECOV_TOKEN }} # required
files: './${{ env.FILE_PREFIX }}-clover.xml'
env_vars: PHP_VERSION
- name: 'Archive code coverage results'
uses: 'actions/upload-artifact@v7'
with:
name: 'BEDITA-${{ inputs.bedita_version }}-PHP-${{ matrix.php-version }}-strategy-job-index-${{ strategy.job-index }}-${{ github.sha }}'
path: '${{ env.FILE_PREFIX }}-clover.xml'