Refactor CI for forked repositories - POC #48
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 'CI' | ||
on: # Build any PRs and main branch changes | ||
workflow_dispatch: # Allows to run the workflow manually from the Actions tab | ||
pull_request: | ||
types: | ||
- opened | ||
- edited | ||
- synchronize | ||
push: | ||
branches: [ master ] | ||
schedule: | ||
- cron: '0 0 1 * *' # Every month | ||
concurrency: | ||
group: "${{ github.workflow }}-${{ github.head_ref || github.ref }}" | ||
cancel-in-progress: true | ||
env: | ||
TEST_OUTPUT_STYLE: pretty | ||
COMPOSER_OPTIONS: --optimize-autoloader | ||
CODACY_CACHE_PATH: ~/.cache/codacy | ||
CODACY_BIN: ~/.cache/codacy/codacy.sh | ||
jobs: | ||
tests: | ||
name: UTs & FTs - PHP ${{ matrix.php-version }} | ||
runs-on: ubuntu-latest | ||
env: | ||
COVERAGE_TYPE: none | ||
COVERAGE_ARTIFACT_NAME: coverage-php${{ matrix.php-version }} | ||
outputs: | ||
php${{ matrix.php-version }}: ${{ steps.output-data.outputs.data }} | ||
Check failure on line 32 in .github/workflows/CI.yml GitHub Actions / CIInvalid workflow file
|
||
strategy: | ||
fail-fast: true | ||
max-parallel: 4 | ||
matrix: | ||
include: | ||
# Bare minimum => Lowest versions allowed by composer config | ||
- php-version: '8.0' | ||
composer-flag: --prefer-lowest | ||
# Up-to-date versions => Latest versions allowed by composer config | ||
- php-version: '8.2' | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
- name: Enable coverage | ||
if: ${{ matrix.php-version == '8.2' }} | ||
run: | | ||
echo "COVERAGE_OUTPUT_STYLE=clover" >> $GITHUB_ENV | ||
echo "COVERAGE_TYPE=xdebug" >> $GITHUB_ENV | ||
- name: Setup PHP ${{ matrix.php-version }} | ||
uses: shivammathur/setup-php@v2 | ||
env: | ||
update: true # Always use latest available patch for the version | ||
with: | ||
php-version: '${{ matrix.php-version }}' | ||
fail-fast: true # Fails if an extension or tool fails to set up | ||
tools: composer | ||
coverage: ${{ env.COVERAGE_TYPE }} | ||
- name: Setup cache | ||
id: cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.composer | ||
./vendor | ||
# Clear the cache if composer json (as composer.lock is in the repo) has been updated | ||
key: tests-${{ matrix.php-version }}-${{ matrix.composer-flag }}-${{ hashFiles('composer.json') }} | ||
- name: Build | ||
run: | | ||
make build | ||
- name: Tests | ||
run: make test-unit && make test-functional | ||
- name: Upload coverage as artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ env.COVERAGE_ARTIFACT_NAME }} | ||
path: "build/coverage-*" | ||
if-no-files-found: error | ||
- name: Prepare output | ||
id: output-data | ||
run: | | ||
echo 'data={ "matrix": {"php-version": "${{ matrix.php-version }}", "artifact": "${{ env.COVERAGE_ARTIFACT_NAME }}"}}' >> $GITHUB_OUTPUT | ||
debug-output: | ||
name: DEBUG | ||
runs-on: ubuntu-latest | ||
needs: [ tests ] | ||
steps: | ||
- run: echo "${{ toJson(needs.tests.outputs.*.matrix) }}" | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
pattern: coverage-php* | ||
path: coverage-data | ||
- run: ls -ail coverage-data | ||
# codecov-coverage-report: | ||
# name: Codecov coverage report | ||
# runs-on: ubuntu-latest | ||
# environment: ci-codecov | ||
# needs: [tests] | ||
# strategy: | ||
# fail-fast: true | ||
# max-parallel: 4 | ||
# matrix: | ||
# include: ${{ needs.tests.outputs.*.matrix }} | ||
# steps: | ||
# - name: Download PHP ${{ matrix.php-version }} coverage artifact | ||
# uses: actions/download-artifact@v4 | ||
# with: | ||
# name: ${{ matrix.artifact }} | ||
# path: coverage-data | ||
# | ||
# - name: DEBUG | ||
# run: ls -ail coverage-data | ||
# | ||
# # See the reports at https://codecov.io/gh/yoanm/php-jsonrpc-server-sdk | ||
# - name: Upload unit tests coverage to codecov | ||
# uses: codecov/codecov-action@v3 | ||
# with: | ||
# files: "coverage-data/coverage-phpunit/unit.clover" | ||
# name: "unit-tests-${{ matrix.php-version }}" | ||
# flags: "unit-tests,php-${{ matrix.php-version }}" | ||
# fail_ci_if_error: true | ||
# token: ${{ secrets.ENV_CODECOV_TOKEN }} | ||
# verbose: ${{ runner.debug == '1' }} | ||
# | ||
# - name: Upload functional tests coverage to codecov | ||
# if: ${{ env.COVERAGE_TYPE == 'xdebug' }} | ||
# uses: codecov/codecov-action@v4 | ||
# with: | ||
# files: "coverage-data/coverage-behat/clover.xml,coverage-data/coverage-phpunit/functional.clover" | ||
# name: "functional-tests-${{ matrix.php-version }}" | ||
# flags: "functional-tests,php-${{ matrix.php-version }}" | ||
# token: ${{ secrets.ENV_CODECOV_TOKEN }} | ||
# verbose: ${{ runner.debug == '1' }} | ||
# codacy-coverage-report: | ||
# name: Codacy coverage report | ||
# runs-on: ubuntu-latest | ||
# environment: ci-codacy | ||
# needs: [ tests ] | ||
# steps: | ||
# - name: Download all PHP coverage artifacts | ||
# uses: actions/download-artifact@v4 | ||
# with: | ||
# pattern: coverage-php* | ||
# path: coverage-data | ||
# | ||
# - name: DEBUG | ||
# run: ls -ail coverage-data | ||
# | ||
# - name: Find available files | ||
# run: | | ||
# ls -ail coverage-data/*/coverage-phpunit/unit.clover coverage-data/*/coverage-behat/clover.xml coverage-data/*/coverage-phpunit/functional.clover | ||
# | ||
# - name: Run codacy-coverage-reporter | ||
# uses: codacy/codacy-coverage-reporter-action@v1 | ||
# with: | ||
# project-token: ${{ secrets.ENV_CODACY_PROJECT_TOKEN }} | ||
# coverage-reports: coverage-data/*/coverage-phpunit/unit.clover,coverage-data/*/coverage-behat/clover.xml,coverage-data/*/coverage-phpunit/functional.clover |