forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreusable-serviceless-phpunit-test.yml
More file actions
142 lines (128 loc) · 5.45 KB
/
reusable-serviceless-phpunit-test.yml
File metadata and controls
142 lines (128 loc) · 5.45 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Reusable workflow for PHPUnit testing
# without Docker services and databases
name: Reusable Serviceless PHPUnit Test
on:
workflow_call:
inputs:
job-name:
description: Name of the job to appear in GitHub UI
type: string
required: true
php-version:
description: The PHP version the workflow should run
type: string
required: true
job-id:
description: Job ID to be used as part of cache key and artifact name
type: string
required: false
group-name:
description: The @group to test
type: string
required: false
enable-artifact-upload:
description: Whether artifact uploading of coverage results should be enabled
type: boolean
required: false
enable-coverage:
description: Whether coverage should be enabled
type: boolean
required: false
enable-profiling:
description: Whether slow tests should be profiled
type: boolean
required: false
extra-extensions:
description: Additional PHP extensions that are needed to be enabled
type: string
required: false
extra-ini-options:
description: Additional PHP configuration directives that should be appended to the php.ini
type: string
required: false
extra-composer-options:
description: Additional Composer options that should be appended to the `composer update` call
type: string
required: false
extra-phpunit-options:
description: Additional PHPUnit options that should be appended to the `vendor/bin/phpunit` call
type: string
required: false
permissions:
contents: read
jobs:
tests:
name: ${{ inputs.job-name }}
runs-on: ubuntu-24.04
steps:
- name: Install latest ImageMagick
if: ${{ contains(inputs.extra-extensions, 'imagick') }}
run: |
sudo apt-get update
sudo apt-get install -y imagemagick libmagickwand-dev ghostscript poppler-data libjbig2dec0:amd64 libopenjp2-7:amd64
- name: Checkout base branch for PR
if: github.event_name == 'pull_request'
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ github.base_ref }}
persist-credentials: false
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
fetch-depth: 0
- name: Setup PHP
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0
with:
php-version: ${{ inputs.php-version }}
tools: composer
extensions: gd, ${{ inputs.extra-extensions }}
ini-values: ${{ inputs.extra-ini-options }}
coverage: ${{ env.COVERAGE_DRIVER }}
env:
COVERAGE_DRIVER: ${{ inputs.enable-coverage && 'xdebug' || 'none' }}
- name: Setup global environment variables
id: setup-env
run: |
echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
echo "ARTIFACT_NAME=${{ inputs.job-id || github.job }}-php-${{ inputs.php-version }}" >> $GITHUB_OUTPUT
- name: Cache Composer dependencies
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: ${{ steps.setup-env.outputs.COMPOSER_CACHE_FILES_DIR }}
key: ${{ inputs.job-id || github.job }}-php-${{ inputs.php-version }}-${{ hashFiles('**/composer.*') }}
restore-keys: |
${{ inputs.job-id || github.job }}-php-${{ inputs.php-version }}-
${{ inputs.job-id || github.job }}-
- name: Cache PHPUnit's static analysis cache
if: ${{ inputs.enable-artifact-upload }}
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: build/.phpunit.cache/code-coverage
key: phpunit-code-coverage-${{ hashFiles('**/phpunit.*') }}
restore-keys: |
phpunit-code-coverage-
- name: Install dependencies
run: |
composer config --global github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
composer update --ansi ${{ inputs.extra-composer-options }}
- name: Compute additional PHPUnit options
id: phpunit-options
run: |
echo "EXTRA_PHPUNIT_OPTIONS=${{ format('{0} {1} {2}', env.GROUP_OPTION, env.COVERAGE_OPTION, inputs.extra-phpunit-options) }}" >> $GITHUB_OUTPUT
env:
COVERAGE_OPTION: ${{ inputs.enable-coverage && format('--coverage-php build/cov/coverage-{0}.cov', steps.setup-env.outputs.ARTIFACT_NAME) || '--no-coverage' }}
GROUP_OPTION: ${{ inputs.group-name && format('--group {0}', inputs.group-name) || '' }}
- name: Run tests
run: script -e -c "vendor/bin/phpunit --color=always ${{ steps.phpunit-options.outputs.EXTRA_PHPUNIT_OPTIONS }}"
env:
TACHYCARDIA_MONITOR_GA: ${{ inputs.enable-profiling && 'enabled' || '' }}
TERM: xterm-256color
- name: Upload coverage results as artifact
if: ${{ inputs.enable-artifact-upload }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ${{ steps.setup-env.outputs.ARTIFACT_NAME }}
path: build/cov/coverage-${{ steps.setup-env.outputs.ARTIFACT_NAME }}.cov
if-no-files-found: error
retention-days: 1