Skip to content

Commit edd0c12

Browse files
authored
Merge pull request #48 from impresscms-dev/feat/container-action
Rewrite action to Docker container + JS Testcontainers tests
2 parents b7684dd + c49e564 commit edd0c12

34 files changed

Lines changed: 2638 additions & 432 deletions

.dockerignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.git
2+
.github
3+
.idea
4+
.zencoder
5+
node_modules
6+
tests
7+
package.json
8+
package-lock.json
9+
README.md
10+
LICENSE

.github/workflows/on-pull-request.yml

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,54 @@ jobs:
1010
test:
1111
runs-on: ubuntu-latest
1212
strategy:
13+
fail-fast: true
14+
max-parallel: 3
1315
matrix:
14-
php:
15-
- 5.6
16-
- 7.0
17-
- 7.1
18-
- 7.2
19-
- 7.3
20-
- 7.4
16+
php_version:
17+
- '5.4'
18+
- '7.0'
19+
- '7.1'
20+
- '7.2'
21+
- '7.3'
22+
- '7.4'
2123

2224
steps:
2325
- name: Checkouting code...
2426
uses: actions/checkout@v5
2527

26-
- name: Installing PHP...
27-
uses: shivammathur/setup-php@2.35.5
28-
with:
29-
php-version: ${{ matrix.php }}
30-
extensions: curl, gd, json, mbstring, pcre, session
31-
coverage: none
32-
tools: composer:v2
28+
- name: Read Node.js version from package.json
29+
id: node-version
30+
run: |
31+
NODE_VERSION=$(jq -r '.engines.node // empty' package.json)
32+
if [[ -z "$NODE_VERSION" || "$NODE_VERSION" == "null" ]]; then
33+
echo "package.json engines.node is required" >&2
34+
exit 1
35+
fi
36+
echo "version=$NODE_VERSION" >> "$GITHUB_OUTPUT"
3337
34-
- name: Setup BATS
35-
uses: mig4/setup-bats@v1
38+
- name: Setup Node.js
39+
uses: actions/setup-node@v4
3640
with:
37-
bats-version: 1.9.0
41+
node-version: ${{ steps.node-version.outputs.version }}
42+
43+
- name: Enable legacy Docker schema v1 pulls for old PHP tags
44+
run: |
45+
sudo mkdir -p /etc/systemd/system/docker.service.d
46+
cat <<'EOF' | sudo tee /etc/systemd/system/docker.service.d/10-enable-schema1.conf
47+
[Service]
48+
Environment=CONTAINERD_ENABLE_DEPRECATED_PULL_SCHEMA_1_IMAGE=1
49+
EOF
50+
sudo systemctl daemon-reload
51+
sudo systemctl restart docker
52+
docker version
3853
39-
- name: Test
40-
run: bats tests
54+
- name: Install dependencies
55+
run: npm ci
56+
57+
- name: Run integration tests
58+
run: npm test
59+
env:
60+
PHP_VERSION: ${{ matrix.php_version }}
4161

4262
dependabot:
4363
needs:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
/.idea/
22
/vendor/
33
/composer.lock
4+
/node_modules/
5+
/.phpdoc/
6+
/phpDocumentor.phar

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
ARG PHP_VERSION=7.4
2+
ARG PHPDOC_VERSION=v2.8.5
3+
4+
FROM php:8.3-cli-bookworm AS phpdocmd-builder
5+
ARG PHPDOC_VERSION
6+
7+
COPY --from=composer:2.2 /usr/bin/composer /usr/local/bin/composer
8+
9+
COPY --chmod=0755 bin/install-builder-deps.sh bin/setup-phpdoc-md.sh bin/setup-phpdocumentor-cache.sh /usr/local/bin/
10+
RUN /usr/local/bin/install-builder-deps.sh
11+
12+
RUN /usr/local/bin/setup-phpdoc-md.sh
13+
RUN /usr/local/bin/setup-phpdocumentor-cache.sh /opt/phpdocumentor-cache "$PHPDOC_VERSION"
14+
15+
FROM php:${PHP_VERSION}-cli
16+
17+
COPY --from=phpdocmd-builder /opt/phpdoc-md /opt/phpdoc-md
18+
COPY --from=phpdocmd-builder /opt/phpdocumentor-cache /opt/phpdocumentor-cache
19+
COPY --chmod=0755 bin/entrypoint.sh /usr/local/bin/entrypoint.sh
20+
21+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

