Skip to content

Commit e9cb0e5

Browse files
committed
GH Actions: change PHAR building to reusable workflow
1 parent 0a364dc commit e9cb0e5

File tree

3 files changed

+83
-70
lines changed

3 files changed

+83
-70
lines changed

.github/workflows/build-phar.yml

Lines changed: 5 additions & 23 deletions
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,8 +39,6 @@ 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.
@@ -48,24 +48,6 @@ jobs:
4848

4949
continue-on-error: ${{ matrix.php == '8.5' }}
5050

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
51+
uses: ./.github/workflows/reusable-build-phar.yml
52+
with:
53+
phpVersion: ${{ matrix.php }}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
createAttestations:
17+
description: "Whether or not to create attestations for the artifacts. Defaults to false."
18+
type: boolean
19+
required: false
20+
default: false
21+
22+
jobs:
23+
build:
24+
runs-on: ubuntu-latest
25+
name: "Build Phar on PHP: ${{ inputs.phpVersion }}"
26+
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
31+
- name: Setup PHP
32+
uses: shivammathur/setup-php@v2
33+
with:
34+
php-version: ${{ inputs.phpVersion }}
35+
coverage: none
36+
ini-values: phar.readonly=Off, error_reporting=-1, display_errors=On
37+
38+
- name: Build the phar files
39+
run: php scripts/build-phar.php
40+
41+
# Provide provenance for generated binaries.
42+
- name: Generate artifact attestations
43+
if: ${{ inputs.createAttestations == true }}
44+
uses: actions/attest-build-provenance@v1
45+
with:
46+
subject-path: |
47+
${{ github.workspace }}/phpcs.phar
48+
${{ github.workspace }}/phpcbf.phar
49+
50+
- name: Upload the PHPCS phar
51+
if: ${{ inputs.uploadArtifacts == true }}
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: phpcs-phar
55+
path: ./phpcs.phar
56+
if-no-files-found: error
57+
retention-days: 28
58+
59+
- name: Upload the PHPCBF phar
60+
if: ${{ inputs.uploadArtifacts == true }}
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: phpcbf-phar
64+
path: ./phpcbf.phar
65+
if-no-files-found: error
66+
retention-days: 28
67+
68+
# Both the below only check a file which is rarely changed and therefore unlikely to have issues.
69+
# This test is about testing that the phars are functional, *not* about whether the code style complies.
70+
- name: 'PHPCS: check code style using the Phar file to test the Phar is functional'
71+
run: php phpcs.phar ./scripts
72+
73+
- name: 'PHPCBF: fix code style using the Phar file to test the Phar is functional'
74+
run: php phpcbf.phar ./scripts

.github/workflows/test.yml

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -22,62 +22,19 @@ 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
4835
# Only attests the build artifacts which will be used in the published releases as per the guidelines in "what to attest".
4936
# 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
37+
createAttestations: ${{ github.ref_type == 'tag' }}
8138

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

0 commit comments

Comments
 (0)