Skip to content

Refactor CI for forked repositories - POC #148

Refactor CI for forked repositories - POC

Refactor CI for forked repositories - POC #148

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-codecov-coverage-report:
name: Prepare Codecov coverage report
runs-on: ubuntu-latest
needs: [ tests ]
steps:
- name: Check out code # Just to be able to load custom action below !
uses: actions/checkout@v3
- name: Download all PHP coverage artifacts
uses: actions/download-artifact@v4
with:
pattern: coverage-report-*
path: coverage-reports
merge-multiple: true
- name: DEBUG
run: ls -ail coverage-reports/* coverage-reports/*/*
- name: DEBUG2
uses: ./.github/actions/grouped-reports-matrix
with:
root: coverage-reports
# - name: Build upload metadata
# id: upload-metadata
# run: |
# METADATA_FILE_LIST=$(find ./coverage-reports -type f -name "metadata.json")
# for METADATA_FILE in $METADATA_FILE_LIST;
# do
# echo "Processing $METADATA_FILE file...";
# WS=$(dirname $METADATA_FILE)
# UNIT_REPORT_FILE_LIST=$(find $WS -type f -name "*-clover.xml")
# echo "unit-files=$(echo FILES | tr "\n" ",") >> "$GITHUB_OUTPUT"
# echo "unit-flags=$(find ./coverage-reports -type f -name "*-clover.xml" | tr "\n" ",") >> "$GITHUB_OUTPUT"
# done
#
# - name: DEBUG2
# run: echo "${{ steps.step1.file-list-builder.files }}"
#
# # 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' }}
upload-codacy-coverage-report:
name: Upload Codacy coverage report
runs-on: ubuntu-latest
needs: [ tests ]
steps:
- name: Download all PHP coverage artifacts
uses: actions/download-artifact@v4
with:
pattern: coverage-report-*
path: coverage-reports
merge-multiple: true
- name: DEBUG
run: ls -ail coverage-reports/* coverage-reports/*/*
- name: Find available files
id: list-builder
run: |
find ./coverage-reports -type f -name "report-*" | tr "\n" ","
echo "files=$(find ./coverage-reports -type f -name "report-*" | tr "\n" ",")" >> "$GITHUB_OUTPUT"
# - name: DEBUG2
# run: echo "${{ steps.step1.file-list-builder.files }}"
#
# - name: Run codacy-coverage-reporter
# uses: codacy/codacy-coverage-reporter-action@v1
# with:
# project-token: ${{ secrets.ENV_CODACY_PROJECT_TOKEN }}
# coverage-reports: coverage-reports/*/coverage-phpunit/unit.clover,coverage-reports/*/coverage-behat/clover.xml,coverage-reports/*/coverage-phpunit/functional.clover