Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/php-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -47,6 +54,9 @@ jobs:
static-analysis:
name: "PHPStan"
runs-on: "ubuntu-latest"
defaults:
run:
working-directory: "${{ inputs.workingDirectory }}"

strategy:
fail-fast: false
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/php-sample.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 17 additions & 2 deletions .github/workflows/php-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 3 additions & 0 deletions php-sample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor/
.phpunit.cache/
composer.lock
44 changes: 44 additions & 0 deletions php-sample/composer.json
Original file line number Diff line number Diff line change
@@ -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
}
14 changes: 14 additions & 0 deletions php-sample/ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

use StrictPhp\Conventions\ExtensionFiles;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
->withRootFiles()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withSets([ExtensionFiles::Ecs]);
3 changes: 3 additions & 0 deletions php-sample/phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

parameters:
ignoreErrors: []
10 changes: 10 additions & 0 deletions php-sample/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
includes:
- phpstan-baseline.neon

parameters:
level: max
paths:
- src
- ecs.php
- rector.php
- tests
13 changes: 13 additions & 0 deletions php-sample/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.1/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
<testsuites>
<testsuite name="Test">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
</phpunit>
14 changes: 14 additions & 0 deletions php-sample/rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use StrictPhp\Conventions\ExtensionFiles;

return RectorConfig::configure()
->withRootFiles()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withSets([ExtensionFiles::Rector]);
13 changes: 13 additions & 0 deletions php-sample/src/Calculator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace WrkFlow\PhpSample;

final class Calculator
{
public function add(int $left, int $right): int
{
return $left + $right;
}
}
18 changes: 18 additions & 0 deletions php-sample/tests/CalculatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace WrkFlow\PhpSample\Tests;

use PHPUnit\Framework\TestCase;
use WrkFlow\PhpSample\Calculator;

final class CalculatorTest extends TestCase
{
public function testAddReturnsSum(): void
{
$calculator = new Calculator();

self::assertSame(5, $calculator->add(2, 3));
}
}
Loading