Skip to content

Commit 4f23197

Browse files
committed
Refactor CI for forked repositories
1 parent e142735 commit 4f23197

File tree

1 file changed

+89
-138
lines changed

1 file changed

+89
-138
lines changed

.github/workflows/CI.yml

Lines changed: 89 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ jobs:
2727
runs-on: ubuntu-latest
2828
env:
2929
COVERAGE_TYPE: none
30+
COVERAGE_ARTIFACT_NAME: coverage-php${{ matrix.php-version }}
31+
outputs:
32+
php${{ matrix.php-version }}: ${{ steps.output-data.outputs.data }}
3033
strategy:
3134
fail-fast: true
3235
max-parallel: 4
@@ -49,13 +52,13 @@ jobs:
4952
5053
- name: Setup PHP ${{ matrix.php-version }}
5154
uses: shivammathur/setup-php@v2
55+
env:
56+
update: true # Always use latest available patch for the version
5257
with:
5358
php-version: '${{ matrix.php-version }}'
59+
fail-fast: true # Fails if an extension or tool fails to set up
5460
tools: composer
5561
coverage: ${{ env.COVERAGE_TYPE }}
56-
env:
57-
# Always use latest available patch for the version
58-
update: true
5962

6063
- name: Setup cache
6164
id: cache
@@ -64,155 +67,103 @@ jobs:
6467
path: |
6568
~/.composer
6669
./vendor
67-
${{ env.CODACY_CACHE_PATH }}
6870
# Clear the cache if composer json (as composer.lock is in the repo) has been updated
6971
key: tests-${{ matrix.php-version }}-${{ matrix.composer-flag }}-${{ hashFiles('composer.json') }}
7072

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-
7973
- name: Build
8074
run: |
8175
make build
8276
8377
- name: Tests
8478
run: make test-unit && make test-functional
8579

86-
# Upload to codacy first as codecov action always remove coverage files despite move_coverage_to_trash at false
87-
# And only if it's not a PR from a fork => Can't work as codacy secret is not accessible in that context
88-
- name: Upload coverages to Codacy
89-
if: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'yoanm/php-jsonrpc-server-sdk') && env.COVERAGE_TYPE == 'xdebug' }}
90-
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
91-
92-
# See the reports at https://codecov.io/gh/yoanm/php-jsonrpc-server-sdk
93-
- name: Upload unit tests coverage to codecov
94-
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
95-
uses: codecov/codecov-action@v3
80+
- name: Upload coverage as artifact
81+
uses: actions/upload-artifact@v4
9682
with:
97-
file: "build/coverage-phpunit/unit.clover"
98-
name: "unit-tests-${{ matrix.php-version }}"
99-
flags: "unit-tests,php-${{ matrix.php-version }}"
100-
fail_ci_if_error: true
101-
move_coverage_to_trash: false
102-
verbose: ${{ runner.debug == '1' }}
83+
name: ${{ env.COVERAGE_ARTIFACT_NAME }}
84+
path: "build/coverage-*"
85+
if-no-files-found: error
10386

