Skip to content

Commit fc0a20c

Browse files
committed
Refine the github action workflow
1 parent 840aa63 commit fc0a20c

File tree

4 files changed

+101
-50
lines changed

4 files changed

+101
-50
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: "Setup Composer"
2+
description: "Sets up the composer dependencies"
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Get Composer Cache Directory
7+
id: composer-cache
8+
run: |
9+
echo "::set-output name=dir::$(composer config cache-files-dir)"
10+
shell: bash
11+
- uses: actions/cache@v2
12+
with:
13+
path: ${{ steps.composer-cache.outputs.dir }}
14+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
15+
restore-keys: |
16+
${{ runner.os }}-composer-
17+
- name: Install dependencies
18+
run: composer install --no-progress --prefer-dist --classmap-authoritative --no-interaction
19+
shell: bash

.github/workflows/main.yml

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ on:
88
workflow_dispatch:
99

1010
jobs:
11-
tests:
11+
PHPUnit:
1212
strategy:
1313
matrix:
14-
operating-system: [ubuntu-latest]
15-
php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
14+
operating-system: [ 'ubuntu-latest', 'windows-latest', 'macos-latest' ]
15+
php-versions: [ '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ]
1616
runs-on: ${{ matrix.operating-system }}
1717
steps:
1818
- name: Checkout
@@ -22,60 +22,70 @@ jobs:
2222
with:
2323
php-version: ${{ matrix.php-versions }}
2424
coverage: none
25-
- name: Get composer cache directory
26-
id: composer-cache
27-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
28-
- name: Cache composer dependencies
29-
uses: actions/cache@v2
25+
tools: phpunit
26+
- name: Setup Composer
27+
uses: ./.github/actions/setup-composer
28+
- name: Run PHPUnit
29+
run: composer test -- --do-not-cache-result
30+
PHP_CodeSniffer:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v2
35+
- name: Setup PHP
36+
uses: shivammathur/setup-php@v2
3037
with:
31-
path: ${{ steps.composer-cache.outputs.dir }}
32-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
33-
restore-keys: ${{ runner.os }}-composer-
34-
- name: Install dependencies
35-
run: composer install --no-progress --prefer-dist --classmap-authoritative --no-interaction
36-
- name: Setup problem matchers for PHPUnit
37-
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
38-
- name: Test with phpunit
39-
run: vendor/bin/phpunit
40-
lint:
38+
php-version: latest
39+
coverage: none
40+
tools: phpcs
41+
- name: Setup Composer
42+
uses: ./.github/actions/setup-composer
43+
- name: Run PHP_CodeSniffer
44+
run: composer phpcs -- --no-cache
45+
PHP-CS-Fixer:
4146
runs-on: ubuntu-latest
4247
steps:
4348
- name: Checkout
4449
uses: actions/checkout@v2
4550
- name: Setup PHP
4651
uses: shivammathur/setup-php@v2
4752
with:
48-
php-version: '7.4'
53+
php-version: latest
4954
coverage: none
50-
tools: cs2pr, php-cs-fixer, phpcs
55+
tools: php-cs-fixer
56+
- name: Setup Composer
57+
uses: ./.github/actions/setup-composer
5158
- name: Run PHP Coding Standards Fixer
52-
run: php-cs-fixer fix --dry-run --using-cache=no --format=checkstyle | cs2pr
53-
- name: Run PHP_CodeSniffer
54-
run: phpcs --standard=PSR12 --exclude=PSR12.Properties.ConstantVisibility -q --report=checkstyle src tests | cs2pr
59+
run: composer php-cs-fixer -- --dry-run --diff --using-cache=no
60+
composer-normalize:
61+
runs-on: ubuntu-latest
62+
steps:
63+
- name: Checkout
64+
uses: actions/checkout@v2
65+
- name: Setup PHP
66+
uses: shivammathur/setup-php@v2
67+
with:
68+
php-version: latest
69+
coverage: none
70+
tools: composer-normalize
71+
- name: Setup Composer
72+
uses: ./.github/actions/setup-composer
73+
- name: Run composer-normalize
74+
run: composer normalize --dry-run
5575
coverage:
5676
runs-on: ubuntu-latest
5777
steps:
58-
- name: Checkout
59-
uses: actions/checkout@v2
60-
- name: Setup PHP
61-
uses: shivammathur/setup-php@v2
62-
with:
63-
php-version: '8.0'
64-
coverage: xdebug
65-
- name: Get composer cache directory
66-
id: composer-cache
67-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
68-
- name: Cache composer dependencies
69-
uses: actions/cache@v2
70-
with:
71-
path: ${{ steps.composer-cache.outputs.dir }}
72-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
73-
restore-keys: ${{ runner.os }}-composer-
74-
- name: Install dependencies
75-
run: composer install --no-progress --prefer-dist --classmap-authoritative --no-interaction
76-
- name: Setup problem matchers for PHPUnit
77-
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
78-
- name: Test with phpunit
79-
run: vendor/bin/phpunit --coverage-clover coverage.xml
80-
- name: Upload coverage
81-
uses: codecov/codecov-action@v1
78+
- name: Checkout
79+
uses: actions/checkout@v2
80+
- name: Setup PHP
81+
uses: shivammathur/setup-php@v2
82+
with:
83+
php-version: latest
84+
coverage: xdebug
85+
tools: phpunit
86+
- name: Setup Composer
87+
uses: ./.github/actions/setup-composer
88+
- name: Run PHPUnit with coverage
89+
run: composer test -- --do-not-cache-result --coverage-clover coverage.xml
90+
- name: Upload coverage
91+
uses: codecov/codecov-action@v1

.phpcs.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Project Coding Standard">
3+
<description>The coding standard configuration used for this project</description>
4+
5+
<file>./src/</file>
6+
<file>./tests/</file>
7+
8+
<exclude-pattern>*/vendor/*</exclude-pattern>
9+
<arg name="extensions" value="php" />
10+
11+
<rule ref="PSR12">
12+
<exclude name="PSR12.Properties.ConstantVisibility" />
13+
</rule>
14+
</ruleset>

composer.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
"php": ">=5.6.0",
2222
"psr/http-message": "^1.0"
2323
},
24-
"require-dev": {
25-
"phpunit/phpunit": "^5.7 || ^6.5 || ^9.4"
26-
},
2724
"autoload": {
2825
"psr-4": {
2926
"Violet\\StreamingJsonEncoder\\": "src/"
@@ -34,5 +31,16 @@
3431
"Violet\\StreamingJsonEncoder\\": "tests/tests/",
3532
"Violet\\StreamingJsonEncoder\\Test\\": "tests/classes/"
3633
}
34+
},
35+
"scripts": {
36+
"ci-all": [
37+
"composer test -- --do-not-cache-result",
38+
"composer phpcs -- --no-cache",
39+
"composer php-cs-fixer -- --dry-run --diff --using-cache=no",
40+
"composer normalize --dry-run"
41+
],
42+
"php-cs-fixer": "php-cs-fixer fix -v",
43+
"phpcs": "phpcs -p",
44+
"test": "phpunit"
3745
}
3846
}

0 commit comments

Comments
 (0)