Skip to content

Enhance

Enhance #165

Workflow file for this run

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 }}
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' }} # DEBUG - Uncomment before merging !
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
fail-fast: true # step will fail if an extension or tool fails to set up
with:
php-version: '${{ matrix.php-version }}'
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: Create "unit tests" coverage report group
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
uses: ./.github/actions/group-coverage-reports
with:
name: unit-tests-php${{ matrix.php-version }}
files: build/coverage-phpunit/unit.clover
flags: unit-tests,php-${{ matrix.php-version }}
root: build/coverage-reports-groups
- name: Create "functional tests" coverage report group
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
uses: ./.github/actions/group-coverage-reports
with:
name: functional-tests-php${{ matrix.php-version }}
files: build/coverage-phpunit/functional.clover,build/coverage-behat/clover.xml
flags: functional-tests,php-${{ matrix.php-version }}
root: build/coverage-reports-groups
# run: |
# echo "::group::Coverage files for PHP ${{ matrix.php-version }}"
# ls -l build/coverage-*
# echo "::endgroup::"
# mkdir -p build/coverage-report/{unit,functional}
# # Unit tests
# echo '{"name": "unit-tests-php${{ matrix.php-version }}", "format": "clover", "flags": ["unit-tests", "php-${{ matrix.php-version }}"]}' > build/coverage-report/unit/metadata.json
# mv build/coverage-phpunit/unit.clover build/coverage-report/unit/phpunit-clover.xml
# # Functional tests
# echo '{"format": "clover", "flags": ["unit-tests", "php-${{ matrix.php-version }}"]}' > build/coverage-report/unit/metadata.json
# mv build/coverage-phpunit/functional.clover build/coverage-report/functional-tests-php${{ matrix.php-version }}/phpunit-clover.xml
# mv build/coverage-behat/clover.xml build/coverage-report/functional-tests-php${{ matrix.php-version }}/behat-clover.xml
- name: Upload coverage as artifact
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
uses: actions/upload-artifact@v4
with:
name: coverage-report-php${{ matrix.php-version }}
path: build/coverage-reports-groups
if-no-files-found: error
prepare-coverage-reports:
name: Prepare coverage reports
runs-on: ubuntu-latest
needs: [ tests ]
outputs:
info: ${{ steps.fetch-info.outputs.info }}
matrix: ${{ steps.fetch-info.outputs.matrix }}
reports: ${{ steps.fetch-info.outputs.reports }}
steps:
- name: Check out code # Just to be able to load custom action below !
uses: actions/checkout@v3
- name: Fetch info
id: fetch-info
uses: ./.github/actions/grouped-reports-matrix
with:
pattern: coverage-report-*
upload-codecov-coverage-report:
name: Upload ${{ matrix.name }} reports to codecov
runs-on: ubuntu-latest
needs: [ prepare-coverage-reports ]
env:
ARTEFACT_PATH: coverage-reports
strategy:
fail-fast: true
max-parallel: 4
matrix: ${{ fromJson(needs.prepare-coverage-reports.outputs.matrix) }}
steps:
- name: DEBUG
run: |
echo "${{ toJson(matrix) }}"
- name: Download coverage artifact
uses: actions/download-artifact@v4
with:
pattern: ${{ matrix.artifact }}
path: ${{ env.ARTEFACT_PATH }}
- name: Build upload metadata
id: build-metadata
uses: actions/github-script@v7
env:
NAME: ${{ matrix.flags }}
FLAGS: ${{ matrix.flags }}
PATH: ${{ matrix.path }}
REPORTS: ${{ matrix.reports }}
with:
script: |
const { NAME, FLAGS, ARTEFACT_PATH, PATH, REPORTS } = process.env;
core.setOutput("name", NAME);
core.setOutput("files", JSON.parse(REPORTS).map(f => `${ARTEFACT_PATH}/${PATH}/${f}`).join(','));
core.setOutput("flags", JSON.parse(FLAGS).map(f => `${PATH}/${f}`).join(','));
# 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:
name: ${{ steps.build-metadata.outputs.name }}
files: ${{ steps.build-metadata.outputs.files }}
flags: ${{ steps.build-metadata.outputs.flags }}
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
verbose: ${{ runner.debug == '1' }}
upload-codacy-coverage-report:
name: Upload coverage reports to Codacy
runs-on: ubuntu-latest
needs: [ prepare-coverage-reports ]
steps:
- name: Download all PHP coverage artifacts
uses: actions/download-artifact@v4
with:
pattern: coverage-report-*
path: coverage-reports
- name: Debug
uses: actions/github-script@v7
with:

Check failure on line 197 in .github/workflows/CI.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/CI.yml

Invalid workflow file

You have an error in your yaml syntax on line 197
script: |
const { ARTEFACT_PATH } = process.env;
const globber = await glob.create(`${ARTEFACT_PATH}/**/report-*,${ARTEFACT_PATH}/**/metadata.json`);
core.info(`test='${JSON.stringify(await globber.glob())}'`);
- name: Build upload metadata
id: build-metadata
uses: actions/github-script@v7
env:
REPORTS: ${{ needs.prepare-coverage-reports.outputs.reports }}
with:
script: |
const { REPORTS } = process.env;
core.setOutput("files", JSON.parse(REPORTS).join(','));
- name: Run codacy-coverage-reporter
uses: codacy/codacy-coverage-reporter-action@v1
with:
coverage-reports: ${{ steps.build-metadata.outputs.files }}
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}