Skip to content

Commit 73f3a1c

Browse files
committed
Imported the shared workflows.
0 parents  commit 73f3a1c

File tree

7 files changed

+333
-0
lines changed

7 files changed

+333
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "phpunit-coverage-check",
5+
"pattern": [
6+
{
7+
"regexp": "(Total code coverage is .* % which is below the accepted .*)",
8+
"message": 1
9+
}
10+
]
11+
}
12+
]
13+
}

.github/scripts/build-matrix.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$versions = explode(' ', getenv('PHP_VERSIONS'));
6+
$minVersion = getenv('MIN_PHP_VERSION');
7+
$suites = [];
8+
9+
if (file_exists('vendor/bin/phpunit')) {
10+
$output = shell_exec('vendor/bin/phpunit --list-suites');
11+
if (preg_match_all('#^ - (.*)$#m', $output, $matches)) {
12+
$suites = array_map('trim', $matches[1]);
13+
}
14+
}
15+
16+
$matrix = [];
17+
if (count($versions) > 0 && count($suites) > 0) {
18+
foreach ($suites as $suite) {
19+
foreach ($versions as $version) {
20+
if ($version !== 'all' && floatval($version) < floatval($minVersion)) {
21+
continue;
22+
}
23+
24+
$matrix[] = [
25+
'suite' => $suite,
26+
'version' => $version,
27+
];
28+
}
29+
}
30+
}
31+
echo json_encode($matrix);
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: CI PHP General
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
extensions:
7+
type: string
8+
description: The comma-separated list of extensions to install.
9+
default: ""
10+
required: false
11+
php-version:
12+
type: string
13+
description: The version of PHP to use for the general tasks.
14+
default: "8.0"
15+
required: false
16+
17+
jobs:
18+
composer-validation:
19+
name: Composer Validation
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v2
24+
25+
- name: Setup PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: ${{ inputs.php-version }}
29+
coverage: none
30+
extensions: ${{ inputs.extensions }}
31+
32+
- name: Run composer validate
33+
run: composer validate --strict
34+
35+
coding-guidelines:
36+
name: Coding Guidelines
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v2
41+
42+
- name: Setup PHP
43+
uses: shivammathur/setup-php@v2
44+
with:
45+
php-version: ${{ inputs.php-version }}
46+
coverage: none
47+
extensions: ${{ inputs.extensions }}
48+
tools: cs2pr
49+
50+
- name: Get composer cache directory
51+
id: composer-cache
52+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
53+
54+
- name: Cache composer dependencies
55+
uses: actions/cache@v2
56+
with:
57+
path: ${{ steps.composer-cache.outputs.dir }}
58+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
59+
restore-keys: ${{ runner.os }}-composer-
60+
61+
- name: Install dependencies
62+
run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
63+
64+
- name: Run phpcs
65+
run: vendor/bin/phpcs -q --report=checkstyle | cs2pr
66+
67+
type-checker:
68+
name: Type Checker
69+
runs-on: ubuntu-latest
70+
steps:
71+
- name: Checkout
72+
uses: actions/checkout@v2
73+
74+
- name: Setup PHP
75+
uses: shivammathur/setup-php@v2
76+
with:
77+
php-version: ${{ inputs.php-version }}
78+
coverage: none
79+
extensions: ${{ inputs.extensions }}
80+
81+
- name: Get composer cache directory
82+
id: composer-cache
83+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
84+
85+
- name: Cache composer dependencies
86+
uses: actions/cache@v2
87+
with:
88+
path: ${{ steps.composer-cache.outputs.dir }}
89+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
90+
restore-keys: ${{ runner.os }}-composer-
91+
92+
- name: Install dependencies
93+
run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
94+
95+
- name: Run phpstan
96+
run: vendor/bin/phpstan analyse --no-interaction
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
name: CI PHP Tests
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
extensions:
7+
type: string
8+
description: The comma-separated list of extensions to install.
9+
default: ""
10+
required: false
11+
php-versions:
12+
type: string
13+
description: The space sparated list of PHP versions to use for the tests.
14+
default: "8.1 8.0"
15+
required: false
16+
min-php-version:
17+
type: string
18+
description: The minimal PHP version to use for the tests.
19+
default: "all"
20+
required: false
21+
suite-with-coverage:
22+
type: string
23+
description: The test suite which is used to check the code coverage.
24+
default: "unit-test"
25+
required: false
26+
27+
jobs:
28+
prepare-matrix:
29+
name: Prepare build matrix
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v2
34+
35+
- name: Checkout shared workflow files
36+
uses: actions/checkout@v2
37+
with:
38+
repository: BluePsyduck/github-workflows
39+
path: .shared
40+
41+
- name: Setup PHP
42+
uses: shivammathur/setup-php@v2
43+
with:
44+
php-version: "8.0"
45+
coverage: none
46+
extensions: ${{ inputs.extensions }}
47+
48+
- name: Get composer cache directory
49+
id: composer-cache
50+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
51+
52+
- name: Cache composer dependencies
53+
uses: actions/cache@v2
54+
with:
55+
path: ${{ steps.composer-cache.outputs.dir }}
56+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
57+
restore-keys: ${{ runner.os }}-composer-
58+
59+
- name: Install dependencies
60+
run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
61+
62+
- name: Generate build matrix
63+
id: matrix
64+
env:
65+
PHP_VERSIONS: ${{ inputs.php-versions }}
66+
MIN_PHP_VERSION: ${{ inputs.min-php-version }}
67+
run: |
68+
echo "::set-output name=matrix::$(php .shared/.github/scripts/build-matrix.php)"
69+
70+
- name: Print matrix
71+
run: echo '${{ steps.matrix.outputs.matrix }}'
72+
outputs:
73+
matrix: ${{ steps.matrix.outputs.matrix }}
74+
75+
test:
76+
name: PHPUnit
77+
needs: prepare-matrix
78+
if: needs.prepare-matrix.outputs.matrix != '[]'
79+
strategy:
80+
fail-fast: false
81+
matrix:
82+
include: ${{ fromJson(needs.prepare-matrix.outputs.matrix) }}
83+
runs-on: ubuntu-latest
84+
steps:
85+
- name: Checkout
86+
uses: actions/checkout@v2
87+
88+
- name: Checkout shared workflow files
89+
uses: actions/checkout@v2
90+
with:
91+
repository: BluePsyduck/github-workflows
92+
path: .shared
93+
94+
- name: Setup PHP
95+
uses: shivammathur/setup-php@v2
96+
with:
97+
php-version: ${{ matrix.version }}
98+
coverage: ${{ matrix.suite == inputs.suite-with-coverage && 'xdebug' || 'none' }}
99+
extensions: ${{ inputs.extensions }}
100+
101+
- name: Get composer cache directory
102+
id: composer-cache
103+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
104+
105+
- name: Cache composer dependencies
106+
uses: actions/cache@v2
107+
with:
108+
path: ${{ steps.composer-cache.outputs.dir }}
109+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
110+
restore-keys: ${{ runner.os }}-composer-
111+
112+
- name: Setup problem matchers
113+
run: |
114+
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
115+
echo "::add-matcher::.shared/.github/problem-matchers/coverage-check.json"
116+
117+
- name: Install dependencies
118+
run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
119+
120+
- name: Run phpunit
121+
run: vendor/bin/phpunit --testsuite=${{ matrix.suite }} ${{ matrix.suite == inputs.suite-with-coverage && '--coverage-clover=coverage.xml' || '' }}
122+
123+
- name: Check coverage.xml existence
124+
id: check-coverage-file
125+
uses: andstor/file-existence-action@v1
126+
with:
127+
files: coverage.xml
128+
129+
- name: Run coverage-check
130+
if: steps.check-coverage-file.outputs.files_exists == 'true'
131+
run: vendor/bin/coverage-check coverage.xml 100
132+
133+
- name: Upload coverage as artifacts
134+
if: steps.check-coverage-file.outputs.files_exists == 'true'
135+
uses: actions/upload-artifact@v2
136+
with:
137+
name: coverage-${{ matrix.version }}
138+
path: coverage.xml
139+
140+
- name: Upload coverage to Codecov
141+
if: steps.check-coverage-file.outputs.files_exists == 'true'
142+
uses: codecov/codecov-action@v1
143+
with:
144+
name: coverage-${{ matrix.version }}
145+
file: coverage.xml

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.idea

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## 1.0.0 - 2021-12-04
4+
5+
- Initial release of the workflows.

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# BluePsyduck's Github Workflows
2+
3+
This repository contains the Github workflows, reused across my projects.
4+
5+
## CI PHP General
6+
7+
This workflow checks general things about the PHP project, including composer validation, coding guidelines using phpcs,
8+
and static analysis through PHPStan.
9+
10+
The following variables can be used with the workflow:
11+
12+
| Variable | Default | Description |
13+
|-------------|---------|----------------------------------------------------|
14+
| extensions | "" | The comma-separated list of extensions to install. |
15+
| php-version | "8.0" | The PHP version to use for the checks. |
16+
17+
Note hat the PHP version is expected as a string (not as a number) to be consistent with the other workflow.
18+
19+
## CI PHP Tests
20+
21+
This workflow executes the PHPUnit tests of the project. It will automatically detect all suites configured for PHPUnit,
22+
and execute them in separate jobs. It also supports checking coverage for one of the suites.
23+
24+
| Variable | Default | Description |
25+
|---------------------|-------------|-------------------------------------------------------------------------------|
26+
| extensions | "" | The comma-separated list of extensions to install. |
27+
| php-versions | "8.1 8.0" | The PHP versions to execute the tests in specified as space-separated string. |
28+
| min-php-version | "all" | The minimal PHP version to use when using the default versions. |
29+
| suite-with-coverage | "unit-test" | The PHPUnit test suite which should be checked for coverage. |
30+
31+
## Example
32+
33+
```yaml
34+
jobs:
35+
call-workflow-ci-php-general:
36+
name: General
37+
uses: factorio-item-browser/github-workflows/.github/workflows/ci-php-general.yaml@v1
38+
39+
call-workflow-ci-php-tests:
40+
name: Tests
41+
uses: factorio-item-browser/github-workflows/.github/workflows/ci-php-tests.yaml@v1
42+
```

0 commit comments

Comments
 (0)