Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 41 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,49 @@ jobs:
source: ${{ matrix.source }}
verify-attestation: ${{ matrix.verify-attestation }}

- run: echo '${{ steps.subject.outputs.matrix }}' > actual.json
- run: |
{
echo "{"
echo '"constraint": "${{ steps.subject.outputs.constraint }}",'
echo '"highest": "${{ steps.subject.outputs.highest }}",'
echo '"lowest": "${{ steps.subject.outputs.lowest }}",'
echo '"versions": ${{ steps.subject.outputs.versions }}'
echo "}"
} >> actual.json

- run: diff <(jq --sort-keys . actual.json) <(jq --sort-keys . local-action/testdata/${{ matrix.case }}.${{ matrix.mode }}.golden.json)

outputs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
path: local-action

- uses: ./local-action
id: subject
with:
composer-json: local-action/testdata/complex.composer.json
mode: minor-only
source: offline
verify-attestation: false

- name: Assert constraint output
run: exit 1
if: steps.subject.outputs.constraint != '^7.3.32 || ^8.1 <=8.1.9'

- name: Assert versions output
run: exit 1
if: steps.subject.outputs.versions != toJSON(fromJSON('["7.3","7.4","8.1"]'))

- name: Assert lowest output
run: exit 1
if: steps.subject.outputs.lowest != '7.3'

- name: Assert highest output
run: exit 1
if: steps.subject.outputs.highest != '8.1'

negative:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -159,6 +198,7 @@ jobs:
wait-for-all-tests:
needs:
- positive
- outputs
- negative
- missing
runs-on: ubuntu-latest
Expand Down
37 changes: 7 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,36 +79,13 @@ See [action.yml](action.yml) and the underlying script [`typisttech/php-matrix`]

### Outputs

This action yields **a single output** `matrix` which is a JSON-encoded string of:

| Key | Description | Example |
| --- | --- | --- |
| `constraint` | PHP constraint found in `composer.json` | `^7.3 \|\| ^8.0` |
| `versions` | Array of all supported PHP versions | In `minor-only` mode, `["7.3", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4"]`<br><br>In `full` mode, `["7.4.998", "7.4.999", "8.4.998", "8.4.999"]` |
| `versions` | String of an array of all supported PHP versions | In `minor-only` mode, `["7.3", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4"]`<br><br>In `full` mode, `["7.4.998", "7.4.999", "8.4.998", "8.4.999"]` |
| `lowest` | Lowest supported PHP versions | In `minor-only` mode, `7.3`<br><br>In `full` mode, `7.3.0` |
| `highest` | Highest supported PHP versions | In `minor-only` mode, `8.4`<br><br>In `full` mode, `8.4.2` |

> [!TIP]
>
> Use [`fromJSON()`](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/evaluate-expressions-in-workflows-and-actions#fromjson) and [`toJSON()`](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/evaluate-expressions-in-workflows-and-actions#tojson) to decode the output.
>
> ```yaml
> jobs:
> php-matrix:
> runs-on: ubuntu-latest
> outputs:
> matrix: ${{ steps.php-matrix.outputs.matrix }}
> constraint: ${{ fromJSON(steps.php-matrix.outputs.matrix).constraint }}
> # Use `fromJSON()` when accessing `versions`!
> versions: ${{ toJSON(fromJSON(steps.php-matrix.outputs.matrix).versions) }}
> lowest: ${{ fromJSON(steps.php-matrix.outputs.matrix).lowest }}
> highest: ${{ fromJSON(steps.php-matrix.outputs.matrix).highest }}
> steps:
> - uses: actions/checkout@v4
> - uses: typisttech/php-matrix-action@main
> id: php-matrix
> ```

## Examples

<details open>
Expand All @@ -124,7 +101,7 @@ jobs:
php-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.php-matrix.outputs.matrix }}
versions: ${{ steps.php-matrix.outputs.versions }}
steps:
- uses: actions/checkout@v4
- uses: typisttech/php-matrix-action@v1
Expand All @@ -135,7 +112,7 @@ jobs:
needs: php-matrix
strategy:
matrix:
php: ${{ fromJSON(needs.php-matrix.outputs.matrix).versions }}
php: ${{ fromJSON(needs.php-matrix.outputs.versions) }}
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -167,7 +144,7 @@ jobs:

- uses: shivammathur/setup-php@v2
with:
php-version: ${{ fromJSON(steps.php-matrix.outputs.matrix).lowest }}
php-version: ${{ steps.php-matrix.outputs.lowest }}

- run: composer install

Expand All @@ -189,8 +166,8 @@ jobs:
php-matrix:
runs-on: ubuntu-latest
outputs:
versions: ${{ toJSON(fromJSON(steps.php-matrix.outputs.matrix).versions) }}
highest: ${{ fromJSON(steps.php-matrix.outputs.matrix).highest }}
versions: ${{ steps.php-matrix.outputs.versions }}
highest: ${{ steps.php-matrix.outputs.highest }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -205,7 +182,7 @@ jobs:
needs: php-matrix
strategy:
matrix:
php: ${{ fromJSON(needs.php-matrix.outputs.versions }}
php: ${{ fromJSON(needs.php-matrix.outputs.versions) }}
dependency-versions: [lowest, highest]
coverage: [none]
exclude:
Expand Down
15 changes: 12 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,18 @@ inputs:
default: ${{ github.token }}

outputs:
matrix:
description: The PHP version matrix
value: ${{ steps.generate-matrix.outputs.matrix }}
constraint:
description: The `require.php` constraint found in `composer.json`
value: ${{ fromJSON(steps.generate-matrix.outputs.matrix).constraint }}
highest:
description: Highest supported PHP versions
value: ${{ fromJSON(steps.generate-matrix.outputs.matrix).highest }}
lowest:
description: Lowest supported PHP versions
value: ${{ fromJSON(steps.generate-matrix.outputs.matrix).lowest }}
versions:
description: Array of all supported PHP versions
value: ${{ toJSON(fromJSON(steps.generate-matrix.outputs.matrix).versions) }}

runs:
using: "composite"
Expand Down
Loading