Skip to content

Commit c49e564

Browse files
committed
Add php_version action input with 5.4-7.4 validation
1 parent 1d93fa2 commit c49e564

4 files changed

Lines changed: 25 additions & 5 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
- name: Generating documentation...
2727
uses: impresscms-dev/generate-phpdocs-with-evert-phpdoc-md-action@v1.0.0
2828
with:
29+
php_version: '7.4'
2930
output_path: ./docs/
3031
ignored_files: |
3132
test/
@@ -42,6 +43,7 @@ jobs:
4243
This action supports such arguments (used in `with` keyword):
4344
| Argument | Required | Default value | Description |
4445
|-------------|----------|----------------------|-----------------------------------|
46+
| php_version | No | 7.4 | PHP version to run (accepted range: `5.4` to `7.4`, inclusive) |
4547
| ignored_files | No | | Defines files that can be ignored (supports glob rules; each line means one rule) |
4648
| phpdocumentor_version | No | v2.8.5 | What [phpDocumentor](https://www.phpdoc.org) version to use (latest or release tag like `v2.8.5`) |
4749
| output_path | Yes | | Path where to write generated documentation |
@@ -51,6 +53,7 @@ This action supports such arguments (used in `with` keyword):
5153
- Docker build clones `git@github.com:evert/phpdoc-md.git` directly and falls back to HTTPS clone when SSH credentials are not available.
5254
- phpDocumentor release artifacts are downloaded during action runtime and are not stored in this repository.
5355
- Dockerfile supports selecting PHP by version: `docker build --build-arg PHP_VERSION=7.4 .`
56+
- `php_version` input must match the container runtime version (this image version is controlled by `PHP_VERSION` build arg).
5457
- Tests are JavaScript integration tests based on [testcontainers-node](https://github.com/testcontainers/testcontainers-node).
5558

5659
## How to contribute?

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ branding:
66
color: red
77

88
inputs:
9+
php_version:
10+
description: "PHP version to run (must be between 5.4 and 7.4 inclusive)"
11+
required: false
12+
default: '7.4'
913
ignored_files:
1014
description: "Defines files that can be ignored (supports glob rules; each line means one rule)"
1115
required: false
@@ -22,6 +26,7 @@ runs:
2226
using: 'docker'
2327
image: 'Dockerfile'
2428
args:
29+
- ${{ inputs.php_version }}
2530
- ${{ inputs.output_path }}
2631
- ${{ inputs.ignored_files }}
2732
- ${{ inputs.phpdocumentor_version }}

bin/entrypoint.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@
22

33
set -euo pipefail
44

5-
OUTPUT_PATH=${1:-}
6-
IGNORED_FILES=${2:-}
7-
PHPDOC_VERSION=${3:-v2.8.5}
5+
REQUESTED_PHP_VERSION=${1:-7.4}
6+
OUTPUT_PATH=${2:-}
7+
IGNORED_FILES=${3:-}
8+
PHPDOC_VERSION=${4:-v2.8.5}
9+
10+
if ! php -r '$version = isset($argv[1]) ? $argv[1] : ""; if (!preg_match("/^(5\\.[4-6]|7\\.[0-4])$/", $version)) { fwrite(STDERR, "Input '\''php_version'\'' must be between 5.4 and 7.4 (inclusive).\n"); exit(1); }' "$REQUESTED_PHP_VERSION"; then
11+
exit 1
12+
fi
13+
14+
RUNTIME_PHP_VERSION=$(php -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;')
15+
if [[ "$REQUESTED_PHP_VERSION" != "$RUNTIME_PHP_VERSION" ]]; then
16+
echo "Input 'php_version' is '$REQUESTED_PHP_VERSION' but action container uses PHP '$RUNTIME_PHP_VERSION'. Build the action image with matching PHP_VERSION." >&2
17+
exit 1
18+
fi
819

920
if [[ -z "$OUTPUT_PATH" ]]; then
1021
echo "Input 'output_path' is required." >&2

tests/action-container.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async function buildActionImage(phpVersion) {
6767
return imageTag;
6868
}
6969

70-
async function runAction(actionImage, ignoredFiles, phpDocumentorVersion) {
70+
async function runAction(actionImage, phpVersion, ignoredFiles, phpDocumentorVersion) {
7171
const workspacePath = await mkdtemp(path.join(os.tmpdir(), "phpdoc-action-workspace-"));
7272

7373
await cp(fixtureProjectPath, workspacePath, { recursive: true });
@@ -101,6 +101,7 @@ async function runAction(actionImage, ignoredFiles, phpDocumentorVersion) {
101101
startedContainer = await container.start();
102102
const execResult = await startedContainer.exec([
103103
"/usr/local/bin/entrypoint.sh",
104+
phpVersion,
104105
"docs",
105106
ignoredFiles,
106107
phpDocumentorVersion
@@ -162,7 +163,7 @@ const phpDocumentorVersion = process.env.PHPDOC_VERSION || "v2.8.5";
162163

163164
test(`boots container and generates markdown (php:${phpVersion}-cli)`, async () => {
164165
const actionImage = await buildActionImage(phpVersion);
165-
const { docsOutputPath, workspacePath } = await runAction(actionImage, "", phpDocumentorVersion);
166+
const { docsOutputPath, workspacePath } = await runAction(actionImage, phpVersion, "", phpDocumentorVersion);
166167

167168
try {
168169
const indexStat = await stat(path.join(docsOutputPath, "ApiIndex.md"));

0 commit comments

Comments
 (0)