Skip to content

Commit 9bcc6b3

Browse files
authored
Refactor CI for fork PR (#26)
1 parent 7e2fb89 commit 9bcc6b3

File tree

1 file changed

+34
-64
lines changed

1 file changed

+34
-64
lines changed

.github/workflows/CI.yml

+34-64
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on: # Build any PRs and main branch changes
44
pull_request:
55
types:
66
- opened
7-
- edited
87
- synchronize
98
push:
109
branches: [ master ]
@@ -18,8 +17,6 @@ concurrency:
1817
env:
1918
TEST_OUTPUT_STYLE: pretty
2019
COMPOSER_OPTIONS: --optimize-autoloader
21-
CODACY_CACHE_PATH: ~/.cache/codacy
22-
CODACY_BIN: ~/.cache/codacy/codacy.sh
2320

2421
jobs:
2522
tests:
@@ -49,13 +46,13 @@ jobs:
4946
5047
- name: Setup PHP ${{ matrix.php-version }}
5148
uses: shivammathur/setup-php@v2
49+
env:
50+
update: true # Always use latest available patch for the version
51+
fail-fast: true # step will fail if an extension or tool fails to set up
5252
with:
5353
php-version: '${{ matrix.php-version }}'
5454
tools: composer
5555
coverage: ${{ env.COVERAGE_TYPE }}
56-
env:
57-
# Always use latest available patch for the version
58-
update: true
5956

6057
- name: Setup cache
6158
id: cache
@@ -64,18 +61,9 @@ jobs:
6461
path: |
6562
~/.composer
6663
./vendor
67-
${{ env.CODACY_CACHE_PATH }}
6864
# Clear the cache if composer json (as composer.lock is in the repo) has been updated
6965
key: tests-${{ matrix.php-version }}-${{ matrix.composer-flag }}-${{ hashFiles('composer.json') }}
7066

71-
- name: Download codacy binary
72-
if: steps.cache.outputs.cache-hit != 'true'
73-
run: |
74-
mkdir -p ${{ env.CODACY_CACHE_PATH }} \
75-
&& curl -LN https://coverage.codacy.com/get.sh -o ${{ env.CODACY_BIN }} \
76-
&& chmod +x ${{ env.CODACY_BIN }} \
77-
&& ${{ env.CODACY_BIN }} download
78-
7967
- name: Build
8068
run: |
8169
composer update ${{ env.COMPOSER_OPTIONS }} ${{ matrix.composer-flag }} \
@@ -84,34 +72,41 @@ jobs:
8472
- name: Tests
8573
run: make test-unit && make test-functional
8674

87-
# Upload to codacy first as codecov action always remove coverage files despite move_coverage_to_trash at false
88-
# And only if it's not a PR from a fork => Can't work as codacy secret is not accessible in that context
89-
- name: Upload coverages to Codacy
90-
if: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'yoanm/php-jsonrpc-http-server-openapi-doc-sdk') && env.COVERAGE_TYPE == 'xdebug' }}
91-
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
92-
93-
# See the reports at https://codecov.io/gh/yoanm/php-jsonrpc-http-server-openapi-doc-sdk
94-
- name: Upload unit tests coverage to codecov
75+
- name: Create "unit tests" reports group
9576
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
96-
uses: codecov/codecov-action@v3
77+
id: unit-tests-coverage-group
78+
uses: yoanm/tmp-reports-group-workspace/.github/actions/create-action@develop
9779
with:
98-
file: "build/coverage-phpunit/unit.clover"
99-
name: "unit-tests-${{ matrix.php-version }}"
100-
flags: "unit-tests,php-${{ matrix.php-version }}"
101-
fail_ci_if_error: true
102-
move_coverage_to_trash: false
103-
verbose: ${{ runner.debug == '1' }}
104-
105-
- name: Upload functional tests coverage to codecov
80+
name: unit-tests
81+
format: clover
82+
files: build/coverage-phpunit/unit.clover
83+
flags: |
84+
unit-tests
85+
php-${{ matrix.php-version }}
86+
path: build/coverage-groups
87+
88+
- name: Create "functional tests" coverage group
10689
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
107-
uses: codecov/codecov-action@v3
90+
id: functional-tests-coverage-group
91+
uses: yoanm/tmp-reports-group-workspace/.github/actions/create-action@develop
10892
with:
109-
files: "build/coverage-behat/clover.xml,build/coverage-phpunit/functional.clover"
110-
name: "functional-tests-${{ matrix.php-version }}"
111-
flags: "functional-tests,php-${{ matrix.php-version }}"
112-
fail_ci_if_error: true
113-
move_coverage_to_trash: false
114-
verbose: ${{ runner.debug == '1' }}
93+
name: functional-tests
94+
format: clover
95+
files: |
96+
build/coverage-phpunit/functional.clover
97+
build/coverage-behat/clover.xml
98+
flags: |
99+
functional-tests
100+
php-${{ matrix.php-version }}
101+
path: build/coverage-groups
102+
103+
- name: Upload coverage reports
104+
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
105+
uses: actions/upload-artifact@v4
106+
with:
107+
name: coverage-groups-php${{ matrix.php-version }}
108+
path: build/coverage-groups
109+
if-no-files-found: error
115110

116111
static-checks:
117112
name: Static checks
@@ -148,31 +143,6 @@ jobs:
148143
if: ${{ github.event_name == 'pull_request' }}
149144
uses: actions/dependency-review-action@v1
150145

151-
finalize-codacy-coverage-report:
152-
runs-on: ubuntu-latest
153-
name: Finalize Codacy coverage report
154-
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'yoanm/php-jsonrpc-http-server-openapi-doc-sdk' }}
155-
needs: [ tests ]
156-
steps:
157-
- name: Setup cache
158-
id: cache
159-
uses: actions/cache@v3
160-
with:
161-
path: |
162-
${{ env.CODACY_CACHE_PATH }}
163-
key: codacy-final
164-
165-
- name: Download codacy binary
166-
if: steps.cache.outputs.cache-hit != 'true'
167-
run: |
168-
mkdir -p ${{ env.CODACY_CACHE_PATH }} \
169-
&& curl -LN https://coverage.codacy.com/get.sh -o ${{ env.CODACY_BIN }} \
170-
&& chmod +x ${{ env.CODACY_BIN }} \
171-
&& ${{ env.CODACY_BIN }} download
172-
173-
- name: Finalize reporting
174-
run: ${{ env.CODACY_BIN }} final -t ${{ secrets.CODACY_PROJECT_TOKEN }}
175-
176146
nightly-tests:
177147
name: Nightly - PHP ${{ matrix.php-version }}
178148
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)