Skip to content

Commit 3de518c

Browse files
author
Stefan Boonstra
committed
Simplify bash usage in github actions
1 parent 45f25c7 commit 3de518c

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

.github/workflows/testing-suite.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ jobs:
44
PHP:
55
strategy:
66
matrix:
7-
php-version: [8.1, 8.2, 8.3, 8.4]
7+
php:
8+
- {version: 8.1, tasks: 'composer,jsonlint,xmllint,yamllint,phpcs,phplint,phpmd,phpstan,securitychecker_enlightn'}
9+
- {version: 8.2, tasks: 'composer,jsonlint,xmllint,yamllint,phpcs,phplint,phpmd,phpstan,securitychecker_enlightn'}
10+
- {version: 8.3}
11+
- {version: 8.4}
812
runs-on: ubuntu-latest
913
container:
10-
image: ${{ matrix.php-version == '8.1' && 'srcoder/development-php:php81-fpm' ||
11-
matrix.php-version == '8.2' && 'srcoder/development-php:php82-fpm' ||
12-
matrix.php-version == '8.3' && 'srcoder/development-php:php83-fpm' ||
13-
matrix.php-version == '8.4' && 'srcoder/development-php:php84-fpm' }}
14+
image: ${{ matrix.php.version == '8.1' && 'srcoder/development-php:php81-fpm' ||
15+
matrix.php.version == '8.2' && 'srcoder/development-php:php82-fpm' ||
16+
matrix.php.version == '8.3' && 'srcoder/development-php:php83-fpm' ||
17+
matrix.php.version == '8.4' && 'srcoder/development-php:php84-fpm' }}
1418
steps:
1519
- name: Checkout
1620
uses: actions/checkout@v2
@@ -23,9 +27,9 @@ jobs:
2327

2428
- name: Run GrumPHP Tasks
2529
run: |
26-
if [[ "${{ matrix.php-version }}" == "8.1" || "${{ matrix.php-version }}" == "8.2" ]]; then
27-
composer2 exec -v grumphp -- run --tasks=composer,jsonlint,xmllint,yamllint,phpcs,phplint,phpmd,phpstan,securitychecker_enlightn
28-
else
29-
composer2 exec -v grumphp -- run
30+
runArguments=()
31+
if [[ "${{ matrix.php.tasks }}" ]]; then
32+
runArguments+=(--tasks="{{ matrix.php.tasks }}")
3033
fi
34+
composer2 exec -v grumphp -- run "${runArguments[@]}"
3135
shell: bash

docs/examples/github-actions.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ jobs:
1010
PHP:
1111
strategy:
1212
matrix:
13-
php-version: [8.1, 8.2, 8.3, 8.4]
13+
php:
14+
- {version: 8.1, tasks: 'composer,jsonlint,xmllint,yamllint,phpcs,phplint,phpmd,phpstan,securitychecker_enlightn'}
15+
- {version: 8.2, tasks: 'composer,jsonlint,xmllint,yamllint,phpcs,phplint,phpmd,phpstan,securitychecker_enlightn'}
16+
- {version: 8.3}
17+
- {version: 8.4}
1418
runs-on: ubuntu-latest
1519
container:
16-
image: ${{ matrix.php-version == '8.1' && 'srcoder/development-php:php81-fpm' ||
17-
matrix.php-version == '8.2' && 'srcoder/development-php:php82-fpm' ||
18-
matrix.php-version == '8.3' && 'srcoder/development-php:php83-fpm' ||
19-
matrix.php-version == '8.4' && 'srcoder/development-php:php84-fpm' }}
20+
image: ${{ matrix.php.version == '8.1' && 'srcoder/development-php:php81-fpm' ||
21+
matrix.php.version == '8.2' && 'srcoder/development-php:php82-fpm' ||
22+
matrix.php.version == '8.3' && 'srcoder/development-php:php83-fpm' ||
23+
matrix.php.version == '8.4' && 'srcoder/development-php:php84-fpm' }}
2024
steps:
2125
- name: Checkout
2226
uses: actions/checkout@v2
@@ -29,12 +33,10 @@ jobs:
2933

3034
- name: Run GrumPHP Tasks
3135
run: |
32-
if [[ "${{ matrix.php-version }}" == "8.1" || "${{ matrix.php-version }}" == "8.2" ]]; then
33-
composer2 exec -v grumphp -- run --tasks=composer,jsonlint,xmllint,yamllint,phpcs,phplint,phpmd,phpstan,securitychecker_enlightn
34-
else
35-
composer2 exec -v grumphp -- run
36+
runArguments=()
37+
if [[ "${{ matrix.php.tasks }}" ]]; then
38+
runArguments+=(--tasks="{{ matrix.php.tasks }}")
3639
fi
40+
composer2 exec -v grumphp -- run "${runArguments[@]}"
3741
shell: bash
38-
39-
4042
```

0 commit comments

Comments
 (0)