Skip to content

Commit

Permalink
Merge pull request #25 from WyriHaximus/working-directory-input
Browse files Browse the repository at this point in the history
Working directory input
  • Loading branch information
WyriHaximus authored Sep 1, 2023
2 parents 83318f1 + 581ee57 commit 35f3c65
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 58 deletions.
118 changes: 61 additions & 57 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,47 @@ on:
pull_request:
jobs:
get-supported-php-versions:
name: Test Composer PHP verions in range Tag on ${{ matrix.os }}
name: Test Composer PHP versions in range Tag on ${{ matrix.os }} in ${{ matrix.workingDirectory }}
strategy:
fail-fast: false
matrix:
include:
- workingDirectory: "another-working-directory/"
highestUpcoming: "5.6"
highest: "5.6"
lowest: "5.3"
extensions: "ast,pcov,xdebug"
requiredExtensions: "ast"
requiredDevExtensions: "pcov,xdebug"
os: ubuntu-latest
- workingDirectory: "another-working-directory"
highestUpcoming: "5.6"
highest: "5.6"
lowest: "5.3"
extensions: "ast,pcov,xdebug"
requiredExtensions: "ast"
requiredDevExtensions: "pcov,xdebug"
os: ubuntu-latest
os:
- ubuntu-latest
- windows-latest
- macos-latest
workingDirectory:
- ""
highestUpcoming:
- "8.3"
highest:
- "8.2"
lowest:
- "7.3"
extensions:
- "ast,pcov,xdebug"
requiredExtensions:
- "ast"
requiredDevExtensions:
- "pcov,xdebug"
outputs:
highestUpcoming: ${{ steps.versionsinrangeincludingupcomingreleases.outputs.highest }}
highest: ${{ steps.versionsinrange.outputs.highest }}
lowest: ${{ steps.versionsinrange.outputs.lowest }}
version: ${{ steps.versionsinrange.outputs.version }}
extensions: ${{ steps.versionsinrange.outputs.extensions }}
requiredExtensions: ${{ steps.versionsinrange.outputs.requiredExtensions }}
requiredDevExtensions: ${{ steps.versionsinrange.outputs.requiredDevExtensions }}
Expand All @@ -27,61 +56,54 @@ jobs:
- name: 'Composer PHP versions in range'
id: versionsinrange
uses: ./
with:
workingDirectory: ${{ matrix.workingDirectory }}
- run: |
echo "${{ steps.versionsinrange.outputs.version }}"
- name: 'Composer PHP versions in range including upcoming releases'
id: versionsinrangeincludingupcomingreleases
uses: ./
with:
upcomingReleases: true
workingDirectory: ${{ matrix.workingDirectory }}
- run: |
echo "${{ steps.versionsinrangeincludingupcomingreleases.outputs.version }}"
highest:
name: The highest detected version is ${{ needs.get-supported-php-versions.outputs.highest }} on ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
needs:
- get-supported-php-versions
runs-on: ${{ matrix.os }}
steps:
- run: |
echo "${{ needs.get-supported-php-versions.outputs.highest }}"
- name: "Assert Output: lowest"
uses: therussiankid92/gat@v1
with:
assertion: should.equal
expected: ${{ matrix.lowest }}
actual: ${{ steps.versionsinrange.outputs.lowest }}
- name: "Assert Output: highest"
uses: therussiankid92/gat@v1
with:
assertion: should.equal
expected: 8.2
actual: ${{ needs.get-supported-php-versions.outputs.highest }}
expected: ${{ matrix.highest }}
actual: ${{ steps.versionsinrange.outputs.highest }}
- name: "Assert Output: highest (upcoming releases)"
uses: therussiankid92/gat@v1
with:
assertion: should.equal
expected: 8.3
actual: ${{ needs.get-supported-php-versions.outputs.highestUpcoming }}
lowest:
name: The lowest detected version is ${{ needs.get-supported-php-versions.outputs.lowest }} on ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
needs:
- get-supported-php-versions
runs-on: ${{ matrix.os }}
steps:
- run: |
echo "${{ needs.get-supported-php-versions.outputs.lowest }}"
- name: "Assert Output: lowest"
expected: ${{ matrix.highestUpcoming }}
actual: ${{ steps.versionsinrangeincludingupcomingreleases.outputs.highest }}
- name: "Assert Output: extensions"
uses: therussiankid92/gat@v1
with:
assertion: should.equal
expected: ${{ matrix.extensions }}
actual: ${{ join(fromJson(steps.versionsinrange.outputs.extensions), ',') }}
- name: "Assert Output: requiredExtensions"
uses: therussiankid92/gat@v1
with:
assertion: should.equal
expected: ${{ matrix.requiredExtensions }}
actual: ${{ join(fromJson(steps.versionsinrange.outputs.requiredExtensions), ',') }}
- name: "Assert Output: requiredDevExtensions"
uses: therussiankid92/gat@v1
with:
assertion: should.equal
expected: 7.3
actual: ${{ needs.get-supported-php-versions.outputs.lowest }}
expected: ${{ matrix.requiredDevExtensions }}
actual: ${{ join(fromJson(steps.versionsinrange.outputs.requiredDevExtensions), ',') }}
extensions:
name: Detected extensions on ${{ matrix.os }}
strategy:
Expand All @@ -104,21 +126,3 @@ jobs:
tools: composer
coverage: none
extensions: ${{ join(fromJson(needs.get-supported-php-versions.outputs.extensions), ',') }}
- name: "Assert Output: extensions"
uses: therussiankid92/gat@v1
with:
assertion: should.equal
expected: ast,pcov,xdebug
actual: ${{ join(fromJson(needs.get-supported-php-versions.outputs.extensions), ',') }}
- name: "Assert Output: requiredExtensions"
uses: therussiankid92/gat@v1
with:
assertion: should.equal
expected: ast
actual: ${{ join(fromJson(needs.get-supported-php-versions.outputs.requiredExtensions), ',') }}
- name: "Assert Output: requiredDevExtensions"
uses: therussiankid92/gat@v1
with:
assertion: should.equal
expected: pcov,xdebug
actual: ${{ join(fromJson(needs.get-supported-php-versions.outputs.requiredDevExtensions), ',') }}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ that will be `8.2`.
* *Default*: `false`
* *Example*: `true` for including upcoming new major or minor releases

