Skip to content

Commit

Permalink
Add GitHub workflows for CI, coding standards, and analysis
Browse files Browse the repository at this point in the history
This commit introduces four new GitHub workflow files. They automate the processes for continuous integration, coding standards validation, static analysis, and updating copyright years in the license file. These workflows leverage various tools and actions to ensure code quality and maintainability.
  • Loading branch information
koriym committed Nov 18, 2024
1 parent cd1ed67 commit 54fd686
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Coding Standards

on:
push:
paths-ignore:
- '**.md'
pull_request:
workflow_dispatch:
workflow_call:
inputs:
php_version:
required: false
type: string
default: '8.3'

jobs:
coding-standards:
name: Coding Standards
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php_version }}
tools: cs2pr
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Validate composer.json
run: composer validate --strict

- name: Run PHP_CodeSniffer
run: ./vendor/tools/vendor/bin/phpcs -q --no-colors --report=checkstyle src tests | cs2pr
102 changes: 102 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Continuous Integration

on:
push:
paths-ignore:
- '**.md'
pull_request:
workflow_dispatch:
workflow_call:
inputs:
old_stable:
description: Old stable php version matrix
required: true
type: string
default: '8.1, 8.2'
current_stable:
description: Current stable php version
required: true
type: string
default: '8.3'
script:
description: Additional scripts to run
required: false
type: string

env:
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist"
COMPOSER_UPDATE_FLAGS: ""

jobs:
phpunit:
name: PHPUnit
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ${{ fromJson(inputs.old_stable) }}
dependencies: [highest, lowest]
os: [ubuntu-latest]
include:
- php-version: ${{ inputs.current_stable }}
os: windows-latest
experimental: false
- php-version: ${{ inputs.current_stable }}
os: ubuntu-latest
experimental: false
- php-version: ${{ inputs.current_stable }}
os: ubuntu-lowest
experimental: false
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: pcov
ini-values: zend.assertions=1

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Handle lowest dependencies update
if: contains(matrix.dependencies, 'lowest')
run: echo COMPOSER_UPDATE_FLAGS=$COMPOSER_UPDATE_FLAGS --prefer-lowest >> $GITHUB_ENV

- name: Handle ignore-platform-reqs dependencies update
if: contains(matrix.dependencies, 'ignore')
run: echo COMPOSER_FLAGS=$COMPOSER_FLAGS --ignore-platform-req=php >> $GITHUB_ENV

- name: Remove platform config to get latest dependencies for current PHP version
if: contains(matrix.dependencies, 'highest') || contains(matrix.dependencies, 'lowest')
run: composer config platform --unset

- name: Allow alpha releases for latest-deps builds to catch problems earlier
if: contains(matrix.dependencies, 'ignore')
run: composer config minimum-stability alpha

- name: Update dependencies
run: composer update ${{ env.COMPOSER_UPDATE_FLAGS }} ${{ env.COMPOSER_FLAGS }}

- name: Run test suite
run: ./vendor/bin/phpunit --coverage-clover=coverage.xml

- name: Upload coverage report
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Run additional script
if: ${{ inputs.script }}
run: php ${{ inputs.script }}
142 changes: 142 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: Static Analysis

on:
push:
paths-ignore:
- '**.md'
pull_request:
workflow_dispatch:
workflow_call:
inputs:
php_version:
required: false
type: string
default: '8.3'
has_crc_config:
required: false
default: false
type: boolean
description: True if the project has composer_require_checker.json

jobs:
static-analysis-phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php_version }}
tools: cs2pr
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Run PHPStan
run: ./vendor/tools/vendor/bin/phpstan analyse -c phpstan.neon --no-progress --no-interaction --error-format=checkstyle | cs2pr

static-analysis-psalm:
name: Psalm
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php_version }}
tools: cs2pr
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Run Psalm
run: ./vendor/tools/vendor/bin/psalm --show-info=false --output-format=checkstyle --shepherd | cs2pr

static-analysis-phpmd:
name: PHPMD
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php_version }}

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Run PHP Mess Detector
run: ./vendor/tools/vendor/bin/phpmd src text ./phpmd.xml

static-analysis-composer-require-checker:
name: ComposerRequireChecker
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php_version }}
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Install dependencies
run: |
composer install --no-interaction --no-progress --prefer-dist
composer require maglnet/composer-require-checker --dev --with-all-dependencies
- name: Run composer-require-checker without config
if: ${{ !inputs.has_crc_config }}
run: ./vendor/tools/vendor/bin/composer-require-checker check ./composer.json

- name: Run composer-require-checker with config
if: ${{ inputs.has_crc_config }}
run: ./vendor/tools/vendor/bin/composer-require-checker check ./composer.json --config-file=./composer-require-checker.json
17 changes: 17 additions & 0 deletions .github/workflows/update-copyright-years-in-license-file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Update copyright year(s) in license file

on:
workflow_dispatch:
schedule:
- cron: "0 3 1 1 *"

jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: FantasticFiasco/action-update-license-year@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 54fd686

Please sign in to comment.