Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: general restructure #7407

Merged
merged 33 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e9e9a2d
build.sh - same shell flags as everywhere else
keradus Nov 3, 2023
361ff95
extract composite actions
keradus Nov 3, 2023
f49a1c8
no need to specify fetch-depth
keradus Nov 3, 2023
c8fb47b
move execute-deployment to separated job
keradus Nov 3, 2023
b0700a1
automate decisions to run extra fixer calls
keradus Nov 3, 2023
e7231d9
CS
keradus Nov 3, 2023
38b067a
fix
keradus Nov 3, 2023
397af8d
move auto-review to SCA
keradus Nov 3, 2023
44a5ed7
update job name
keradus Nov 3, 2023
b2db833
Revert "update job name"
keradus Nov 3, 2023
7a39aca
Update .github/workflows/sca.yml
keradus Nov 3, 2023
67e2db9
fix flags after changes on master
keradus Nov 3, 2023
b0f4f89
Merge branch 'ci' of github.com:keradus/PHP-CS-Fixer into ci
keradus Nov 3, 2023
7ae5a2b
Autoreview extracted
keradus Nov 3, 2023
b15502a
further cleanup on auto-review and tests suites
keradus Nov 3, 2023
3743bd1
Update .github/composite-actions/install-composer-deps/action.yml
keradus Nov 3, 2023
e672d9f
CS
keradus Nov 3, 2023
4adfbc8
Merge branch 'ci' of github.com:keradus/PHP-CS-Fixer into ci
keradus Nov 3, 2023
f944f63
fix FAST_LINT_TEST_CASES var
keradus Nov 3, 2023
fc0c6e0
nested compose action
keradus Nov 3, 2023
81b1873
code-coverage collected
keradus Nov 3, 2023
e1f40ce
CS
keradus Nov 3, 2023
004257a
divide test:all further
keradus Nov 3, 2023
36fe205
composer normalize
keradus Nov 3, 2023
05688d3
drop outdated flag
keradus Nov 3, 2023
c6b7fac
NO-CACHE check job after cache-purge on repo
keradus Nov 3, 2023
07024c3
kick CI
keradus Nov 3, 2023
2db6d19
even longer composer-cache key, as we not always have lock files
keradus Nov 3, 2023
8a0dcd6
kick CI
keradus Nov 3, 2023
8e3f42d
kick CI 2
keradus Nov 3, 2023
a34a0cf
Update .github/workflows/sca.yml
keradus Nov 3, 2023
576dd87
----- MARKER -----
keradus Nov 4, 2023
5b3b02c
delete setup-cache, as NOT working anyway, and we have different need…
keradus Nov 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Wirone marked this conversation as resolved.
Show resolved Hide resolved
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
keradus marked this conversation as resolved.
Show resolved Hide resolved
cancel-in-progress: true
Wirone marked this conversation as resolved.
Show resolved Hide resolved

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