From f58e69282e63573b8386d1176e45f59e6ca542b4 Mon Sep 17 00:00:00 2001 From: TangRufus Date: Sat, 18 Oct 2025 17:16:01 +0100 Subject: [PATCH] Decode action output; Remove `matrix` output --- .github/workflows/test.yml | 42 +++++++++++++++++++++++++++++++++++++- README.md | 37 +++++++-------------------------- action.yml | 15 +++++++++++--- 3 files changed, 60 insertions(+), 34 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0e55d81..c4de962 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: @@ -159,6 +198,7 @@ jobs: wait-for-all-tests: needs: - positive + - outputs - negative - missing runs-on: ubuntu-latest diff --git a/README.md b/README.md index aa2cc5a..cc2a203 100644 --- a/README.md +++ b/README.md @@ -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"]`

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"]`

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`

In `full` mode, `7.3.0` | | `highest` | Highest supported PHP versions | In `minor-only` mode, `8.4`

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
@@ -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 @@ -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 @@ -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 @@ -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: @@ -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: diff --git a/action.yml b/action.yml index 953a02b..d3daafb 100644 --- a/action.yml +++ b/action.yml @@ -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"