README.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
GitHub action to generate PHP project documentation in [MarkDown](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax) format. Based on [evert/phpdoc-md](https://github.com/evert/phpdoc-md) library.
77

8-
***Warning***: at current moment this action doesn't work with PHP newer than 7.4.
8+
This action is container-based and runs on official PHP Docker images. It does not require setting up PHP or Composer on the runner.
99

1010
## Usage
1111

@@ -22,22 +22,11 @@ jobs:
2222
steps:
2323
- name: Checkouting project code...
2424
uses: actions/checkout@v2
25-
26-
- name: Install PHP
27-
uses: shivammathur/setup-php@v2.2
28-
with:
29-
php-version: 7.4
30-
extensions: curl, gd, pdo_mysql, json, mbstring, pcre, session
31-
ini-values: post_max_size=256M
32-
coverage: none
33-
tools: composer:v2
34-
35-
- name: Install Composer dependencies (with dev)
36-
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
37-
25+
3826
- name: Generating documentation...
3927
uses: impresscms-dev/generate-phpdocs-with-evert-phpdoc-md-action@v1.0.0
4028
with:
29+
php_version: '7.4'
4130
output_path: ./docs/
4231
ignored_files: |
4332
test/
@@ -54,10 +43,19 @@ jobs:
5443
This action supports such arguments (used in `with` keyword):
5544
| Argument | Required | Default value | Description |
5645
|-------------|----------|----------------------|-----------------------------------|
46+
| php_version | No | 7.4 | PHP version to run (accepted range: `5.4` to `7.4`, inclusive) |
5747
| ignored_files | No | | Defines files that can be ignored (supports glob rules; each line means one rule) |
58-
| phpdocumentor_version | No | latest | What [PHP Documentator](https://www.phpdoc.org) version to use? (version = docker image tag) |
48+
| phpdocumentor_version | No | v2.8.5 | What [phpDocumentor](https://www.phpdoc.org) version to use (latest or release tag like `v2.8.5`) |
5949
| output_path | Yes | | Path where to write generated documentation |
6050

51+
## Notes
52+
53+
- Docker build clones `git@github.com:evert/phpdoc-md.git` directly and falls back to HTTPS clone when SSH credentials are not available.
54+
- phpDocumentor release artifacts are downloaded during action runtime and are not stored in this repository.
55+
- 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).
57+
- Tests are JavaScript integration tests based on [testcontainers-node](https://github.com/testcontainers/testcontainers-node).
58+
6159
## How to contribute?
6260

6361
If you want to add some functionality or fix bugs, you can fork, change and create pull request. If you not sure how this works, try [interactive GitHub tutorial](https://skills.github.com).

action.yml

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,27 @@ 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
1216
default: ''
1317
phpdocumentor_version:
14-
description: "What PHP Documentator version to use? (version = docker image tag)"
15-
default: latest
18+
description: "What phpDocumentor version to use? (latest or release tag like v2.8.5)"
19+
default: v2.8.5
1620
required: false
1721
output_path:
1822
description: "Path where to write generated documentation"
1923
required: true
2024

2125
runs:
22-
using: 'composite'
23-
steps:
24-
- name: Setting env variables...
25-
env:
26-
GENERATOR_TMP_FILES_PATH: "${{ runner.temp }}/phpdocs-${{ github.sha }}-${{ github.run_id }}-${{ github.github.run_attempt }}"
27-
GENERATOR_DOCS_PATH: ${{ inputs.output_path }}
28-
run: $ACTION_BIN_PATH/generate-env.sh "$GENERATOR_TMP_FILES_PATH" "$GENERATOR_DOCS_PATH" >> $GITHUB_ENV
29-
shell: bash
30-
31-
- name: Creating required paths...
32-
run: $ACTION_BIN_PATH/create-paths.sh
33-
shell: bash
34-
35-
- name: Running phpDocumentator...
36-
run: $ACTION_BIN_PATH/phpdoc.sh "${{ inputs.ignored_files }}" "${{ inputs.phpdocumentor_version }}"
37-
shell: bash
38-
39-
- name: Installing evert/phpdoc-md...
40-
run: $ACTION_BIN_PATH/add-composer-packages.sh
41-
shell: bash
42-
43-
- name: Generating documentation...
44-
run: $ACTION_BIN_PATH/generate-docs.sh
45-
shell: bash
46-
47-
- name: Uninstalling evert/phpdoc-md...
48-
run: $ACTION_BIN_PATH/remove-composer-dependencies.sh
49-
shell: bash
50-
51-
- name: Deleting tmp data...
52-
run: $ACTION_BIN_PATH/remove-tmp-data.sh
53-
shell: bash
26+
using: 'docker'
27+
image: 'Dockerfile'
28+
args:
29+
- ${{ inputs.php_version }}
30+
- ${{ inputs.output_path }}
31+
- ${{ inputs.ignored_files }}
32+
- ${{ inputs.phpdocumentor_version }}

bin/add-composer-packages.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

bin/create-paths.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

bin/entrypoint.sh

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
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
19+
20+
if [[ -z "$OUTPUT_PATH" ]]; then
21+
echo "Input 'output_path' is required." >&2
22+
exit 1
23+
fi
24+
25+
WORKSPACE_PATH=${GITHUB_WORKSPACE:-/github/workspace}
26+
27+
if [[ ! -d "$WORKSPACE_PATH" ]]; then
28+
echo "Workspace path does not exist: $WORKSPACE_PATH" >&2
29+
exit 1
30+
fi
31+
32+
if [[ "$OUTPUT_PATH" = /* ]]; then
33+
DOCS_PATH=$OUTPUT_PATH
34+
else
35+
DOCS_PATH="$WORKSPACE_PATH/$OUTPUT_PATH"
36+
fi
37+
38+
TMP_ROOT=$(mktemp -d)
39+
PHPDOC_XML_PATH="$TMP_ROOT/phpdoc-xml"
40+
PHPDOC_PHAR_PATH="$TMP_ROOT/phpDocumentor.phar"
41+
PHPDOC_TAR_GZ_PATH="$TMP_ROOT/phpDocumentor.tgz"
42+
PHPDOC_EXTRACT_PATH="$TMP_ROOT/phpDocumentor"
43+
PHPDOC_MD_PATH=/opt/phpdoc-md
44+
PHPDOC_CACHE_PATH=/opt/phpdocumentor-cache
45+
46+
cleanup() {
47+
rm -rf "$TMP_ROOT"
48+
}
49+
trap cleanup EXIT
50+
51+
mkdir -p "$DOCS_PATH"
52+
mkdir -p "$PHPDOC_XML_PATH"
53+
mkdir -p "$PHPDOC_EXTRACT_PATH"
54+
55+
download_file() {
56+
local url=$1
57+
local target=$2
58+
php -r '$url = isset($argv[1]) ? $argv[1] : null; $target = isset($argv[2]) ? $argv[2] : null; if (!$url || !$target) { fwrite(STDERR, "Missing download arguments\n"); exit(1); } $data = @file_get_contents($url); if ($data === false) { exit(1); } if (@file_put_contents($target, $data) === false) { fwrite(STDERR, "Unable to write file: $target\n"); exit(1); }' "$url" "$target"
59+
}
60+
61+
extract_tgz() {
62+
local archive=$1
63+
local target=$2
64+
php -r '$archive = isset($argv[1]) ? $argv[1] : null; $target = isset($argv[2]) ? $argv[2] : null; if (!$archive || !$target) { fwrite(STDERR, "Missing extract arguments\n"); exit(1); } if (!is_dir($target) && !mkdir($target, 0777, true)) { fwrite(STDERR, "Unable to create extract directory\n"); exit(1); } $tarPath = preg_replace("/\\.tgz$/", ".tar", $archive); if ($tarPath === null) { fwrite(STDERR, "Unable to derive tar path\n"); exit(1); } try { $tgz = new PharData($archive); if (!file_exists($tarPath)) { $tgz->decompress(); } $tar = new PharData($tarPath); $tar->extractTo($target, null, true); } catch (Exception $e) { fwrite(STDERR, "Unable to extract phpDocumentor archive: " . $e->getMessage() . "\n"); exit(1); }' "$archive" "$target"
65+
}
66+
67+
PHPDOC_COMMAND=()
68+
PHPDOC_COMMAND_SET=0
69+
if [[ "$PHPDOC_VERSION" == "latest" ]]; then
70+
PHPDOC_PHAR_URL="https://phpdoc.org/phpDocumentor.phar"
71+
download_file "$PHPDOC_PHAR_URL" "$PHPDOC_PHAR_PATH"
72+
PHPDOC_COMMAND=(php "$PHPDOC_PHAR_PATH" run)
73+
PHPDOC_COMMAND_SET=1
74+
else
75+
PHPDOC_VERSION_NO_PREFIX=${PHPDOC_VERSION#v}
76+
CACHED_PHPDOC_TAR_GZ_PATH="$PHPDOC_CACHE_PATH/phpDocumentor-${PHPDOC_VERSION_NO_PREFIX}.tgz"
77+
CACHED_PHPDOC_PHAR_PATH="$PHPDOC_CACHE_PATH/phpDocumentor-${PHPDOC_VERSION_NO_PREFIX}.phar"
78+
PHPDOC_TAR_GZ_URL="https://github.com/phpDocumentor/phpDocumentor/releases/download/v${PHPDOC_VERSION_NO_PREFIX}/phpDocumentor-${PHPDOC_VERSION_NO_PREFIX}.tgz"
79+
PHPDOC_PHAR_URL="https://github.com/phpDocumentor/phpDocumentor/releases/download/v${PHPDOC_VERSION_NO_PREFIX}/phpDocumentor.phar"
80+
81+
if [[ "$PHPDOC_COMMAND_SET" -eq 0 ]] && [[ -f "$CACHED_PHPDOC_TAR_GZ_PATH" ]]; then
82+
cp "$CACHED_PHPDOC_TAR_GZ_PATH" "$PHPDOC_TAR_GZ_PATH"
83+
elif [[ "$PHPDOC_COMMAND_SET" -eq 0 ]] && ! download_file "$PHPDOC_TAR_GZ_URL" "$PHPDOC_TAR_GZ_PATH"; then
84+
download_file "$PHPDOC_PHAR_URL" "$PHPDOC_PHAR_PATH"
85+
PHPDOC_COMMAND=(php "$PHPDOC_PHAR_PATH" run)
86+
PHPDOC_COMMAND_SET=1
87+
fi
88+
89+
if [[ "$PHPDOC_COMMAND_SET" -eq 0 ]]; then
90+
extract_tgz "$PHPDOC_TAR_GZ_PATH" "$PHPDOC_EXTRACT_PATH"
91+
PHPDOC_BIN_PATH="$PHPDOC_EXTRACT_PATH/phpDocumentor-${PHPDOC_VERSION_NO_PREFIX}/bin/phpdoc"
92+
if [[ ! -f "$PHPDOC_BIN_PATH" ]]; then
93+
echo "Unable to find phpDocumentor binary after extraction." >&2
94+
exit 1
95+
fi
96+
PHPDOC_COMMAND=(php "$PHPDOC_BIN_PATH")
97+
PHPDOC_COMMAND_SET=1
98+
fi
99+
fi
100+
101+
declare -a PHPDOC_IGNORE_ARGS
102+
PHPDOC_IGNORE_ARGS+=("--ignore=vendor/**")
103+
while IFS= read -r LINE; do
104+
LINE=${LINE%$'\r'}
105+
if [[ -n "$LINE" ]]; then
106+
PHPDOC_IGNORE_ARGS+=("--ignore=$LINE")
107+
fi
108+
done <<< "$IGNORED_FILES"
109+
110+
"${PHPDOC_COMMAND[@]}" \
111+
--target="$PHPDOC_XML_PATH" \
112+
--directory="$WORKSPACE_PATH" \
113+
--cache-folder="$TMP_ROOT/cache" \
114+
--template=xml \
115+
--no-interaction \
116+
--ansi \
117+
"${PHPDOC_IGNORE_ARGS[@]}"
118+
119+
if [[ ! -f "$PHPDOC_MD_PATH/bin/phpdocmd" ]]; then
120+
echo "phpdoc-md binary is missing: $PHPDOC_MD_PATH/bin/phpdocmd" >&2
121+
exit 1
122+
fi
123+
124+
php "$PHPDOC_MD_PATH/bin/phpdocmd" "$PHPDOC_XML_PATH/structure.xml" "$DOCS_PATH"

bin/generate-docs.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)