Skip to content

Commit 8d4b138

Browse files
authored
Refactor CI for fork PR (#33)
1 parent 0d4ed9f commit 8d4b138

File tree

2 files changed

+93
-64
lines changed

2 files changed

+93
-64
lines changed

.github/workflows/CI.yml

Lines changed: 36 additions & 64 deletions
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:
@@ -65,13 +62,13 @@ jobs:
6562
6663
- name: Setup PHP ${{ matrix.php-version }}
6764
uses: shivammathur/setup-php@v2
65+
env:
66+
update: true # Always use latest available patch for the version
67+
fail-fast: true # step will fail if an extension or tool fails to set up
6868
with:
6969
php-version: '${{ matrix.php-version }}'
7070
tools: composer
7171
coverage: ${{ env.COVERAGE_TYPE }}
72-
env:
73-
# Always use latest available patch for the version
74-
update: true
7572

7673
- name: Setup cache
7774
id: cache
@@ -80,18 +77,9 @@ jobs:
8077
path: |
8178
~/.composer
8279
./vendor
83-
${{ env.CODACY_CACHE_PATH }}
8480
# Clear the cache if composer json (as composer.lock is in the repo) has been updated
8581
key: tests-${{ matrix.php-version }}-${{ matrix.symfony-version }}-${{ matrix.composer-flag }}-${{ hashFiles('composer.json') }}
8682

87-
- name: Download codacy binary
88-
if: steps.cache.outputs.cache-hit != 'true'
89-
run: |
90-
mkdir -p ${{ env.CODACY_CACHE_PATH }} \
91-
&& curl -LN https://coverage.codacy.com/get.sh -o ${{ env.CODACY_BIN }} \
92-
&& chmod +x ${{ env.CODACY_BIN }} \
93-
&& ${{ env.CODACY_BIN }} download
94-
9583
- name: Build
9684
run: |
9785
SF_VERSION=${{ matrix.symfony-version }}
@@ -107,34 +95,43 @@ jobs:
10795
- name: Tests
10896
run: make test-unit && make test-functional
10997

110-
# Upload to codacy first as codecov action always remove coverage files despite move_coverage_to_trash at false
111-
# And only if it's not a PR from a fork => Can't work as codacy secret is not accessible in that context
112-
- name: Upload coverages to Codacy
113-
if: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk') && env.COVERAGE_TYPE == 'xdebug' }}
114-
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
115-
116-
# See the reports at https://codecov.io/gh/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk
117-
- name: Upload unit tests coverage to codecov
98+
- name: Create "unit tests" reports group
11899
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
119-
uses: codecov/codecov-action@v3
100+
id: unit-tests-coverage-group
101+
uses: yoanm/temp-reports-group-workspace/.github/actions/create-action@develop
120102
with:
121-
file: "build/coverage-phpunit/unit.clover"
122-
name: "unit-tests-${{ matrix.php-version }}-${{ matrix.symfony-version }}"
123-
flags: "unit-tests,php-${{ matrix.php-version }},sf-${{ matrix.symfony-version }}"
124-
fail_ci_if_error: true
125-
move_coverage_to_trash: false
126-
verbose: ${{ runner.debug == '1' }}
127-
128-
- name: Upload functional tests coverage to codecov
103+
name: unit-tests
104+
format: clover
105+
files: build/coverage-phpunit/unit.clover
106+
flags: |
107+
unit-tests
108+
php-${{ matrix.php-version }}
109+
sf-${{ matrix.symfony-version }}
110+
path: build/coverage-groups
111+
112+
- name: Create "functional tests" coverage group
129113
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
130-
uses: codecov/codecov-action@v3
114+
id: functional-tests-coverage-group
115+
uses: yoanm/temp-reports-group-workspace/.github/actions/create-action@develop
131116
with:
132-
files: "build/coverage-behat/clover.xml,build/coverage-phpunit/functional.clover"
133-
name: "functional-tests-${{ matrix.php-version }}-${{ matrix.symfony-version }}"
134-
flags: "functional-tests,php-${{ matrix.php-version }},sf-${{ matrix.symfony-version }}"
135-
fail_ci_if_error: true
136-
move_coverage_to_trash: false
137-
verbose: ${{ runner.debug == '1' }}
117+
name: functional-tests
118+
format: clover
119+
files: |
120+
build/coverage-phpunit/functional.clover
121+
build/coverage-behat/clover.xml
122+
flags: |
123+
functional-tests
124+
php-${{ matrix.php-version }}
125+
sf-${{ matrix.symfony-version }}
126+
path: build/coverage-groups
127+
128+
- name: Upload coverage reports
129+
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
130+
uses: actions/upload-artifact@v4
131+
with:
132+
name: coverage-groups-php${{ matrix.php-version }}-sf${{ matrix.symfony-version }}
133+
path: build/coverage-groups
134+
if-no-files-found: error
138135

139136
static-checks:
140137
name: Static checks
@@ -171,31 +168,6 @@ jobs:
171168
if: ${{ github.event_name == 'pull_request' }}
172169
uses: actions/dependency-review-action@v1
173170

174-
finalize-codacy-coverage-report:
175-
runs-on: ubuntu-latest
176-
name: Finalize Codacy coverage report
177-
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk' }}
178-
needs: [ tests ]
179-
steps:
180-
- name: Setup cache
181-
id: cache
182-
uses: actions/cache@v3
183-
with:
184-
path: |
185-
${{ env.CODACY_CACHE_PATH }}
186-
key: codacy-final
187-
188-
- name: Download codacy binary
189-
if: steps.cache.outputs.cache-hit != 'true'
190-
run: |
191-
mkdir -p ${{ env.CODACY_CACHE_PATH }} \
192-
&& curl -LN https://coverage.codacy.com/get.sh -o ${{ env.CODACY_BIN }} \
193-
&& chmod +x ${{ env.CODACY_BIN }} \
194-
&& ${{ env.CODACY_BIN }} download
195-
196-
- name: Finalize reporting
197-
run: ${{ env.CODACY_BIN }} final -t ${{ secrets.CODACY_PROJECT_TOKEN }}
198-
199171
nightly-tests:
200172
name: Nightly - Symfony ${{ matrix.symfony-version }}
201173
runs-on: ubuntu-latest

.github/workflows/coverage-upload.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: 'Coverage upload'
2+
on:
3+
workflow_run:
4+
workflows: ["CI"]
5+
types: [completed]
6+
7+
jobs:
8+
fetch-info:
9+
name: Fetch triggering workflow metadata
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
checks: write # For the check run creation !
14+
steps:
15+
- name: 'Check run ○'
16+
uses: yoanm/temp-reports-group-workspace/.github/actions/attach-check-run-to-triggering-workflow-action@develop
17+
with:
18+
name: 'Fetch coverage info'
19+
fails-on-triggering-workflow-failure: true
20+
21+
- uses: yoanm/temp-reports-group-workspace/.github/actions/fetch-workflow-metadata-action@develop
22+
id: fetch-workflow-metadata
23+
24+
outputs:
25+
commit-sha: ${{ steps.fetch-workflow-metadata.outputs.commit-sha }}
26+
run-id: ${{ steps.fetch-workflow-metadata.outputs.run-id }}
27+
28+
codacy-uploader:
29+
name: Codacy
30+
needs: [fetch-info]
31+
uses: yoanm/temp-reports-group-workspace/.github/workflows/codacy-upload-from-artifacts.yml@develop
32+
permissions:
33+
contents: read
34+
checks: write # For the check run creation !
35+
secrets:
36+
PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
37+
with:
38+
artifacts-pattern: coverage-groups-*
39+
run-id: ${{ needs.fetch-info.outputs.run-id }}
40+
41+
codecov-uploader:
42+
name: Codecov
43+
needs: [fetch-info]
44+
uses: yoanm/temp-reports-group-workspace/.github/workflows/codecov-upload-from-artifacts.yml@develop
45+
permissions:
46+
contents: read
47+
checks: write # For the check run creation !
48+
secrets:
49+
TOKEN: ${{ secrets.CODECOV_TOKEN }}
50+
with:
51+
artifacts-pattern: coverage-groups-*
52+
run-id: ${{ needs.fetch-info.outputs.run-id }}
53+
override-commit: ${{ needs.fetch-info.outputs.commit-sha }}
54+
override-branch: ${{ needs.fetch-info.outputs.branch }}
55+
override-pr: ${{ needs.fetch-info.outputs.pr-number }}
56+
override-build: ${{ needs.fetch-info.outputs.run-id }}
57+
override-build-url: ${{ needs.fetch-info.outputs.run-url }}

0 commit comments

Comments
 (0)