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
39 changes: 27 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ and you want your workflow to set up PHP with the version 8.1 using the shivamma
name: My workflow
on: [push, pull_request]

permissions:
contents: read

jobs:
my-workflow:
runs-on: ubuntu-latest
Expand All @@ -67,10 +70,12 @@ jobs:
php-version: ${{ steps.php-version.outputs.minimal }}
tools: composer:v2

- name: Validate composer.json and composer.lock
run: composer validate
- name: Test
run: echo "run your tests"
```

![Test with minimal](doc/test-minimal.png)

If you want to do the same but using the latest PHP version that meets the requirements defined in `composer.json`, you
simply need to replace `steps.php-version.outputs.minimal` by `steps.php-version.outputs.latest`

Expand All @@ -80,9 +85,12 @@ Let's say you want to run the unit tests on all versions starting from the minim
until the latest released one, you need to run the version lookup as a separate job:

```yaml
name: Testing all PHP versions
name: Testing matrix
on: [push, pull_request]

permissions:
contents: read

jobs:
php-versions:
name: Lookup PHP versions
Expand All @@ -95,13 +103,13 @@ jobs:
id: versions

test:
name: Test on ${{ matrix.os }} with PHP ${{ matrix.php-version }}
name: Test PHP ${{ matrix.php-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: php-versions

strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest] # add more os
php-version: ${{ fromJSON(needs.php-versions.outputs.matrix) }}

steps:
Expand All @@ -115,12 +123,12 @@ jobs:
coverage: xdebug
tools: composer:v2

- name: Run Tests
run: |
composer install
vendor/bin/phpunit -v
- name: Test
run: echo "run your tests"
```

![Test with matrix](doc/test-matrix.png)

### Custom Working Directory

If your `composer.json` is in a subdirectory:
Expand All @@ -138,11 +146,18 @@ If your `composer.json` is in a subdirectory:
The action supports all the constraints supported by
[Composer](https://getcomposer.org/doc/articles/versions.md#writing-version-constraints)

## Summary

The action writes a
[GitHub Actions Job Summary](https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/) with
output values it identified.

![Job summary](doc/job-summary.png)

## Areas for Improvement

1. Add a GitHub Actions Job Summary with values it identified.
2. Add an input `unstable` to include unstable versions (beta, release candidates)
3. Add an input `unsupported` to include old versions not longer supported
1. Add an input `unstable` to include unstable versions (beta, release candidates)
2. Add an input `unsupported` to include old versions not longer supported

---

Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 17 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Binary file added doc/job-summary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/test-matrix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/test-minimal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 21 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,27 @@ export async function run(): Promise<void> {
core.setOutput('minimal', min)
core.setOutput('latest', lat)

core.debug(`PHP version defined in ${workingDir} is ${composerPhpVersion}`)
const matrixWithLinks = mat
.map(
(v) =>
`<a href="https://www.php.net/ChangeLog-${v.split('.')[0]}.php#PHP_${v.replaceAll('.', '_')}">PHP ${v}</a>`
)
.join('<br>')

await core.summary
.addHeading('PHP versions summary')
.addTable([
[
{ data: 'Output', header: true },
{ data: 'Value', header: true }
],
['Composer requirements', composerPhpVersion],
['minimal', `<a href="https://www.php.net/releases/${min}/en.php">PHP ${min}</a>`],
['latest', `<a href="https://www.php.net/releases/${lat}/en.php">PHP ${lat}</a>`],
['matrix', matrixWithLinks]
])
.addRaw(`data extracted from <code>${workingDir}/composer.json</code>`)
.write()
} catch (error) {
// Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message)
Expand Down