From 08db20dc1786be86d39e6ac65f98c968c35315ff Mon Sep 17 00:00:00 2001 From: Oleksii Bulba Date: Fri, 4 Aug 2023 22:39:40 +0300 Subject: [PATCH] Feature: Workflows - Added reusable workflows: - coding-standards.yml - phpcs, phpmd, php-cs-fixer; - composer-lint.yml - composer validate, normalize; - continuous-integration.yaml - phpunit; - static-analysis.yml - phpstan, psalm; Signed-off-by: Oleksii Bulba --- .github/workflows/coding-standards.yml | 126 ++++++++++++++++++ .github/workflows/composer-lint.yml | 39 ++++++ .github/workflows/continuous-integration.yaml | 70 ++++++++++ .github/workflows/static-analysis.yml | 86 ++++++++++++ 4 files changed, 321 insertions(+) create mode 100644 .github/workflows/coding-standards.yml create mode 100644 .github/workflows/composer-lint.yml create mode 100644 .github/workflows/continuous-integration.yaml create mode 100644 .github/workflows/static-analysis.yml diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml new file mode 100644 index 0000000..1452c07 --- /dev/null +++ b/.github/workflows/coding-standards.yml @@ -0,0 +1,126 @@ +name: 'Coding Standards' + +on: + workflow_call: + inputs: + php-version: + description: 'The PHP version to use when running the job' + default: '8.2' + required: false + type: 'string' + composer-root-version: + description: 'The version of the package being tested, in case of circular dependencies.' + required: false + type: 'string' + composer-options: + description: 'Additional flags for the composer install command.' + default: '--prefer-dist' + required: false + type: 'string' + +jobs: + coding-standards: + name: 'Coding Standards' + runs-on: 'ubuntu-22.04' + + strategy: + matrix: + php-version: + - '${{ inputs.php-version }}' + + steps: + - name: 'Checkout' + uses: 'actions/checkout@v3' + + - name: 'Install PHP' + uses: 'shivammathur/setup-php@v2' + with: + coverage: 'none' + php-version: '${{ matrix.php-version }}' + tools: 'cs2pr' + + - name: 'Set COMPOSER_ROOT_VERSION' + run: | + echo 'COMPOSER_ROOT_VERSION=${{ inputs.composer-root-version }}' >> $GITHUB_ENV + if: '${{ inputs.composer-root-version }}' + + - name: 'Install Php_Codesniffer with Composer' + uses: 'ramsey/composer-install@v2' + with: + dependency-versions: 'highest' + composer-options: '${{ inputs.composer-options }} --working-dir=vendor/micro/dev-tools/phpcs' + + - name: 'Run PHP_CodeSniffer' + run: 'vendor/bin/phpcs -q --no-colors --report=checkstyle | cs2pr' + + mess-detector: + name: 'Mess detector' + runs-on: 'ubuntu-22.04' + + strategy: + matrix: + php-version: + - '${{ inputs.php-version }}' + + steps: + - name: 'Checkout' + uses: 'actions/checkout@v3' + + - name: 'Install PHP' + uses: 'shivammathur/setup-php@v2' + with: + coverage: 'none' + php-version: '${{ matrix.php-version }}' + + - name: 'Set COMPOSER_ROOT_VERSION' + run: | + echo 'COMPOSER_ROOT_VERSION=${{ inputs.composer-root-version }}' >> $GITHUB_ENV + if: '${{ inputs.composer-root-version }}' + + - name: 'Install MessDetector with Composer' + uses: 'ramsey/composer-install@v2' + with: + dependency-versions: 'highest' + composer-options: '${{ inputs.composer-options }} --working-dir=vendor/micro/dev-tools/phpmd' + + - name: 'PHP Mess Detector' + uses: 'php-actions/phpmd@v1' + with: + php_version: '${{ matrix.php-version }}' + path: 'src/' + output: 'github' + vendored_phpmd_path: 'vendor/micro/dev-tools/phpmd/vendor/bin/phpmd' + # ruleset: test/phpmd/ruleset.xml + + phpcsfixer: + name: 'PHP Code Style fixer' + runs-on: 'ubuntu-22.04' + + strategy: + matrix: + php-version: + - '${{ inputs.php-version }}' + + steps: + - name: 'Checkout' + uses: 'actions/checkout@v3' + + - name: 'Install PHP' + uses: 'shivammathur/setup-php@v2' + with: + coverage: 'none' + php-version: '${{ matrix.php-version }}' + + - name: 'Set COMPOSER_ROOT_VERSION' + run: | + echo 'COMPOSER_ROOT_VERSION=${{ inputs.composer-root-version }}' >> $GITHUB_ENV + if: '${{ inputs.composer-root-version }}' + + - name: 'Install PHP Code Style fixer with Composer' + uses: 'ramsey/composer-install@v2' + with: + dependency-versions: 'highest' + composer-options: '${{ inputs.composer-options }} --working-dir=vendor/micro/dev-tools/php-cs-fixer' + + - name: 'PHP Code Style fixer' + run: 'vendor/micro/dev-tools/phpmd/vendor/bin/php-cs-fixer fix --verbose --dry-run --using-cache=no' diff --git a/.github/workflows/composer-lint.yml b/.github/workflows/composer-lint.yml new file mode 100644 index 0000000..66f9c55 --- /dev/null +++ b/.github/workflows/composer-lint.yml @@ -0,0 +1,39 @@ +name: 'Composer Lint' + +on: + workflow_call: + inputs: + php-version: + description: 'The PHP version to use when running the job' + default: '8.2' + required: false + type: 'string' + +jobs: + composer-lint: + name: 'Composer Lint' + runs-on: 'ubuntu-22.04' + + strategy: + matrix: + php-version: + - '${{ inputs.php-version }}' + + steps: + - name: 'Checkout' + uses: 'actions/checkout@v3' + + - name: 'Install PHP' + uses: 'shivammathur/setup-php@v2' + with: + coverage: 'none' + php-version: '${{ matrix.php-version }}' + tools: composer:v2, composer-normalize:2 + env: + COMPOSER_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + + - name: 'Composer normalize' + run: 'composer-normalize --dry-run' + + - name: 'Composer validate' + run: 'composer validate --strict' diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml new file mode 100644 index 0000000..d658ca3 --- /dev/null +++ b/.github/workflows/continuous-integration.yaml @@ -0,0 +1,70 @@ +name: 'Continuous Integration' + +on: + workflow_call: + inputs: + php-versions: + description: 'The PHP versions to use when running the job' + default: '8.2' + required: false + type: 'string' + composer-root-version: + description: 'The version of the package being tested, in case of circular dependencies.' + required: false + type: 'string' + composer-options: + description: 'Additional flags for the composer install command.' + default: '--prefer-dist' + required: false + type: 'string' + +env: + fail-fast: true + +jobs: + phpunit: + name: 'PHPUnit' + runs-on: 'ubuntu-22.04' + + strategy: + matrix: + php-version: '${{ fromJson(inputs.php-versions) }}' + dependencies: + - 'highest' + include: + - php-version: '${{ fromJson(inputs.php-versions)[0] }}' + dependencies: 'lowest' + + steps: + - name: 'Checkout' + uses: 'actions/checkout@v3' + with: + fetch-depth: 2 + + - name: 'Install PHP with PCOV' + uses: 'shivammathur/setup-php@v2' + with: + php-version: '${{ matrix.php-version }}' + coverage: 'pcov' + ini-values: 'zend.assertions=1' + + - name: 'Set COMPOSER_ROOT_VERSION' + run: | + echo "COMPOSER_ROOT_VERSION=${{ inputs.composer-root-version }}" >> $GITHUB_ENV + if: '${{ inputs.composer-root-version }}' + + - name: 'Install dependencies with Composer' + uses: 'ramsey/composer-install@v2' + with: + dependency-versions: '${{ matrix.dependencies }}' + composer-options: '${{ inputs.composer-options }}' + + - name: 'Run PHPUnit' + run: 'vendor/bin/phpunit --coverage-clover=coverage.xml' + + - name: 'Upload coverage reports to Codecov' + run: | + # Replace `linux` below with the appropriate OS + curl -Os https://uploader.codecov.io/latest/linux/codecov + chmod +x codecov + ./codecov -t ${CODECOV_TOKEN} diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..f759766 --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,86 @@ +name: 'Static Analysis' + +on: + workflow_call: + inputs: + php-version: + description: 'The PHP version to use when running the job' + default: '8.2' + required: false + type: 'string' + composer-root-version: + description: 'The version of the package being tested, in case of circular dependencies.' + required: false + type: 'string' + composer-options: + description: 'Additional flags for the composer install command.' + default: '--prefer-dist' + required: false + type: 'string' + +jobs: + phpstan: + name: 'PHPStan' + runs-on: 'ubuntu-22.04' + + strategy: + matrix: + php-version: + - '${{ inputs.php-version }}' + + steps: + - name: 'Checkout code' + uses: 'actions/checkout@v3' + + - name: 'Install PHP' + uses: 'shivammathur/setup-php@v2' + with: + coverage: 'none' + php-version: '${{ matrix.php-version }}' + + - name: 'Set COMPOSER_ROOT_VERSION' + run: | + echo 'COMPOSER_ROOT_VERSION=${{ inputs.composer-root-version }}' >> $GITHUB_ENV + if: '${{ inputs.composer-root-version }}' + + - name: 'Install PHPStan with Composer' + uses: 'ramsey/composer-install@v2' + with: + dependency-versions: 'highest' + composer-options: '${{ inputs.composer-options }} --working-dir=vendor/micro/dev-tools/phpstan' + + - name: 'Run a static analysis with phpstan/phpstan' + run: 'vendor/bin/phpstan analyse' + + psalm: + name: 'Psalm' + runs-on: 'ubuntu-22.04' + + strategy: + matrix: + php-version: + - '${{ inputs.php-version }}' + + steps: + - name: 'Checkout code' + uses: 'actions/checkout@v3' + + - name: 'Install PHP' + uses: 'shivammathur/setup-php@v2' + with: + coverage: 'none' + php-version: '${{ matrix.php-version }}' + + - name: 'Set COMPOSER_ROOT_VERSION' + run: | + echo 'COMPOSER_ROOT_VERSION=${{ inputs.composer-root-version }}' >> $GITHUB_ENV + if: '${{ inputs.composer-root-version }}' + + - name: 'Install Psalm with Composer' + uses: 'ramsey/composer-install@v2' + with: + dependency-versions: 'highest' + composer-options: '${{ inputs.composer-options }} --working-dir=vendor/micro/dev-tools/psalm' + + - name: 'Run a static analysis with vimeo/psalm' + run: 'vendor/bin/psalm --show-info=false --stats --output-format=github --threads=$(nproc)'