Skip to content

Commit

Permalink
CI: general restructure (#7407)
Browse files Browse the repository at this point in the history
Co-authored-by: Greg Korba <wirone@gmail.com>
  • Loading branch information
keradus and Wirone committed Nov 4, 2023
1 parent 77103ef commit 74f6ba0
Show file tree
Hide file tree
Showing 14 changed files with 256 additions and 158 deletions.
23 changes: 23 additions & 0 deletions .github/composite-actions/install-composer-deps/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Install composer deps"

inputs:
flags:
description: 'Composer flags'
required: false

runs:
using: "composite"
steps:
- name: Install dependencies
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
retry_wait_seconds: 30
# `--no-scripts` to avoid side-effects (e.g. installing dev-tools for all jobs on CI level),
# all executed scripts should be explicit and run only when needed.
command: composer update --optimize-autoloader --no-interaction --no-progress --no-scripts ${{ inputs.flags }}

- name: Show versions of packages
shell: bash
run: composer info -D
57 changes: 57 additions & 0 deletions .github/composite-actions/setup-php-with-composer-deps/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: "Setup PHP with Composer deps"

inputs:
os:
description: 'OS version'
required: true
php:
description: 'PHP version'
required: true
php-coverage:
description: 'Enable coverage driver'
required: false
default: 'no'
tools:
description: 'tools'
required: false
default: 'none'
composer-flags:
description: 'Composer flags'
required: false
composer-flex-with-symfony-version:
description: 'Sf version to determine with Flex'
required: false

runs:
using: "composite"
steps:
- name: Resolve PHP tools flag
uses: actions/github-script@v6
id: setup-php-resolve-tools
with:
script: 'return "${{ inputs.composer-flex-with-symfony-version }}" ? "flex" : "none"'
result-encoding: string

- name: Resolve PHP coverage flag
uses: actions/github-script@v6
id: setup-php-resolve-coverage
with:
script: 'return "${{ inputs.php-coverage }}" == "yes" ? "pcov" : "none"'
result-encoding: string

- name: Setup PHP
uses: ./.github/composite-actions/setup-php
with:
version: ${{ inputs.php }}
coverage: ${{ steps.setup-php-resolve-coverage.outputs.result }}
tools: ${{ steps.setup-php-resolve-tools.outputs.result }}, ${{ inputs.tools }}

- name: Configure Symfony Flex
if: inputs.composer-flex-with-symfony-version
shell: bash
run: composer config extra.symfony.require ${{ inputs.composer-flex-with-symfony-version }}

- name: Install Composer deps
uses: ./.github/composite-actions/install-composer-deps
with:
flags: ${{ inputs.composer-flags }}
25 changes: 25 additions & 0 deletions .github/composite-actions/setup-php/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: "Setup PHP"

inputs:
version:
description: 'PHP version'
required: true
coverage:
description: 'coverage mode'
required: false
default: 'none'
tools:
description: 'tools'
required: false
default: 'none'

runs:
using: "composite"
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.version }}
coverage: ${{ inputs.coverage }}
tools: composer, ${{ inputs.tools }}
extensions: none, curl, dom, json, mbstring, opcache, openssl, simplexml, tokenizer, xml, xmlwriter, zip
148 changes: 65 additions & 83 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ concurrency:
group: ci-${{ github.head_ref || github.run_id }} # will be canceled on subsequent pushes in pull requests but not branches
cancel-in-progress: true

env:
PHP_MAX: '8.2'
PHP_MIN: '7.4'

jobs:
tests:
strategy:
Expand All @@ -21,7 +25,6 @@ jobs:
php-version: '7.4'
job-description: 'Fixer with lowest deps'
run-fixer: 'yes'
run-phpdoc-to-native-type: 'yes' # should be checked on the lowest supported PHP version
composer-flags: '--prefer-lowest' # should be checked on the lowest supported PHP version
execute-flex-with-symfony-version: '^5' # explicit check for Symfony 5.x compatibility

Expand Down Expand Up @@ -67,31 +70,21 @@ jobs:

- operating-system: 'ubuntu-20.04'
php-version: '8.2'
job-description: 'tests with migration rules'
run-tests: 'yes'
run-migration-rules: 'yes' # should be checked on the highest supported PHP version

- operating-system: 'ubuntu-20.04'
php-version: '8.2'
job-description: 'auto-review'
job-description: 'tests'
run-tests: 'yes'
phpunit-flags: '--group auto-review'

- operating-system: 'ubuntu-20.04'
php-version: '8.2'
job-description: 'tests'
job-description: 'tests with migration rules'
run-tests: 'yes'
run-migration-rules: 'yes' # should be checked on the highest supported PHP version

- operating-system: 'ubuntu-20.04'
php-version: '8.2'
job-description: 'code coverage'
run-tests: 'yes'
collect-code-coverage: 'yes'

- operating-system: 'ubuntu-20.04'
php-version: '8.2'
job-description: 'deployment check'
execute-deployment: 'yes'

- operating-system: 'windows-latest'
php-version: '8.2'
job-description: 'Fixer on Windows'
Expand Down Expand Up @@ -138,62 +131,22 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

- name: Resolve PHP coverage flag
uses: actions/github-script@v6
id: setup-php-resolve-coverage
with:
script: 'return "${{ matrix.code-coverage }}" == "yes" ? "pcov" : "none"'
result-encoding: string

- name: Resolve PHP tools flag
uses: actions/github-script@v6
id: setup-php-resolve-tools
with:
script: 'return "${{ matrix.execute-flex-with-symfony-version }}" ? "flex" : "none"'
result-encoding: string

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: none, curl, dom, json, mbstring, opcache, openssl, simplexml, tokenizer, xml, xmlwriter, zip
coverage: ${{ steps.setup-php-resolve-coverage.outputs.result }}
tools: composer, ${{ steps.setup-php-resolve-tools.outputs.result }}

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

- name: Cache dependencies
uses: actions/cache@v3
- name: Setup PHP with Composer deps
uses: ./.github/composite-actions/setup-php-with-composer-deps
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-${{ matrix.composer-flags }}
restore-keys: |
composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-
composer-${{ runner.os }}-${{ matrix.php-version }}-
composer-${{ runner.os }}-
composer-
- name: Configure Symfony Flex
if: matrix.execute-flex-with-symfony-version
run: composer config extra.symfony.require ${{ matrix.execute-flex-with-symfony-version }}

- name: Install dependencies
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
retry_wait_seconds: 30
command: |
composer update --optimize-autoloader --no-interaction --no-progress --no-scripts ${{ matrix.composer-flags }} # --no-scripts to avoid installing dev-tools for all jobs on CI level
composer info -D
# execute migration rules before running tests and self-fixing,
# so that we know that our codebase is future-ready
os: ${{ runner.os }}
php: ${{ matrix.php-version }}
php-coverage: ${{ matrix.collect-code-coverage }}
composer-flags: ${{ matrix.composer-flags }}
composer-flex-with-symfony-version: ${{ matrix.execute-flex-with-symfony-version }}

# Execute migration rules before running tests and self-fixing,
# so we know that our codebase is future-ready.
# Should be checked on the highest supported PHP version.
- name: Run PHP CS Fixer with migration rules
if: matrix.run-migration-rules == 'yes'
if: env.PHP_MAX == matrix.php-version && matrix.run-migration-rules == 'yes'
env:
PHP_CS_FIXER_FUTURE_MODE: 1
run: php php-cs-fixer fix --config .php-cs-fixer.php-highest.php -q

- name: Disable time limit for tests when collecting coverage
Expand All @@ -205,33 +158,62 @@ jobs:
env:
PHP_CS_FIXER_IGNORE_ENV: ${{ matrix.PHP_CS_FIXER_IGNORE_ENV }}
FAST_LINT_TEST_CASES: ${{ matrix.FAST_LINT_TEST_CASES }}
run: vendor/bin/paraunit run ${{ matrix.phpunit-flags || '--exclude-group auto-review' }}
run: vendor/bin/paraunit run --testsuite unit,integration

