diff --git a/.github/workflows/php-check.yml b/.github/workflows/php-check.yml index b9df49c..994e528 100644 --- a/.github/workflows/php-check.yml +++ b/.github/workflows/php-check.yml @@ -16,11 +16,18 @@ on: required: false type: string default: "8.1" + workingDirectory: + required: false + type: string + default: "." jobs: coding-standards: name: "Coding Standard" runs-on: "ubuntu-latest" + defaults: + run: + working-directory: "${{ inputs.workingDirectory }}" steps: - name: "Checkout" @@ -47,6 +54,9 @@ jobs: static-analysis: name: "PHPStan" runs-on: "ubuntu-latest" + defaults: + run: + working-directory: "${{ inputs.workingDirectory }}" strategy: fail-fast: false diff --git a/.github/workflows/php-sample.yml b/.github/workflows/php-sample.yml new file mode 100644 index 0000000..b48125e --- /dev/null +++ b/.github/workflows/php-sample.yml @@ -0,0 +1,48 @@ +name: "PHP sample" + +on: + push: + branches: + - "main" + + pull_request: + paths: + - "php-sample/src/**" + - "php-sample/tests/**" + - "php-sample/composer.json" + - "php-sample/ecs.php" + - "php-sample/rector.php" + - "php-sample/phpstan.neon" + - "php-sample/phpstan-baseline.neon" + - "php-sample/phpunit.xml" + +concurrency: + group: "php-sample-${{ github.ref }}" + cancel-in-progress: true + +jobs: + code: + name: "Code check" + strategy: + matrix: + phpVersion: ["8.3", "8.4", "8.5"] + uses: ./.github/workflows/php-check.yml + with: + phpVersion: "${{ matrix.phpVersion }}" + workingDirectory: "php-sample" + secrets: inherit + + tests: + name: "Run tests" + strategy: + matrix: + phpVersion: ["8.3", "8.4", "8.5"] + uses: ./.github/workflows/php-tests.yml + with: + badgeOnBranch: "main" + badgeOnPullRequest: true + gistOnPhpVersion: "8.3" + gistID: "de6a8c4102b8d237e822ca47ed805036" + phpVersion: "${{ matrix.phpVersion }}" + workingDirectory: "php-sample" + secrets: inherit diff --git a/.github/workflows/php-tests.yml b/.github/workflows/php-tests.yml index eb468f0..32bb908 100644 --- a/.github/workflows/php-tests.yml +++ b/.github/workflows/php-tests.yml @@ -24,10 +24,22 @@ on: required: false type: string default: "8.1" + badgeOnBranch: + required: false + type: string + default: "main" + badgeOnPullRequest: + required: false + type: boolean + default: false phpVersion: required: false type: string default: "8.1" + workingDirectory: + required: false + type: string + default: "." secrets: GIST_SECRET: required: false @@ -36,6 +48,9 @@ jobs: tests: name: "Tests ${{ inputs.phpVersion }} (${{ matrix.dependencies }})" runs-on: "ubuntu-latest" + defaults: + run: + working-directory: "${{ inputs.workingDirectory }}" strategy: fail-fast: false @@ -94,8 +109,8 @@ jobs: # TODO on pull request add comment? - name: "Create badge" - if: ${{ inputs.gistID != '' && inputs.gistOnPhpVersion == inputs.phpVersion && github.ref == 'refs/heads/main' && matrix.dependencies == 'highest' && steps.tests.outputs.coverage != '' }} - uses: pionl/dynamic-badges-action@9c9a724ab23462889be4eb54f09fde5d9c2ea667 + if: ${{ inputs.gistID != '' && inputs.gistOnPhpVersion == inputs.phpVersion && matrix.dependencies == 'highest' && steps.tests.outputs.coverage != '' && ((inputs.badgeOnBranch != '' && github.ref == format('refs/heads/{0}', inputs.badgeOnBranch)) || (inputs.badgeOnPullRequest && github.event_name == 'pull_request')) }} + uses: pionl/dynamic-badges-action@f2bde01f27576417b46298af6fb12801fcd97b1c with: auth: ${{ secrets.GIST_SECRET }} gistID: ${{ inputs.gistID }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/README.md b/README.md index 929b730..3d748df 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ See https://docs.github.com/en/actions/learn-github-actions/reusing-workflows#ca ## PHP Check +![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/pionl/de6a8c4102b8d237e822ca47ed805036/raw/coverage.json) + 1. Create a file `.github/workflows/check.yml` 2. Runs PHPStan **(needs to be installed).** with `composer analyse` 3. Runs Rector PHP **(needs to be installed).** with `composer lint:upgrade:check` diff --git a/php-sample/.gitignore b/php-sample/.gitignore new file mode 100644 index 0000000..4c8679d --- /dev/null +++ b/php-sample/.gitignore @@ -0,0 +1,3 @@ +vendor/ +.phpunit.cache/ +composer.lock \ No newline at end of file diff --git a/php-sample/composer.json b/php-sample/composer.json new file mode 100644 index 0000000..9c90a5d --- /dev/null +++ b/php-sample/composer.json @@ -0,0 +1,44 @@ +{ + "name": "wrk-flow/reusable-workflows", + "description": "Sample PHP project for exercising wrk-flow reusable workflows.", + "type": "project", + "license": "MIT", + "require": { + "php": "^8.3" + }, + "require-dev": { + "strictphp/conventions": "^2.0" + }, + "autoload": { + "psr-4": { + "WrkFlow\\PhpSample\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "WrkFlow\\PhpSample\\Tests\\": "tests/" + } + }, + "scripts": { + "qa": [ + "@lint", + "@test", + "@analyse" + ], + "analyse": "./vendor/bin/phpstan", + "lint:check": "./vendor/bin/ecs", + "lint:fix": "./vendor/bin/ecs --fix", + "lint:upgrade": "./vendor/bin/rector process", + "lint:upgrade:check": "./vendor/bin/rector process --dry-run", + "test": "./vendor/bin/phpunit", + "test:coverage": "./vendor/bin/phpunit --coverage-text" + }, + "config": { + "allow-plugins": { + "phpstan/extension-installer": true + }, + "sort-packages": true + }, + "minimum-stability": "stable", + "prefer-stable": true +} diff --git a/php-sample/ecs.php b/php-sample/ecs.php new file mode 100644 index 0000000..5c05fe3 --- /dev/null +++ b/php-sample/ecs.php @@ -0,0 +1,14 @@ +withRootFiles() + ->withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->withSets([ExtensionFiles::Ecs]); diff --git a/php-sample/phpstan-baseline.neon b/php-sample/phpstan-baseline.neon new file mode 100644 index 0000000..fc99ea9 --- /dev/null +++ b/php-sample/phpstan-baseline.neon @@ -0,0 +1,3 @@ + +parameters: + ignoreErrors: [] diff --git a/php-sample/phpstan.neon b/php-sample/phpstan.neon new file mode 100644 index 0000000..0428f52 --- /dev/null +++ b/php-sample/phpstan.neon @@ -0,0 +1,10 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: max + paths: + - src + - ecs.php + - rector.php + - tests diff --git a/php-sample/phpunit.xml b/php-sample/phpunit.xml new file mode 100644 index 0000000..9ab9971 --- /dev/null +++ b/php-sample/phpunit.xml @@ -0,0 +1,13 @@ + + + + + src + + + + + tests + + + diff --git a/php-sample/rector.php b/php-sample/rector.php new file mode 100644 index 0000000..ad1ead7 --- /dev/null +++ b/php-sample/rector.php @@ -0,0 +1,14 @@ +withRootFiles() + ->withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->withSets([ExtensionFiles::Rector]); diff --git a/php-sample/src/Calculator.php b/php-sample/src/Calculator.php new file mode 100644 index 0000000..7e96ade --- /dev/null +++ b/php-sample/src/Calculator.php @@ -0,0 +1,13 @@ +add(2, 3)); + } +}