104-
- name: Upload functional tests coverage to codecov
105-
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
106-
uses: codecov/codecov-action@v3
107-
with:
108-
files: "build/coverage-behat/clover.xml,build/coverage-phpunit/functional.clover"
109-
name: "functional-tests-${{ matrix.php-version }}"
110-
flags: "functional-tests,php-${{ matrix.php-version }}"
111-
fail_ci_if_error: true
112-
move_coverage_to_trash: false
113-
verbose: ${{ runner.debug == '1' }}
87+
- name: Prepare output
88+
id: output-data
89+
run: |
90+
echo 'data={ "matrix": {"php-version": "${{ matrix.php-version }}", "artifact": "${{ env.COVERAGE_ARTIFACT_NAME }}"}}' >> $GITHUB_OUTPUT
11491
115-
static-checks:
116-
name: Static checks
92+
debug-output:
93+
name: DEBUG
11794
runs-on: ubuntu-latest
118-
steps:
119-
- uses: actions/checkout@v3
120-
121-
- name: Setup PHP 8.2
122-
uses: shivammathur/setup-php@v2
123-
with:
124-
php-version: 8.2 # Latest supported
125-
tools: composer
126-
coverage: none
127-
env:
128-
# Always use latest available patch for the version
129-
update: true
130-
131-
- name: Setup cache
132-
id: cache
133-
uses: actions/cache@v3
134-
with:
135-
path: |
136-
~/.composer
137-
# Clear the cache if composer json (as composer.lock is in the repo) has been updated
138-
key: tests-${{ env.PHP_VERSION }}-${{ hashFiles('composer.json') }}
139-
140-
- name: Build
141-
run: make build
142-
143-
- name: ComposerRequireChecker
144-
uses: docker://webfactory/composer-require-checker:4.5.0
145-
146-
- name: Dependencies check
147-
if: ${{ github.event_name == 'pull_request' }}
148-
uses: actions/dependency-review-action@v1
149-
150-
finalize-codacy-coverage-report:
151-
runs-on: ubuntu-latest
152-
name: Finalize Codacy coverage report
153-
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'yoanm/php-jsonrpc-server-sdk' }}
15495
needs: [ tests ]
15596
steps:
156-
- name: Setup cache
157-
id: cache
158-
uses: actions/cache@v3
97+
- run: echo "${{ toJson(needs.tests.outputs.*.matrix) }}"
98+
- uses: actions/download-artifact@v4
15999
with:
160-
path: |
161-
${{ env.CODACY_CACHE_PATH }}
162-
key: codacy-final
163-
164-
- name: Download codacy binary
165-
if: steps.cache.outputs.cache-hit != 'true'
166-
run: |
167-
mkdir -p ${{ env.CODACY_CACHE_PATH }} \
168-
&& curl -LN https://coverage.codacy.com/get.sh -o ${{ env.CODACY_BIN }} \
169-
&& chmod +x ${{ env.CODACY_BIN }} \
170-
&& ${{ env.CODACY_BIN }} download
171-
172-
- name: Finalize reporting
173-
run: ${{ env.CODACY_BIN }} final -t ${{ secrets.CODACY_PROJECT_TOKEN }}
174-
175-
nightly-tests:
176-
name: Nightly - PHP ${{ matrix.php-version }}
177-
runs-on: ubuntu-latest
178-
env:
179-
COMPOSER_OPTIONS: '--optimize-autoloader --ignore-platform-req=php+'
180-
continue-on-error: true
181-
needs: [ static-checks, tests ]
182-
strategy:
183-
fail-fast: false
184-
max-parallel: 4
185-
matrix:
186-
php-version:
187-
- '8.3' # Current php dev version
188-
189-
steps:
190-
- name: Check out code
191-
uses: actions/checkout@v3
192-
193-
- name: Setup PHP ${{ matrix.php-version }}
194-
uses: shivammathur/setup-php@v2
195-
with:
196-
php-version: '${{ matrix.php-version }}'
197-
tools: composer
198-
coverage: none
199-
env:
200-
# Always use latest available patch for the version
201-
update: true
202-
203-
- name: Setup cache
204-
id: cache
205-
uses: actions/cache@v3
206-
with:
207-
path: |
208-
~/.composer
209-
./vendor
210-
# Clear the cache if composer json (as composer.lock is in the repo) has been updated
211-
key: tests-${{ matrix.php-version }}-${{ hashFiles('composer.json') }}
212-
213-
- name: Build
214-
run: |
215-
make build
216-
217-
- name: Test
218-
run: make test-unit && make test-functional
100+
pattern: coverage-php*
101+
path: coverage-data
102+
- run: ls -ail coverage-data
103+
104+
# codecov-coverage-report:
105+
# name: Codecov coverage report
106+
# runs-on: ubuntu-latest
107+
# environment: ci-codecov
108+
# needs: [tests]
109+
# strategy:
110+
# fail-fast: true
111+
# max-parallel: 4
112+
# matrix:
113+
# include: ${{ needs.tests.outputs.*.matrix }}
114+
# steps:
115+
# - name: Download PHP ${{ matrix.php-version }} coverage artifact
116+
# uses: actions/download-artifact@v4
117+
# with:
118+
# name: ${{ matrix.artifact }}
119+
# path: coverage-data
120+
#
121+
# - name: DEBUG
122+
# run: ls -ail coverage-data
123+
#
124+
# # See the reports at https://codecov.io/gh/yoanm/php-jsonrpc-server-sdk
125+
# - name: Upload unit tests coverage to codecov
126+
# uses: codecov/codecov-action@v3
127+
# with:
128+
# files: "coverage-data/coverage-phpunit/unit.clover"
129+
# name: "unit-tests-${{ matrix.php-version }}"
130+
# flags: "unit-tests,php-${{ matrix.php-version }}"
131+
# fail_ci_if_error: true
132+
# token: ${{ secrets.ENV_CODECOV_TOKEN }}
133+
# verbose: ${{ runner.debug == '1' }}
134+
#
135+
# - name: Upload functional tests coverage to codecov
136+
# if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
137+
# uses: codecov/codecov-action@v4
138+
# with:
139+
# files: "coverage-data/coverage-behat/clover.xml,coverage-data/coverage-phpunit/functional.clover"
140+
# name: "functional-tests-${{ matrix.php-version }}"
141+
# flags: "functional-tests,php-${{ matrix.php-version }}"
142+
# token: ${{ secrets.ENV_CODECOV_TOKEN }}
143+
# verbose: ${{ runner.debug == '1' }}
144+
145+
146+
# codacy-coverage-report:
147+
# name: Codacy coverage report
148+
# runs-on: ubuntu-latest
149+
# environment: ci-codacy
150+
# needs: [ tests ]
151+
# steps:
152+
# - name: Download all PHP coverage artifacts
153+
# uses: actions/download-artifact@v4
154+
# with:
155+
# pattern: coverage-php*
156+
# path: coverage-data
157+
#
158+
# - name: DEBUG
159+
# run: ls -ail coverage-data
160+
#
161+
# - name: Find available files
162+
# run: |
163+
# ls -ail coverage-data/*/coverage-phpunit/unit.clover coverage-data/*/coverage-behat/clover.xml coverage-data/*/coverage-phpunit/functional.clover
164+
#
165+
# - name: Run codacy-coverage-reporter
166+
# uses: codacy/codacy-coverage-reporter-action@v1
167+
# with:
168+
# project-token: ${{ secrets.ENV_CODACY_PROJECT_TOKEN }}
169+
# coverage-reports: coverage-data/*/coverage-phpunit/unit.clover,coverage-data/*/coverage-behat/clover.xml,coverage-data/*/coverage-phpunit/functional.clover

0 commit comments

Comments
 (0)