Skip to content

Commit 09b2aa1

Browse files
authored
Add zero-to-prod-data-model-helper, PHP 8.5 support, and xdebug configuration (#31)
1 parent 3117b3c commit 09b2aa1

File tree

12 files changed

+264
-19
lines changed

12 files changed

+264
-19
lines changed

.github/workflows/backwards_compatibility.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
continue-on-error: ${{ github.event.pull_request.base.ref != 'main' }}
1111
steps:
12-
- uses: actions/checkout@v4
12+
- uses: actions/checkout@v5
1313
with:
1414
fetch-depth: 0
1515
- name: Set safe directory

.github/workflows/composer_require_checker.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111

1212
strategy:
1313
matrix:
14-
php-version: [ "8.4", "8.3", "8.2", "8.1" ]
14+
php-version: [ "8.5", "8.4", "8.3", "8.2", "8.1" ]
1515

1616
steps:
17-
- uses: actions/checkout@v4
17+
- uses: actions/checkout@v5
1818
with:
1919
fetch-depth: 0
2020
- name: Set safe directory

.github/workflows/docblock_update.yml

Lines changed: 157 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,176 @@ jobs:
1414
- name: Checkout code
1515
uses: actions/checkout@v5
1616
with:
17-
token: ${{ secrets.GITHUB_TOKEN }}
17+
token: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
1818
ref: ${{ github.head_ref || github.ref }}
1919
fetch-depth: 0
2020

2121
- name: Update docblocks
2222
run: |
23-
set -e
24-
SOURCE_URL=$(jq -r '.support.source' composer.json)
25-
if [ ! -d ./src ]; then
26-
echo "Source directory ./src does not exist!"
27-
exit 1
28-
fi
29-
docker run --rm -v "$PWD/src:/app/run" davidsmith3/docblock-annotator-cli \
30-
docblock-annotator-cli:update-directory /app/run "@link $SOURCE_URL"
23+
set -euo pipefail
24+
25+
# Constants
26+
readonly COMPOSER_JSON="composer.json"
27+
readonly DOCBLOCK_DOCKER_IMAGE="davidsmith3/docblock-annotator-cli"
28+
readonly DOCBLOCK_COMMAND="docblock-annotator-cli:update-file"
29+
30+
# Execute docblock annotator via Docker for a specific file
31+
execute_docblock_annotator() {
32+
local file_path="$1"
33+
shift
34+
35+
docker run \
36+
--rm \
37+
--volume "$(pwd):/app/run" \
38+
"${DOCBLOCK_DOCKER_IMAGE}" \
39+
"${DOCBLOCK_COMMAND}" \
40+
"/app/run/${file_path}" \
41+
"$@"
42+
}
43+
44+
# Validate required dependencies are available
45+
validate_dependencies() {
46+
if ! command -v jq &> /dev/null; then
47+
echo "Error: jq is required but not installed." >&2
48+
return 1
49+
fi
50+
51+
if [[ ! -f "${COMPOSER_JSON}" ]]; then
52+
echo "Error: ${COMPOSER_JSON} not found in current directory." >&2
53+
return 1
54+
fi
55+
}
56+
57+
# Extract the main PHP class file path from composer.json PSR-4 autoload configuration
58+
get_main_class_file() {
59+
local namespace directory class_name php_file
60+
61+
namespace=$(jq -r '.autoload."psr-4" | keys[0] // empty' "${COMPOSER_JSON}")
62+
directory=$(jq -r --arg ns "$namespace" '.autoload."psr-4"[$ns] // empty' "${COMPOSER_JSON}")
63+
64+
if [[ -z "$namespace" || -z "$directory" ]]; then
65+
echo "Error: Could not extract PSR-4 namespace or directory from ${COMPOSER_JSON}." >&2
66+
return 1
67+
fi
68+
69+
# Remove trailing backslash from namespace
70+
namespace="${namespace%\\}"
71+
72+
# Extract class name from namespace (last segment)
73+
class_name=$(echo "$namespace" | awk -F'\\\\' '{print $NF}')
74+
75+
# Construct PHP file path
76+
php_file="${directory}${class_name}.php"
77+
78+
# Convert backslashes to forward slashes for file path
79+
php_file=$(echo "$php_file" | sed 's/\\/\//g')
80+
81+
if [[ ! -f "$php_file" ]]; then
82+
echo "Warning: Main class file '$php_file' not found. Trying to find an alternative..." >&2
83+
84+
# Try to find the first PHP class file in the directory
85+
local alternative_file
86+
alternative_file=$(find "$directory" -maxdepth 1 -name "*.php" -type f | head -1)
87+
88+
if [[ -n "$alternative_file" ]]; then
89+
echo "Using alternative file: $alternative_file" >&2
90+
echo "$alternative_file"
91+
return 0
92+
else
93+
echo "Error: No PHP class files found in directory '$directory'." >&2
94+
return 1
95+
fi
96+
fi
97+
98+
echo "$php_file"
99+
}
100+
101+
# Extract package description from composer.json
102+
get_package_description() {
103+
local description
104+
description=$(jq -r '.description // empty' "${COMPOSER_JSON}")
105+
106+
if [[ -z "$description" ]]; then
107+
echo "Error: Could not extract package description from ${COMPOSER_JSON}." >&2
108+
return 1
109+
fi
110+
111+
echo "$description"
112+
}
113+
114+
# Extract package homepage from composer.json
115+
get_package_homepage() {
116+
local homepage
117+
homepage=$(jq -r '.homepage // empty' "${COMPOSER_JSON}")
118+
119+
if [[ -z "$homepage" ]]; then
120+
echo "Error: Could not extract package homepage from ${COMPOSER_JSON}." >&2
121+
return 1
122+
fi
123+
124+
echo "$homepage"
125+
}
126+
127+
# Update docblock with package description
128+
update_docblock_with_description() {
129+
local php_file description
130+
131+
php_file=$(get_main_class_file) || return 1
132+
description=$(get_package_description) || return 1
133+
134+
execute_docblock_annotator "$php_file" "$description" "--statements=class"
135+
}
136+
137+
# Update docblock with homepage link
138+
update_docblock_with_link() {
139+
local php_file homepage
140+
141+
php_file=$(get_main_class_file) || return 1
142+
homepage=$(get_package_homepage) || return 1
143+
144+
execute_docblock_annotator "$php_file" "@link $homepage"
145+
}
146+
147+
# Main function to update all docblocks
148+
update_package_docblocks() {
149+
validate_dependencies || return 1
150+
151+
echo "Updating docblocks with package description..."
152+
update_docblock_with_description || return 1
153+
154+
echo "Updating docblocks with homepage link..."
155+
update_docblock_with_link || return 1
156+
157+
echo "Docblock updates completed successfully."
158+
}
159+
160+
# Execute the main function
161+
update_package_docblocks
31162
32163
- name: Commit and push changes (if any)
33164
run: |
34-
set -e
165+
set -euo pipefail
166+
167+
# Configure git user for commits
35168
git config --local user.email "action@github.com"
36169
git config --local user.name "GitHub Action"
170+
171+
# Stage all changes
37172
git add -A
173+
174+
# Check if there are any changes to commit
38175
if ! git diff --cached --quiet; then
39-
git commit -m "Update docblocks with @link annotations" --no-verify
176+
echo "Changes detected, committing docblock updates..."
177+
178+
# Commit without skip-ci to allow other workflows to run
179+
git commit -m "Update docblocks with @link annotations" \
180+
--no-verify
181+
182+
# Push changes - using PAT_TOKEN if available to trigger workflows properly
40183
git push
184+
185+
echo "Docblock updates committed and pushed successfully."
186+
echo "Other workflows will run on the new commit."
41187
else
42188
echo "No changes to commit."
43189
fi

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
release:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v4
15+
- uses: actions/checkout@v5
1616
with:
1717
fetch-depth: 0
1818

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
php-version: ["8.4", "8.3", "8.2", "8.1"]
15+
php-version: [ "8.5", "8.4", "8.3", "8.2", "8.1"]
1616

1717
steps:
18-
- uses: actions/checkout@v4
18+
- uses: actions/checkout@v5
1919

2020
- name: Create .env
2121
run: touch .env

bin/zero-to-prod-data-model-helper

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/**
5+
* Zero-to-Prod Data Model Helper Documentation Publisher
6+
*
7+
* Publishes the README.md file to the user's documentation directory.
8+
*/
9+
10+
require getcwd().'/vendor/autoload.php';
11+
12+
use Zerotoprod\PackageHelper\PackageHelper;
13+
14+
$target_path = getcwd().'/docs/zero-to-prod/data-model-helper/';
15+
if (isset($argv[1])) {
16+
$target_path = rtrim($argv[1], '/').'/';
17+
}
18+
19+
$source_file = __DIR__.'/../README.md';
20+
21+
if (!file_exists($source_file)) {
22+
fwrite(STDERR, "Error: Not found $source_file\n");
23+
exit(1);
24+
}
25+
26+
try {
27+
PackageHelper::copy($source_file, $target_path);
28+
exit(0);
29+
} catch (RuntimeException $e) {
30+
fwrite(STDERR, "Error: ".$e->getMessage()."\n");
31+
exit(1);
32+
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"phpunit/phpunit": "<12.0"
5252
},
5353
"bin": [
54-
"bin/zero-to-prod-data-model-factory"
54+
"bin/zero-to-prod-data-model-factory",
55+
"bin/zero-to-prod-data-model-helper"
5556
],
5657
"suggest": {
5758
"zero-to-prod/transformable": "Transform a class into different types.",

docker-compose.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,32 @@ services:
104104
volumes:
105105
- ./:/app:delegated
106106
- ./.vendor/php8.4:/app/vendor
107+
build:
108+
target: composer
109+
110+
php8.5:
111+
volumes:
112+
- ./:/app:delegated
113+
- ./.vendor/php8.5:/app/vendor
114+
build:
115+
context: ./docker/8.5
116+
target: base
117+
118+
debug8.5:
119+
extends:
120+
service: php8.5
121+
volumes:
122+
- ./:/app:delegated
123+
- ./docker/8.5:/usr/local/etc/php
124+
- ./.vendor/php8.5:/app/vendor
125+
build:
126+
target: debug
127+
128+
composer8.5:
129+
extends:
130+
service: php8.5
131+
volumes:
132+
- ./:/app:delegated
133+
- ./.vendor/php8.5:/app/vendor
107134
build:
108135
target: composer

docker/8.5/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.phpunit.result.cache

docker/8.5/Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM php:8.5-rc-alpine AS builder
2+
3+
RUN apk add --no-cache \
4+
git \
5+
unzip \
6+
$PHPIZE_DEPS
7+
8+
RUN git config --global --add safe.directory /app
9+
10+
WORKDIR /app
11+
12+
FROM builder AS composer
13+
14+
RUN curl -sS https://getcomposer.org/installer | php -- \
15+
--install-dir=/usr/local/bin \
16+
--filename=composer
17+
18+
FROM builder AS debug
19+
20+
RUN apk add --no-cache --virtual .build-deps \
21+
$PHPIZE_DEPS \
22+
linux-headers \
23+
&& pecl channel-update pecl.php.net \
24+
&& pecl install xdebug \
25+
&& docker-php-ext-enable xdebug \
26+
&& apk del .build-deps \
27+
&& rm -rf /tmp/* /var/cache/apk/*
28+
29+
FROM php:8.5-rc-alpine AS base
30+
31+
WORKDIR /app
32+
33+
CMD ["bash"]

0 commit comments

Comments
 (0)