Skip to content

Refactor CI for forked repositories - POC #74

Refactor CI for forked repositories - POC

Refactor CI for forked repositories - POC #74

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' }}
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: Upload coverage as artifact
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
uses: actions/upload-artifact@v4
with:
name: ${{ env.COVERAGE_ARTIFACT_NAME }}
path: "build/coverage-*"
if-no-files-found: error
- name: Upload matrix output
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
uses: cloudposse/github-action-matrix-outputs-write@v1
id: out
with:
matrix-step-name: php-version-and-artifact
matrix-key: ${{ strategy.job-index }}
outputs: |-
version: ${{ matrix.php-version }}
artifact: ${{ env.COVERAGE_ARTIFACT_NAME }}
data: '{"version": "${{ matrix.php-version }}", "artifact": "${{ env.COVERAGE_ARTIFACT_NAME }}"}'
debug-output:
name: DEBUG
runs-on: ubuntu-latest
needs: [ tests ]
outputs:
matrix: ${{ steps.fetch-data.outputs.result }}
steps:
- uses: cloudposse/github-action-matrix-outputs-read@v1
id: fetch-data
with:
matrix-step-name: php-version-and-artifact
debug-output2:
name: DEBUG2
runs-on: ubuntu-latest
needs: [ debug-output ]
strategy:
matrix:
data: ${{ fromJson(needs.debug-output.outputs.matrix).data.* }}
steps:
- name: matrix.data
run: echo "${{ matrix.data }}"
- name: fromJson(matrix.data)
run: echo "${{ fromJson(matrix.data) }}"
- name: fromJson(matrix.data).version
run: echo "${{ fromJson(matrix.data).version }}"
debug-output2-2:
name: DEBUG2-2
runs-on: ubuntu-latest
needs: [ debug-output ]
strategy:
matrix:
version: ${{ fromJson(needs.debug-output.outputs.matrix).data.version.* }}
artifact: ${{ fromJson(needs.debug-output.outputs.matrix).data.artifact.* }}
steps:
- name: matrix.data
run: echo "${{ matrix.data }}"
- name: fromJson(matrix.data)
run: echo "${{ fromJson(matrix.data) }}"
- name: fromJson(matrix.data).version
run: echo "${{ fromJson(matrix.data).version }}"
debug-output2-3:
name: DEBUG2-3
runs-on: ubuntu-latest
needs: [ debug-output ]
strategy:
matrix: ${{ fromJson(needs.debug-output.outputs.matrix) }}
steps:
- name: matrix.data
run: echo "${{ matrix.data }}"
- name: fromJson(matrix.data)
run: echo "${{ fromJson(matrix.data) }}"
- name: fromJson(matrix.data).version
run: echo "${{ fromJson(matrix.data).version }}"
debug-output3:
name: DEBUG3
runs-on: ubuntu-latest
needs: [ debug-output ]
steps:
- name: needs.debug-output.outputs
run: echo "${{ needs.debug-output.outputs }}"
- name: toJson(needs.debug-output.outputs)
run: echo "${{ toJson(needs.debug-output.outputs) }}"
- name: needs.debug-output.outputs.matrix
run: echo "${{ needs.debug-output.outputs.matrix }}"
- name: toJson(needs.debug-output.outputs.matrix)
run: echo "${{ toJson(needs.debug-output.outputs.matrix) }}"
- name: fromJson(needs.debug-output.outputs.matrix)
run: echo "${{ fromJson(needs.debug-output.outputs.matrix) }}"
- name: fromJson(needs.debug-output.outputs.matrix).data
run: echo "${{ fromJson(needs.debug-output.outputs.matrix) }}"
- name: fromJson(needs.debug-output.outputs.matrix).data.*
run: echo "${{ fromJson(needs.debug-output.outputs.matrix).* }}"
- name: toJson(needs.debug-output.outputs.matrix.*)
run: echo "${{ toJson(needs.debug-output.outputs.matrix.*) }}"
- name: toJson(needs.debug-output.outputs.matrix).*
run: echo "${{ toJson(needs.debug-output.outputs.matrix).* }}"
- name: needs.debug-output.outputs.matrix.data
run: echo "${{ needs.debug-output.outputs.matrix.data }}"
- name: toJson(needs.debug-output.outputs.matrix).data
run: echo "${{ toJson(needs.debug-output.outputs.matrix).data }}"
- name: toJson(needs.debug-output.outputs.matrix.data.*)
run: echo "${{ toJson(needs.debug-output.outputs.matrix.data.*) }}"
- name: toJson(needs.debug-output.outputs.matrix).data.*
run: echo "${{ toJson(needs.debug-output.outputs.matrix).data.* }}"
# - 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