Skip to content

Commit 799e293

Browse files
authored
Merge pull request #751 from PHPCSStandards/feature/ghactions-make-phar-building-reusable
GH Actions: change PHAR building to reusable workflow
2 parents 5033272 + 21dc873 commit 799e293

File tree

3 files changed

+92
-73
lines changed

3 files changed

+92
-73
lines changed

.github/workflows/build-phar.yml

+6-26
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
- master
99
paths:
1010
- '.github/workflows/build-phar.yml'
11+
- '.github/workflows/reusable-build-phar.yml'
1112
- 'scripts/build-phar.php'
1213
- 'autoload.php'
1314
- 'src/Config.php'
@@ -18,6 +19,7 @@ on:
1819
pull_request:
1920
paths:
2021
- '.github/workflows/build-phar.yml'
22+
- '.github/workflows/reusable-build-phar.yml'
2123
- 'scripts/build-phar.php'
2224
- 'autoload.php'
2325
- 'src/Config.php'
@@ -37,35 +39,13 @@ concurrency:
3739

3840
jobs:
3941
build:
40-
runs-on: ubuntu-latest
41-
4242
strategy:
4343
matrix:
4444
# Deliberately missing PHP 8.0 as that PHAR is build and used in the test workflow.
45-
php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.1', '8.2', '8.3', '8.4', '8.5']
45+
php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.1', '8.2', '8.3', '8.4', 'nightly']
4646

4747
name: "Build Phar on PHP: ${{ matrix.php }}"
4848

49-
continue-on-error: ${{ matrix.php == '8.5' }}
50-
51-
steps:
52-
- name: Checkout code
53-
uses: actions/checkout@v4
54-
55-
- name: Setup PHP
56-
uses: shivammathur/setup-php@v2
57-
with:
58-
php-version: ${{ matrix.php }}
59-
coverage: none
60-
ini-values: phar.readonly=Off, error_reporting=-1, display_errors=On
61-
62-
- name: Build the phars
63-
run: php scripts/build-phar.php
64-
65-
# Both the below only check a file which is rarely changed and therefore unlikely to have issues.
66-
# This test is about testing that the phars are functional, *not* about whether the code style complies.
67-
- name: 'PHPCS: check code style using the Phar file to test the Phar is functional'
68-
run: php phpcs.phar ./scripts
69-
70-
- name: 'PHPCBF: fix code style using the Phar file to test the Phar is functional'
71-
run: php phpcbf.phar ./scripts
49+
uses: ./.github/workflows/reusable-build-phar.yml
50+
with:
51+
phpVersion: ${{ matrix.php }}
+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Build PHAR files
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
phpVersion:
7+
description: "The PHP version to use. Defaults to PHP 8.0 as used for the releases."
8+
type: string
9+
required: false
10+
default: '8.0'
11+
uploadArtifacts:
12+
description: "Whether or not to upload the artifacts. Defaults to false."
13+
type: boolean
14+
required: false
15+
default: false
16+
retentionDays:
17+
description: "How long uploaded artifacts should remain available (in days). Defaults to 1 day."
18+
type: string
19+
required: false
20+
default: 1
21+
createAttestations:
22+
description: "Whether or not to create attestations for the artifacts. Defaults to false."
23+
type: boolean
24+
required: false
25+
default: false
26+
27+
jobs:
28+
build:
29+
runs-on: ubuntu-latest
30+
name: "Build Phar on PHP: ${{ inputs.phpVersion }}"
31+
32+
continue-on-error: ${{ inputs.phpVersion == 'nightly' }}
33+
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v4
37+
38+
- name: Setup PHP
39+
uses: shivammathur/setup-php@v2
40+
with:
41+
php-version: ${{ inputs.phpVersion }}
42+
coverage: none
43+
ini-values: phar.readonly=Off, error_reporting=-1, display_errors=On
44+
45+
- name: Build the phar files
46+
run: php scripts/build-phar.php
47+
48+
# Provide provenance for generated binaries.
49+
- name: Generate artifact attestations
50+
if: ${{ inputs.createAttestations == true }}
51+
uses: actions/attest-build-provenance@v2
52+
with:
53+
subject-path: |
54+
${{ github.workspace }}/phpcs.phar
55+
${{ github.workspace }}/phpcbf.phar
56+
57+
- name: Upload the PHPCS phar
58+
if: ${{ inputs.uploadArtifacts == true }}
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: phpcs-phar
62+
path: ./phpcs.phar
63+
if-no-files-found: error
64+
retention-days: ${{ inputs.retentionDays }}
65+
66+
- name: Upload the PHPCBF phar
67+
if: ${{ inputs.uploadArtifacts == true }}
68+
uses: actions/upload-artifact@v4
69+
with:
70+
name: phpcbf-phar
71+
path: ./phpcbf.phar
72+
if-no-files-found: error
73+
retention-days: ${{ inputs.retentionDays }}
74+
75+
# Both the below only check a file which is rarely changed and therefore unlikely to have issues.
76+
# This test is about testing that the phars are functional, *not* about whether the code style complies.
77+
- name: 'PHPCS: check code style using the Phar file to test the Phar is functional'
78+
run: php phpcs.phar ./scripts
79+
80+
- name: 'PHPCBF: fix code style using the Phar file to test the Phar is functional'
81+
run: php phpcbf.phar ./scripts

