Skip to content

Commit

Permalink
Refactor CI for fork PR
Browse files Browse the repository at this point in the history
  • Loading branch information
yoanm committed Mar 25, 2024
1 parent 48a995b commit ad13c70
Showing 1 changed file with 26 additions and 64 deletions.
90 changes: 26 additions & 64 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on: # Build any PRs and main branch changes
pull_request:
types:
- opened
- edited
- synchronize
push:
branches: [ master ]
Expand All @@ -18,8 +17,6 @@ concurrency:
env:
TEST_OUTPUT_STYLE: pretty
COMPOSER_OPTIONS: --optimize-autoloader
CODACY_CACHE_PATH: ~/.cache/codacy
CODACY_BIN: ~/.cache/codacy/codacy.sh

jobs:
tests:
Expand Down Expand Up @@ -49,13 +46,13 @@ jobs:
- 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 }}
env:
# Always use latest available patch for the version
update: true

- name: Setup cache
id: cache
Expand All @@ -64,18 +61,9 @@ jobs:
path: |
~/.composer
./vendor
${{ env.CODACY_CACHE_PATH }}
# 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: Download codacy binary
if: steps.cache.outputs.cache-hit != 'true'
run: |
mkdir -p ${{ env.CODACY_CACHE_PATH }} \
&& curl -LN https://coverage.codacy.com/get.sh -o ${{ env.CODACY_BIN }} \
&& chmod +x ${{ env.CODACY_BIN }} \
&& ${{ env.CODACY_BIN }} download
- name: Build
run: |
composer update ${{ env.COMPOSER_OPTIONS }} ${{ matrix.composer-flag }} \
Expand All @@ -84,34 +72,33 @@ jobs:
- name: Tests
run: make test-unit && make test-functional

# Upload to codacy first as codecov action always remove coverage files despite move_coverage_to_trash at false
# And only if it's not a PR from a fork => Can't work as codacy secret is not accessible in that context
- name: Upload coverages to Codacy
if: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'yoanm/php-jsonrpc-server-doc-sdk') && env.COVERAGE_TYPE == 'xdebug' }}
run: ${{ env.CODACY_BIN }} report -r build/coverage-phpunit/unit.clover -r build/coverage-behat/clover.xml -r build/coverage-phpunit/functional.clover -t ${{ secrets.CODACY_PROJECT_TOKEN }} --partial

# See the reports at https://codecov.io/gh/yoanm/php-jsonrpc-server-doc-sdk
- name: Upload unit tests coverage to codecov
- name: Create "unit tests" reports group
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
uses: codecov/codecov-action@v3
id: unit-tests-coverage-group
uses: yoanm/tmp-reports-group-workspace/.github/actions/create-action@develop
with:
file: "build/coverage-phpunit/unit.clover"
name: "unit-tests-${{ matrix.php-version }}"
flags: "unit-tests,php-${{ matrix.php-version }}"
fail_ci_if_error: true
move_coverage_to_trash: false
verbose: ${{ runner.debug == '1' }}

- name: Upload functional tests coverage to codecov
name: unit-tests
format: clover
files: build/coverage-phpunit/unit.clover
flags: |
unit-tests
php-${{ matrix.php-version }}
path: build/coverage-groups

- name: Create "functional tests" coverage group
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
uses: codecov/codecov-action@v3
id: functional-tests-coverage-group
uses: yoanm/tmp-reports-group-workspace/.github/actions/create-action@develop
with:
files: "build/coverage-behat/clover.xml,build/coverage-phpunit/functional.clover"
name: "functional-tests-${{ matrix.php-version }}"
flags: "functional-tests,php-${{ matrix.php-version }}"
fail_ci_if_error: true
move_coverage_to_trash: false
verbose: ${{ runner.debug == '1' }}
name: functional-tests
format: clover
files: |
build/coverage-phpunit/functional.clover
build/coverage-behat/clover.xml
flags: |
functional-tests
php-${{ matrix.php-version }}
path: build/coverage-groups

static-checks:
name: Static checks
Expand Down Expand Up @@ -148,31 +135,6 @@ jobs:
if: ${{ github.event_name == 'pull_request' }}
uses: actions/dependency-review-action@v1

finalize-codacy-coverage-report:
runs-on: ubuntu-latest
name: Finalize Codacy coverage report
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'yoanm/php-jsonrpc-server-doc-sdk' }}
needs: [ tests ]
steps:
- name: Setup cache
id: cache
uses: actions/cache@v3
with:
path: |
${{ env.CODACY_CACHE_PATH }}
key: codacy-final

- name: Download codacy binary
if: steps.cache.outputs.cache-hit != 'true'
run: |
mkdir -p ${{ env.CODACY_CACHE_PATH }} \
&& curl -LN https://coverage.codacy.com/get.sh -o ${{ env.CODACY_BIN }} \
&& chmod +x ${{ env.CODACY_BIN }} \
&& ${{ env.CODACY_BIN }} download
- name: Finalize reporting
run: ${{ env.CODACY_BIN }} final -t ${{ secrets.CODACY_PROJECT_TOKEN }}

nightly-tests:
name: Nightly - PHP ${{ matrix.php-version }}
runs-on: ubuntu-latest
Expand Down

0 comments on commit ad13c70

Please sign in to comment.