Skip to content

Commit f58e692

Browse files
committed
Decode action output; Remove matrix output
1 parent 51ce2a6 commit f58e692

File tree

3 files changed

+60
-34
lines changed

3 files changed

+60
-34
lines changed

.github/workflows/test.yml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,49 @@ jobs:
8585
source: ${{ matrix.source }}
8686
verify-attestation: ${{ matrix.verify-attestation }}
8787

88-
- run: echo '${{ steps.subject.outputs.matrix }}' > actual.json
88+
- run: |
89+
{
90+
echo "{"
91+
echo '"constraint": "${{ steps.subject.outputs.constraint }}",'
92+
echo '"highest": "${{ steps.subject.outputs.highest }}",'
93+
echo '"lowest": "${{ steps.subject.outputs.lowest }}",'
94+
echo '"versions": ${{ steps.subject.outputs.versions }}'
95+
echo "}"
96+
} >> actual.json
8997
9098
- run: diff <(jq --sort-keys . actual.json) <(jq --sort-keys . local-action/testdata/${{ matrix.case }}.${{ matrix.mode }}.golden.json)
9199

100+
outputs:
101+
runs-on: ubuntu-latest
102+
steps:
103+
- uses: actions/checkout@v5
104+
with:
105+
path: local-action
106+
107+
- uses: ./local-action
108+
id: subject
109+
with:
110+
composer-json: local-action/testdata/complex.composer.json
111+
mode: minor-only
112+
source: offline
113+
verify-attestation: false
114+
115+
- name: Assert constraint output
116+
run: exit 1
117+
if: steps.subject.outputs.constraint != '^7.3.32 || ^8.1 <=8.1.9'
118+
119+
- name: Assert versions output
120+
run: exit 1
121+
if: steps.subject.outputs.versions != toJSON(fromJSON('["7.3","7.4","8.1"]'))
122+
123+
- name: Assert lowest output
124+
run: exit 1
125+
if: steps.subject.outputs.lowest != '7.3'
126+
127+
- name: Assert highest output
128+
run: exit 1
129+
if: steps.subject.outputs.highest != '8.1'
130+
92131
negative:
93132
runs-on: ubuntu-latest
94133
strategy:
@@ -159,6 +198,7 @@ jobs:
159198
wait-for-all-tests:
160199
needs:
161200
- positive
201+
- outputs
162202
- negative
163203
- missing
164204
runs-on: ubuntu-latest

README.md

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -79,36 +79,13 @@ See [action.yml](action.yml) and the underlying script [`typisttech/php-matrix`]
7979
8080
### Outputs
8181
82-
This action yields **a single output** `matrix` which is a JSON-encoded string of:
83-
8482
| Key | Description | Example |
8583
| --- | --- | --- |
8684
| `constraint` | PHP constraint found in `composer.json` | `^7.3 \|\| ^8.0` |
87-
| `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"]` |
85+
| `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"]` |
8886
| `lowest` | Lowest supported PHP versions | In `minor-only` mode, `7.3`<br><br>In `full` mode, `7.3.0` |
8987
| `highest` | Highest supported PHP versions | In `minor-only` mode, `8.4`<br><br>In `full` mode, `8.4.2` |
9088

91-
> [!TIP]
92-
>
93-
> 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.
94-
>
95-
> ```yaml
96-
> jobs:
97-
> php-matrix:
98-
> runs-on: ubuntu-latest
99-
> outputs:
100-
> matrix: ${{ steps.php-matrix.outputs.matrix }}
101-
> constraint: ${{ fromJSON(steps.php-matrix.outputs.matrix).constraint }}
102-
> # Use `fromJSON()` when accessing `versions`!
103-
> versions: ${{ toJSON(fromJSON(steps.php-matrix.outputs.matrix).versions) }}
104-
> lowest: ${{ fromJSON(steps.php-matrix.outputs.matrix).lowest }}
105-
> highest: ${{ fromJSON(steps.php-matrix.outputs.matrix).highest }}
106-
> steps:
107-
> - uses: actions/checkout@v4
108-
> - uses: typisttech/php-matrix-action@main
109-
> id: php-matrix
110-
> ```
111-
11289
## Examples
11390

11491
<details open>
@@ -124,7 +101,7 @@ jobs:
124101
php-matrix:
125102
runs-on: ubuntu-latest
126103
outputs:
127-
matrix: ${{ steps.php-matrix.outputs.matrix }}
104+
versions: ${{ steps.php-matrix.outputs.versions }}
128105
steps:
129106
- uses: actions/checkout@v4
130107
- uses: typisttech/php-matrix-action@v1
@@ -135,7 +112,7 @@ jobs:
135112
needs: php-matrix
136113
strategy:
137114
matrix:
138-
php: ${{ fromJSON(needs.php-matrix.outputs.matrix).versions }}
115+
php: ${{ fromJSON(needs.php-matrix.outputs.versions) }}
139116
steps:
140117
- uses: actions/checkout@v4
141118
- uses: shivammathur/setup-php@v2
@@ -167,7 +144,7 @@ jobs:
167144
168145
- uses: shivammathur/setup-php@v2
169146
with:
170-
php-version: ${{ fromJSON(steps.php-matrix.outputs.matrix).lowest }}
147+
php-version: ${{ steps.php-matrix.outputs.lowest }}
171148
172149
- run: composer install
173150
@@ -189,8 +166,8 @@ jobs:
189166
php-matrix:
190167
runs-on: ubuntu-latest
191168
outputs:
192-
versions: ${{ toJSON(fromJSON(steps.php-matrix.outputs.matrix).versions) }}
193-
highest: ${{ fromJSON(steps.php-matrix.outputs.matrix).highest }}
169+
versions: ${{ steps.php-matrix.outputs.versions }}
170+
highest: ${{ steps.php-matrix.outputs.highest }}
194171
steps:
195172
- uses: actions/checkout@v4
196173
with:
@@ -205,7 +182,7 @@ jobs:
205182
needs: php-matrix
206183
strategy:
207184
matrix:
208-
php: ${{ fromJSON(needs.php-matrix.outputs.versions }}
185+
php: ${{ fromJSON(needs.php-matrix.outputs.versions) }}
209186
dependency-versions: [lowest, highest]
210187
coverage: [none]
211188
exclude:

action.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,18 @@ inputs:
3333
default: ${{ github.token }}
3434

3535
outputs:
36-
matrix:
37-
description: The PHP version matrix
38-
value: ${{ steps.generate-matrix.outputs.matrix }}
36+
constraint:
37+
description: The `require.php` constraint found in `composer.json`
38+
value: ${{ fromJSON(steps.generate-matrix.outputs.matrix).constraint }}
39+
highest:
40+
description: Highest supported PHP versions
41+
value: ${{ fromJSON(steps.generate-matrix.outputs.matrix).highest }}
42+
lowest:
43+
description: Lowest supported PHP versions
44+
value: ${{ fromJSON(steps.generate-matrix.outputs.matrix).lowest }}
45+
versions:
46+
description: Array of all supported PHP versions
47+
value: ${{ toJSON(fromJSON(steps.generate-matrix.outputs.matrix).versions) }}
3948

4049
runs:
4150
using: "composite"

0 commit comments

Comments
 (0)