.github/workflows/test.yml

+5-47
Original file line numberDiff line numberDiff line change
@@ -22,62 +22,20 @@ jobs:
2222
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
2323
cancel-in-progress: true
2424

25-
runs-on: ubuntu-latest
2625
name: "Build Phar on PHP: 8.0"
2726

2827
permissions:
2928
id-token: write
3029
contents: read
3130
attestations: write
3231

33-
steps:
34-
- name: Checkout code
35-
uses: actions/checkout@v4
36-
37-
- name: Setup PHP
38-
uses: shivammathur/setup-php@v2
39-
with:
40-
php-version: '8.0'
41-
coverage: none
42-
ini-values: phar.readonly=Off, error_reporting=-1, display_errors=On
43-
44-
- name: Build the phar
45-
run: php scripts/build-phar.php
46-
47-
# Provide provenance for generated binaries.
32+
uses: ./.github/workflows/reusable-build-phar.yml
33+
with:
34+
uploadArtifacts: true
35+
retentionDays: 28
4836
# Only attests the build artifacts which will be used in the published releases as per the guidelines in "what to attest".
4937
# https://docs.github.com/en/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds
50-
- name: Generate artifact attestations
51-
if: ${{ github.ref_type == 'tag' }}
52-
uses: actions/attest-build-provenance@v1
53-
with:
54-
subject-path: |
55-
${{ github.workspace }}/phpcs.phar
56-
${{ github.workspace }}/phpcbf.phar
57-
58-
- name: Upload the PHPCS phar
59-
uses: actions/upload-artifact@v4
60-
with:
61-
name: phpcs-phar
62-
path: ./phpcs.phar
63-
if-no-files-found: error
64-
retention-days: 28
65-
66-
- name: Upload the PHPCBF phar
67-
uses: actions/upload-artifact@v4
68-
with:
69-
name: phpcbf-phar
70-
path: ./phpcbf.phar
71-
if-no-files-found: error
72-
retention-days: 28
73-
74-
# Both the below only check a file which is rarely changed and therefore unlikely to have issues.
75-
# This test is about testing that the phars are functional, *not* about whether the code style complies.
76-
- name: 'PHPCS: check code style using the Phar file to test the Phar is functional'
77-
run: php phpcs.phar ./scripts
78-
79-
- name: 'PHPCBF: fix code style using the Phar file to test the Phar is functional'
80-
run: php phpcbf.phar ./scripts
38+
createAttestations: ${{ github.ref_type == 'tag' }}
8139

8240
test:
8341
# Cancels all previous runs of this particular job for the same branch that have not yet completed.

0 commit comments

Comments
 (0)