Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH Actions: change PHAR building to reusable workflow #751

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 6 additions & 26 deletions .github/workflows/build-phar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- master
paths:
- '.github/workflows/build-phar.yml'
- '.github/workflows/reusable-build-phar.yml'
- 'scripts/build-phar.php'
- 'autoload.php'
- 'src/Config.php'
Expand All @@ -18,6 +19,7 @@ on:
pull_request:
paths:
- '.github/workflows/build-phar.yml'
- '.github/workflows/reusable-build-phar.yml'
- 'scripts/build-phar.php'
- 'autoload.php'
- 'src/Config.php'
Expand All @@ -37,35 +39,13 @@ 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.
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']
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']

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

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 }}
81 changes: 81 additions & 0 deletions .github/workflows/reusable-build-phar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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
retentionDays:
description: "How long uploaded artifacts should remain available (in days). Defaults to 1 day."
type: string
required: false
default: 1
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 }}"

continue-on-error: ${{ inputs.phpVersion == 'nightly' }}

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: ${{ inputs.retentionDays }}

- 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: ${{ inputs.retentionDays }}

# 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
52 changes: 5 additions & 47 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,62 +22,20 @@ 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
retentionDays: 28
# 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
Loading