- name: Collect code coverage
if: matrix.collect-code-coverage == 'yes'
- name: Run tests and collect code coverage
if: matrix.run-tests == 'yes' && matrix.collect-code-coverage == 'yes'
env:
FAST_LINT_TEST_CASES: 1
run: vendor/bin/paraunit coverage --testsuite coverage --exclude-group covers-nothing --clover build/logs/clover.xml
run: vendor/bin/paraunit coverage --testsuite unit --exclude-group covers-nothing --clover build/logs/clover.xml

- name: Upload coverage results to Coveralls
if: matrix.collect-code-coverage == 'yes'
if: matrix.run-tests == 'yes' && matrix.collect-code-coverage == 'yes'
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: php vendor/bin/php-coveralls --verbose

- name: Run PHP CS Fixer with PHPDoc to type rules
if: matrix.run-phpdoc-to-native-type == 'yes'
run: php php-cs-fixer check --diff -v --config .php-cs-fixer.php-lowest.php

- name: Run PHP CS Fixer
if: matrix.run-fixer == 'yes'
env:
PHP_CS_FIXER_IGNORE_ENV: ${{ matrix.PHP_CS_FIXER_IGNORE_ENV }}
PHP_CS_FIXER_FUTURE_MODE: 1
run: php php-cs-fixer check --diff -v

- name: Execute deployment checks
if: matrix.execute-deployment == 'yes'
run: |
./dev-tools/build.sh
PHP_CS_FIXER_TEST_ALLOW_SKIPPING_SMOKE_TESTS=0 vendor/bin/phpunit tests/Smoke/
# Should be checked on the lowest supported PHP version.
# If any type can be converted from PHPDoc to native type on lowest supported PHP, we should commit such change.
- name: Run PHP CS Fixer with PHPDoc to type rules
if: env.PHP_MIN == matrix.php-version && matrix.run-fixer == 'yes'
env:
PHP_CS_FIXER_FUTURE_MODE: 1
run: php php-cs-fixer check --diff -v --config .php-cs-fixer.php-lowest.php

deployment:
needs: tests
strategy:
fail-fast: false
matrix:
include:
- operating-system: 'ubuntu-20.04'
php-version: '8.2'

name: Deployment checks

runs-on: ${{ matrix.operating-system }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP with Composer deps
uses: ./.github/composite-actions/setup-php-with-composer-deps
with:
os: ${{ runner.os }}
php: ${{ matrix.php-version }}

- name: Build phar
run: ./dev-tools/build.sh

- name: Run smoke tests
env:
FAST_LINT_TEST_CASES: 1
run: vendor/bin/phpunit --testsuite smoke
40 changes: 7 additions & 33 deletions .github/workflows/sca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,43 +28,14 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
- name: Setup PHP with Composer deps
uses: ./.github/composite-actions/setup-php-with-composer-deps
with:
php-version: ${{ matrix.php-version }}
extensions: none, curl, dom, json, mbstring, opcache, simplexml, tokenizer, xml, xmlwriter, zip
coverage: none # without this Xdebug will be enabled
os: ${{ runner.os }}
php: ${{ matrix.php-version }}
tools: cs2pr

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

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-${{ matrix.composer-flags }}
restore-keys: |
composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-
composer-${{ runner.os }}-${{ matrix.php-version }}-
composer-${{ runner.os }}-
composer-
- name: Install dependencies
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
retry_wait_seconds: 30
command: composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }}

- name: Report versions
run: composer info -D

## We want to have a lock-file used on PR level, so contributors are not bothered by SCA complains unrelated to their changes,
## and same time we want to be aware that we are complying with bleeding edge of SCA tools as maintainers observing the push hook.
- name: Unlock dev-tools
Expand All @@ -79,6 +50,9 @@ jobs:
retry_wait_seconds: 30
command: ./dev-tools/install.sh

- name: Run AutoReview
run: vendor/bin/paraunit run --testsuite auto-review

- name: Check - file permissions
run: ./dev-tools/check_file_permissions.sh

Expand Down

0 comments on commit 74f6ba0

Please sign in to comment.