### workingDirectory

Set a different than the root directory to look for `composer.json`

* *Required*: `No`
* *Type*: `String`
* *Default*: `""`
* *Example*: `clients/GitHub`

## Output

The action comes with 7 outputs, most importantly `version` which contains a JSON list with versions to be used in
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ inputs:
upcomingReleases:
description: 'Include upcoming new major or minor releases'
required: false
workingDirectory:
description: The directory to run this action in
default: ""
required: false
outputs:
highest:
description: 'The highest version found in range'
Expand Down
10 changes: 10 additions & 0 deletions another-working-directory/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"require": {
"php": "^5",
"ext-ast": "*"
},
"require-dev": {
"ext-pcov": "*",
"ext-xdebug": "*"
}
}
9 changes: 8 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
const semver = require('semver');
const fs = require('fs');
const composerJsonPath = (
process.env.INPUT_WORKINGDIRECTORY.toString().length > 0 ? (
(process.env.INPUT_WORKINGDIRECTORY.endsWith('/') ? process.env.INPUT_WORKINGDIRECTORY.slice(0, -1) : process.env.INPUT_WORKINGDIRECTORY) + '/'
) : ''
) + 'composer.json';

let composerJson = JSON.parse(fs.readFileSync('composer.json'));
console.log(composerJsonPath);

let composerJson = JSON.parse(fs.readFileSync(composerJsonPath));
let supportedVersionsRange = composerJson['require']['php'].toString().replaceAll('||', 'PIPEPIPEPLACEHOLDER').replaceAll('|', '||').replaceAll('PIPEPIPEPLACEHOLDER', '||');

let versions = [];
Expand Down

0 comments on commit 35f3c65

Please sign in to comment.