Skip to content

Commit

Permalink
GH Actions: change PHAR building to reusable workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfnl committed Nov 30, 2024
1 parent 0a364dc commit bf512be
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 70 deletions.
26 changes: 3 additions & 23 deletions .github/workflows/build-phar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ concurrency:

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
# Deliberately missing PHP 8.0 as that PHAR is build and used in the test workflow.
Expand All @@ -48,24 +46,6 @@ jobs:

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

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
ini-values: phar.readonly=Off, error_reporting=-1, display_errors=On

- name: Build the phars
run: php scripts/build-phar.php

# Both the below only check a file which is rarely changed and therefore unlikely to have issues.
# This test is about testing that the phars are functional, *not* about whether the code style complies.
- name: 'PHPCS: check code style using the Phar file to test the Phar is functional'
run: php phpcs.phar ./scripts

- name: 'PHPCBF: fix code style using the Phar file to test the Phar is functional'
run: php phpcbf.phar ./scripts
uses: ./.github/workflows/reusable-build-phar.yml
with:
phpVersion: ${{ matrix.php }}
74 changes: 74 additions & 0 deletions .github/workflows/reusable-build-phar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Build PHAR files

on:
workflow_call:
inputs:
phpVersion:
description: "The PHP version to use. Defaults to PHP 8.0 as used for the releases."
type: string
required: false
default: '8.0'
uploadArtifacts:
description: "Whether or not to upload the artifacts. Defaults to false."
type: boolean
required: false
default: false
createAttestations:
description: "Whether or not to create attestations for the artifacts. Defaults to false."
type: boolean
required: false
default: false

jobs:
build:
runs-on: ubuntu-latest
name: "Build Phar on PHP: ${{ inputs.phpVersion }}"

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.phpVersion }}
coverage: none
ini-values: phar.readonly=Off, error_reporting=-1, display_errors=On

- name: Build the phar files
run: php scripts/build-phar.php

# Provide provenance for generated binaries.
- name: Generate artifact attestations
if: ${{ inputs.createAttestations == true }}
uses: actions/attest-build-provenance@v1
with:
subject-path: |
${{ github.workspace }}/phpcs.phar
${{ github.workspace }}/phpcbf.phar
- name: Upload the PHPCS phar
if: ${{ inputs.uploadArtifacts == true }}
uses: actions/upload-artifact@v4
with:
name: phpcs-phar
path: ./phpcs.phar
if-no-files-found: error
retention-days: 28

- name: Upload the PHPCBF phar
if: ${{ inputs.uploadArtifacts == true }}
uses: actions/upload-artifact@v4
with:
name: phpcbf-phar
path: ./phpcbf.phar
if-no-files-found: error
retention-days: 28

# Both the below only check a file which is rarely changed and therefore unlikely to have issues.
# This test is about testing that the phars are functional, *not* about whether the code style complies.
- name: 'PHPCS: check code style using the Phar file to test the Phar is functional'
run: php phpcs.phar ./scripts

- name: 'PHPCBF: fix code style using the Phar file to test the Phar is functional'
run: php phpcbf.phar ./scripts
51 changes: 4 additions & 47 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,62 +22,19 @@ jobs:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true

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

permissions:
id-token: write
contents: read
attestations: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
coverage: none
ini-values: phar.readonly=Off, error_reporting=-1, display_errors=On

- name: Build the phar
run: php scripts/build-phar.php

# Provide provenance for generated binaries.
uses: ./.github/workflows/reusable-build-phar.yml
with:
uploadArtifacts: true
# Only attests the build artifacts which will be used in the published releases as per the guidelines in "what to attest".
# https://docs.github.com/en/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds
- name: Generate artifact attestations
if: ${{ github.ref_type == 'tag' }}
uses: actions/attest-build-provenance@v1
with:
subject-path: |
${{ github.workspace }}/phpcs.phar
${{ github.workspace }}/phpcbf.phar
- name: Upload the PHPCS phar
uses: actions/upload-artifact@v4
with:
name: phpcs-phar
path: ./phpcs.phar
if-no-files-found: error
retention-days: 28

- name: Upload the PHPCBF phar
uses: actions/upload-artifact@v4
with:
name: phpcbf-phar
path: ./phpcbf.phar
if-no-files-found: error
retention-days: 28

# Both the below only check a file which is rarely changed and therefore unlikely to have issues.
# This test is about testing that the phars are functional, *not* about whether the code style complies.
- name: 'PHPCS: check code style using the Phar file to test the Phar is functional'
run: php phpcs.phar ./scripts

- name: 'PHPCBF: fix code style using the Phar file to test the Phar is functional'
run: php phpcbf.phar ./scripts
createAttestations: ${{ github.ref_type == 'tag' }}

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

0 comments on commit bf512be

Please sign in to comment.