Skip to content

Commit 5383e9c

Browse files
authored
Update README.md (#6)
1 parent 0ec3346 commit 5383e9c

File tree

1 file changed

+183
-21
lines changed

1 file changed

+183
-21
lines changed

README.md

Lines changed: 183 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[![Hire Typist Tech](https://img.shields.io/badge/Hire-Typist%20Tech-778899)](https://typist.tech/contact/)
1313

1414
<p>
15-
<strong>TODO.</strong>
15+
<strong>Generate PHP version matrix according to `composer.json`.</strong>
1616
<br>
1717
<br>
1818
Built with ♥ by <a href="https://typist.tech/">Typist Tech</a>
@@ -24,32 +24,194 @@
2424

2525
## Usage
2626

27-
TODO
28-
29-
### Inputs
30-
31-
TODO
32-
33-
#### `mode`
34-
35-
Available modes:
36-
- `minor-only` *(default)*: Report `MAJOR.MINOR` versions only
37-
- `full`: Report all satisfying versions in `MAJOR.MINOR.PATCH` format
38-
39-
#### `source`
40-
41-
Available sources:
42-
- `auto` *(default)*: Use `offline` in `minor-only` mode. Otherwise, fetch from [php.net](https://www.php.net/releases/index.php)
43-
- `php.net`: Fetch releases information from [php.net](https://www.php.net/releases/index.php)
44-
- `offline`: Use [hardcoded releases](https://github.com/typisttech/php-matrix/blob/main/resources/all-versions.json) information
27+
See [action.yml](action.yml) and the underlying script [`typisttech/php-matrix`](https://github.com/typisttech/php-matrix/#options).
28+
29+
```yaml
30+
- uses: typisttech/php-matrix-action@v1
31+
with:
32+
# Version format.
33+
#
34+
# Available modes:
35+
# - `minor-only`: Report `MAJOR.MINOR` versions only
36+
# - `full`: Report all satisfying versions in `MAJOR.MINOR.PATCH` format
37+
#
38+
# Default: minor-only
39+
mode: ''
40+
41+
# Source of releases information.
42+
#
43+
# Available sources:
44+
# - `auto`: Use `offline` in `minor-only` mode. Otherwise, fetch from [php.net]
45+
# - `php.net`: Fetch releases information from [php.net]
46+
# - `offline`: Use [hardcoded releases] information
47+
#
48+
# [php.net]: https://www.php.net/releases/index.php
49+
# [hardcoded releases]: https://github.com/typisttech/php-matrix/blob/main/resources/all-versions.json
50+
#
51+
# Default: auto
52+
source: ''
53+
```
4554
4655
### Outputs
4756
48-
TODO
57+
This action yields a single output `matrix` which is a JSON-encoded string of:
58+
59+
| Key | Description | Example |
60+
| --- | --- | --- |
61+
| `constraint` | PHP constraint found in `composer.json` | `^7.3 \|\| ^8.0` |
62+
| `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"]` |
63+
| `lowest` | Lowest supported PHP versions | In `minor-only` mode, `7.3`<br><br>In `full` mode, `7.3.0` |
64+
| `highest` | Highest supported PHP versions | In `minor-only` mode, `8.4`<br><br>In `full` mode, `8.4.2` |
65+
66+
> [!TIP]
67+
>
68+
> 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.
69+
>
70+
> ```yaml
71+
> jobs:
72+
> php-matrix:
73+
> runs-on: ubuntu-latest
74+
> outputs:
75+
> matrix: ${{ steps.php-matrix.outputs.matrix }}
76+
> constraint: ${{ fromJSON(steps.php-matrix.outputs.matrix).constraint }}
77+
> # Use `fromJSON()` when accessing `versions`!
78+
> versions: ${{ toJSON(fromJSON(steps.php-matrix.outputs.matrix).versions) }}
79+
> lowest: ${{ fromJSON(steps.php-matrix.outputs.matrix).lowest }}
80+
> highest: ${{ fromJSON(steps.php-matrix.outputs.matrix).highest }}
81+
> steps:
82+
> - uses: actions/checkout@v4
83+
> - uses: typisttech/php-matrix-action@main
84+
> id: php-matrix
85+
> ```
4986

5087
## Examples
5188

52-
TODO
89+
<details>
90+
<summary>Run tests against all supported PHP minor versions.</summary>
91+
92+
```yaml
93+
name: Test
94+
95+
on:
96+
push:
97+
98+
jobs:
99+
php-matrix:
100+
runs-on: ubuntu-latest
101+
outputs:
102+
matrix: ${{ steps.php-matrix.outputs.matrix }}
103+
steps:
104+
- uses: actions/checkout@v4
105+
- uses: typisttech/php-matrix-action@v1
106+
id: php-matrix
107+
108+
test:
109+
runs-on: ubuntu-latest
110+
needs: php-matrix
111+
strategy:
112+
matrix:
113+
php: ${{ fromJSON(needs.php-matrix.outputs.matrix).versions }}
114+
steps:
115+
- uses: actions/checkout@v4
116+
- uses: shivammathur/setup-php@v2
117+
with:
118+
php-version: ${{ matrix.php }}
119+
- run: composer install
120+
- run: composer test
121+
```
122+
123+
</details>
124+
125+
<details>
126+
<summary>Run `$ pint --test` with the lowest supported PHP minor version.</summary>
127+
128+
```yaml
129+
name: Pint
130+
131+
on:
132+
push:
133+
134+
jobs:
135+
pint:
136+
runs-on: ubuntu-latest
137+
steps:
138+
- uses: actions/checkout@v4
139+
140+
- uses: typisttech/php-matrix-action@v1
141+
id: php-matrix
142+
143+
- uses: shivammathur/setup-php@v2
144+
with:
145+
php-version: ${{ fromJSON(steps.php-matrix.outputs.matrix).lowest }}
146+
tools: pint
147+
148+
- run: pint --test
149+
```
150+
151+
</details>
152+
153+
<details>
154+
<summary>Run tests with coverage.</summary>
155+
156+
```yaml
157+
name: Test
158+
159+
on:
160+
push:
161+
162+
jobs:
163+
php-matrix:
164+
runs-on: ubuntu-latest
165+
outputs:
166+
versions: ${{ toJSON(fromJSON(steps.php-matrix.outputs.matrix).versions) }}
167+
highest: ${{ fromJSON(steps.php-matrix.outputs.matrix).highest }}
168+
steps:
169+
- uses: actions/checkout@v4
170+
with:
171+
sparse-checkout: composer.json
172+
sparse-checkout-cone-mode: false
173+
174+
- uses: typisttech/php-matrix-action@v1
175+
id: php-matrix
176+
177+
test:
178+
runs-on: ubuntu-latest
179+
needs: php-matrix
180+
strategy:
181+
matrix:
182+
php: ${{ fromJSON(needs.php-matrix.outputs.versions }}
183+
dependency-versions: [lowest, highest]
184+
coverage: [none]
185+
exclude:
186+
- php: ${{ needs.php-matrix.outputs.highest }}
187+
dependency-versions: highest
188+
coverage: none
189+
include:
190+
- php: ${{ needs.php-matrix.outputs.highest }}
191+
dependency-versions: highest
192+
coverage: xdebug
193+
steps:
194+
- uses: actions/checkout@v4
195+
196+
- uses: shivammathur/setup-php@v2
197+
with:
198+
php-version: ${{ matrix.php }}
199+
coverage: ${{ matrix.coverage }}
200+
env:
201+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
202+
203+
- uses: ramsey/composer-install@v3
204+
with:
205+
dependency-versions: ${{ matrix.dependency-versions }}
206+
207+
- run: composer test:with-coverage
208+
if: ${{ matrix.coverage == 'xdebug' }}
209+
210+
- run: composer test:without-coverage
211+
if: ${{ matrix.coverage != 'xdebug' }}
212+
```
213+
214+
</details>
53215

54216
## Credits
55217

0 commit comments

Comments
 (0)