Skip to content

Commit 01e447b

Browse files
authored
Refactor CI for forked repositories - Improve (yoanm#129)
1 parent d2e80a3 commit 01e447b

File tree

5 files changed

+354
-263
lines changed

5 files changed

+354
-263
lines changed

.github/workflows/CI.yml

Lines changed: 13 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
name: 'CI'
2+
23
on: # Build any PRs and main branch changes
34
workflow_dispatch: # Allows to run the workflow manually from the Actions tab
45
pull_request:
56
types:
67
- opened
78
- synchronize
9+
paths-ignore:
10+
# In case of updates to those workflows, they must be pre-checked by `pre-check-CI-updates.yml` rather than this workflow !
11+
# Any updates on those workflows are expected to be restricted to those workflows only ! (no update on code for instance)
12+
- '.github/workflows/pre-check-CI-updates.yml'
13+
- '.github/workflows/CI.yml'
14+
- '.github/workflows/coverage-upload.yml'
15+
- '.github/workflows/reusable-CI-workflow.yml'
16+
- '.github/workflows/reusable-coverage-upload-workflow.yml'
817
push:
918
branches: [ master ]
1019
schedule:
@@ -20,171 +29,7 @@ env:
2029

2130
jobs:
2231
tests:
23-
name: UTs & FTs - PHP ${{ matrix.php-version }}
24-
runs-on: ubuntu-latest
25-
env:
26-
COVERAGE_TYPE: xdebug
27-
COVERAGE_OUTPUT_STYLE: clover
28-
strategy:
29-
fail-fast: true
30-
max-parallel: 4
31-
matrix:
32-
include:
33-
# Bare minimum => Lowest versions allowed by composer config
34-
- php-version: '8.0'
35-
composer-flag: --prefer-lowest
36-
# Up-to-date versions => Latest versions allowed by composer config
37-
- php-version: '8.2'
38-
steps:
39-
- name: Check out code
40-
uses: actions/checkout@v4
41-
42-
# @TODO Figure out if coverage for every version is actually useful or not
43-
# - name: Enable coverage
44-
# if: ${{ matrix.php-version == '8.2' }}
45-
# run: |
46-
# echo "COVERAGE_OUTPUT_STYLE=clover" >> $GITHUB_ENV
47-
# echo "COVERAGE_TYPE=xdebug" >> $GITHUB_ENV
48-
49-
- name: Setup PHP ${{ matrix.php-version }}
50-
uses: shivammathur/setup-php@v2
51-
env:
52-
update: true # Always use latest available patch for the version
53-
fail-fast: true # step will fail if an extension or tool fails to set up
54-
with:
55-
php-version: '${{ matrix.php-version }}'
56-
tools: composer
57-
coverage: ${{ env.COVERAGE_TYPE }}
58-
59-
- name: Setup cache
60-
id: cache
61-
uses: actions/cache@v4
62-
with:
63-
path: |
64-
~/.composer
65-
./vendor
66-
# Clear the cache if composer json (as composer.lock is in the repo) has been updated
67-
key: tests-${{ matrix.php-version }}-${{ matrix.composer-flag }}-${{ hashFiles('composer.json') }}
68-
69-
- name: Build
70-
run: |
71-
make build
72-
73-
- name: Tests
74-
run: make test-unit && make test-functional
75-
76-
- name: Create "unit tests" reports directory
77-
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
78-
id: unit-tests-coverage-group
79-
uses: yoanm/temp-reports-group-workspace/.github/actions/create-action@develop
80-
with:
81-
name: unit-tests
82-
format: clover
83-
files: build/coverage-phpunit/unit.clover
84-
flags: |
85-
unit-tests
86-
php-${{ matrix.php-version }}
87-
path: build/coverage-groups
88-
89-
- name: Create "functional tests" coverage group
90-
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
91-
id: functional-tests-coverage-group
92-
uses: yoanm/temp-reports-group-workspace/.github/actions/create-action@develop
93-
with:
94-
name: functional-tests
95-
format: clover
96-
files: |
97-
build/coverage-phpunit/functional.clover
98-
build/coverage-behat/clover.xml
99-
flags: |
100-
functional-tests
101-
php-${{ matrix.php-version }}
102-
path: build/coverage-groups
103-
104-
- name: Upload coverage reports
105-
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
106-
uses: actions/upload-artifact@v4
107-
with:
108-
name: coverage-groups-php${{ matrix.php-version }}
109-
path: build/coverage-groups
110-
if-no-files-found: error
111-
112-
static-checks:
113-
name: Static checks
114-
runs-on: ubuntu-latest
115-
steps:
116-
- uses: actions/checkout@v4
117-
118-
- name: Setup PHP 8.2
119-
uses: shivammathur/setup-php@v2
120-
with:
121-
php-version: 8.2 # Latest supported
122-
tools: composer
123-
coverage: none
124-
env:
125-
# Always use latest available patch for the version
126-
update: true
127-
128-
- name: Setup cache
129-
id: cache
130-
uses: actions/cache@v4
131-
with:
132-
path: |
133-
~/.composer
134-
# Clear the cache if composer json (as composer.lock is in the repo) has been updated
135-
key: tests-${{ env.PHP_VERSION }}-${{ hashFiles('composer.json') }}
136-
137-
- name: Build
138-
run: make build
139-
140-
- name: ComposerRequireChecker
141-
uses: docker://webfactory/composer-require-checker:4.5.0
142-
143-
- name: Dependencies check
144-
if: ${{ github.event_name == 'pull_request' }}
145-
uses: actions/dependency-review-action@v4
146-
147-
nightly-tests:
148-
name: Nightly - PHP ${{ matrix.php-version }}
149-
runs-on: ubuntu-latest
150-
env:
151-
COMPOSER_OPTIONS: '--optimize-autoloader --ignore-platform-req=php+'
152-
continue-on-error: true
153-
needs: [ static-checks, tests ]
154-
strategy:
155-
fail-fast: false
156-
max-parallel: 4
157-
matrix:
158-
php-version:
159-
- '8.3' # Current php dev version
160-
161-
steps:
162-
- name: Check out code
163-
uses: actions/checkout@v4
164-
165-
- name: Setup PHP ${{ matrix.php-version }}
166-
uses: shivammathur/setup-php@v2
167-
with:
168-
php-version: '${{ matrix.php-version }}'
169-
tools: composer
170-
coverage: none
171-
env:
172-
# Always use latest available patch for the version
173-
update: true
174-
175-
- name: Setup cache
176-
id: cache
177-
uses: actions/cache@v4
178-
with:
179-
path: |
180-
~/.composer
181-
./vendor
182-
# Clear the cache if composer json (as composer.lock is in the repo) has been updated
183-
key: tests-${{ matrix.php-version }}-${{ hashFiles('composer.json') }}
184-
185-
- name: Build
186-
run: |
187-
make build
188-
189-
- name: Test
190-
run: make test-unit && make test-functional
32+
name: Tests
33+
permissions:
34+
contents: read
35+
uses: ./.github/workflows/reusable-CI-workflow.yml
Lines changed: 6 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,16 @@
1-
name: 'Coverage upload'
1+
name: 'Coverage'
22
on:
33
workflow_run:
44
workflows: ["CI"]
55
types: [completed]
66

77
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
8+
upload:
9+
name: Upload
3210
permissions:
3311
contents: read
3412
checks: write # For the check run creation !
3513
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 }}
58-
59-
debug-context:
60-
name: DEBUG - context
61-
runs-on: ubuntu-latest
62-
steps:
63-
- run: |
64-
echo '{'
65-
echo '"github.action": ${{ toJson(github.action) }},'
66-
echo '"github.action_path": ${{ toJson(github.action_path) }},'
67-
echo '"github.action_ref": ${{ toJson(github.action_ref) }},'
68-
echo '"github.action_repository": ${{ toJson(github.action_repository) }},'
69-
echo '"github.action_status": ${{ toJson(github.action_status) }},'
70-
echo '"github.actor": ${{ toJson(github.actor) }},'
71-
echo '"github.actor_id": ${{ toJson(github.actor_id) }},'
72-
echo '"github.base_ref": ${{ toJson(github.base_ref) }},'
73-
echo '"github.event": ${{ toJson(github.event) }},'
74-
echo '"github.event_name": ${{ toJson(github.event_name) }},'
75-
echo '"github.event_path": ${{ toJson(github.event_path) }},'
76-
echo '"github.head_ref": ${{ toJson(github.head_ref) }},'
77-
echo '"github.job": ${{ toJson(github.job) }},'
78-
echo '"github.path": ${{ toJson(github.path) }},'
79-
echo '"github.ref": ${{ toJson(github.ref) }},'
80-
echo '"github.ref_name": ${{ toJson(github.ref_name) }},'
81-
echo '"github.ref_protected": ${{ toJson(github.ref_protected) }},'
82-
echo '"github.ref_type": ${{ toJson(github.ref_type) }},'
83-
echo '"github.repository": ${{ toJson(github.repository) }},'
84-
echo '"github.repository_id": ${{ toJson(github.repository_id) }},'
85-
echo '"github.repository_owner": ${{ toJson(github.repository_owner) }},'
86-
echo '"github.repository_owner_id": ${{ toJson(github.repository_owner_id) }},'
87-
echo '"github.repositoryUrl": ${{ toJson(github.repositoryUrl) }},'
88-
echo '"github.run_id": ${{ toJson(github.run_id) }},'
89-
echo '"github.run_number": ${{ toJson(github.run_number) }},'
90-
echo '"github.run_attempt": ${{ toJson(github.run_attempt) }},'
91-
echo '"github.sha": ${{ toJson(github.sha) }},'
92-
echo '"github.triggering_actor": ${{ toJson(github.triggering_actor) }},'
93-
echo '"github.workflow": ${{ toJson(github.workflow) }},'
94-
echo '"github.workflow_ref": ${{ toJson(github.workflow_ref) }},'
95-
echo '"github.workflow_sha": ${{ toJson(github.workflow_sha) }},'
96-
echo '"github.workspace": ${{ toJson(github.workspace) }}'
97-
echo '}'
98-
99-
debug-uploads:
100-
name: DEBUG - Uploaders
101-
runs-on: ubuntu-latest
102-
needs: [ codacy-uploader, codecov-uploader ]
103-
steps:
104-
- run: echo 'codecov='"'"'${{ toJson(needs.codecov-uploader) }}'"'"
105-
- run: echo 'codacy='"'"'${{ toJson(needs.codacy-uploader) }}'"'"
14+
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
15+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
16+
uses: ./.github/workflows/reusable-coverage-upload-workflow.yml
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: 'Test CI updates'
2+
# [DESCRIPTION]
3+
# As CI workflow relies on `workflow_run` trigger for upload, this workflow is used in order to ease updates made on
4+
# CI workflow (or linked workflows/actions). It's kind of pre-check to ensure once updates are merged on main branch,
5+
# the `workflow_run` workflow execution will behave as expected.
6+
7+
on:
8+
pull_request:
9+
types:
10+
- opened
11+
- synchronize
12+
branches: [master] # Only for PR targeting master branch
13+
paths: # /!\ Duplicate the same list as `on.pull_request.paths-ignore` property value for CI workflow !
14+
- '.github/workflows/pre-check-CI-updates.yml' # This workflow
15+
- '.github/workflows/CI.yml'
16+
- '.github/workflows/coverage-upload.yml'
17+
- '.github/workflows/reusable-CI-workflow.yml'
18+
- '.github/workflows/reusable-coverage-upload-workflow.yml'
19+
20+
concurrency:
21+
group: "${{ github.workflow }}-${{ github.head_ref || github.ref }}"
22+
cancel-in-progress: true
23+
24+
jobs:
25+
tests:
26+
name: Tests
27+
permissions:
28+
contents: read
29+
uses: ./.github/workflows/reusable-CI-workflow.yml
30+
31+
upload:
32+
name: Upload
33+
needs: [tests]
34+
permissions:
35+
contents: read
36+
checks: write # For the check run creation !
37+
secrets:
38+
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
39+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
40+
uses: ./.github/workflows/reusable-coverage-upload-workflow.yml

0 commit comments

Comments
 (0)