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
11 changes: 9 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
- name: Build Dockerfile
run: docker build .

- name: Verify nginx redirects
run: docker run --rm -v "$PWD:/app:ro" -w /app nginx:alpine sh tests/nginx.sh

cs-stan:
name: Coding Standard
runs-on: ubuntu-latest
Expand Down Expand Up @@ -50,8 +53,12 @@ jobs:
- name: Composer install
run: composer install

- name: Run loader regression checks
run: php tests/loader.php
- name: Run regression checks
run: |
php tests/loader.php
php tests/generator.php
php tests/releases.php
sh tests/build-release.sh

- name: Run PHP CodeSniffer
run: vendor/bin/phpcs -q --report=checkstyle src/ | cs2pr
39 changes: 17 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Build api docs with php 8.1 requirements
# syntax=docker/dockerfile:1
# Build API docs with PHP 8.2
FROM alpine:3.19 AS builder

RUN apk add --no-cache \
Expand All @@ -7,7 +8,7 @@ RUN apk add --no-cache \
git \
make \
openssh-client \
php81 \
php82 \
php82-bz2 \
php82-curl \
php82-dom \
Expand All @@ -24,29 +25,23 @@ RUN apk add --no-cache \

RUN ln -sf /usr/bin/php82 /usr/bin/php

RUN mkdir /root/.ssh \
&& ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts

WORKDIR /data
COPY . /data

RUN git clone https://github.com/cakephp/cakephp.git /cakephp \
&& git clone https://github.com/cakephp/authentication.git /authentication \
&& git clone https://github.com/cakephp/authorization.git /authorization \
&& git clone https://github.com/cakephp/chronos.git /chronos \
&& git clone https://github.com/cakephp/elastic-search.git /elastic \
&& git clone https://github.com/cakephp/queue.git /queue
# Install generator dependencies independently of source, template and asset edits.
COPY composer.json composer.lock ./
RUN --mount=type=cache,target=/root/.composer/cache \
curl -sS https://getcomposer.org/installer | php \
&& php composer.phar install --no-interaction --prefer-dist

COPY . /data

RUN ls -lah \
&& make build-cakephp3-all CAKEPHP_SOURCE_DIR=/cakephp \
&& make build-cakephp4-all CAKEPHP_SOURCE_DIR=/cakephp \
&& make build-cakephp5-all CAKEPHP_SOURCE_DIR=/cakephp \
&& make build-cakephp6-all CAKEPHP_SOURCE_DIR=/cakephp \
&& make build-authentication-all AUTHENTICATION_SOURCE_DIR=/authentication \
&& make build-authorization-all AUTHORIZATION_SOURCE_DIR=/authorization \
&& make build-chronos-all CHRONOS_SOURCE_DIR=/chronos \
&& make build-elastic-all ELASTIC_SOURCE_DIR=/elastic \
&& make build-queue-all QUEUE_SOURCE_DIR=/queue
# Change DOCS_CACHE_REFRESH to re-resolve dependencies even for unchanged source refs.
ARG DOCS_CACHE_REFRESH=
ENV DOCS_CACHE_DIR=/cache/docs
RUN --mount=type=cache,target=/sources,sharing=locked \
--mount=type=cache,target=/cache/docs,sharing=locked \
--mount=type=cache,target=/root/.composer/cache,sharing=locked \
DOCS_CACHE_REFRESH="$DOCS_CACHE_REFRESH" sh bin/build-all.sh

# nginx server
FROM alpine:3.19
Expand Down
94 changes: 32 additions & 62 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,65 +9,36 @@ BUILD_DIR ?= ./build/api
DEPLOY_DIR ?= ./website

PHP ?= php
DOCS_CACHE_DIR ?=
export DOCS_CACHE_REFRESH
COMPOSER := $(CURDIR)/composer.phar
COMPOSER_UPDATE_FLAGS := --no-plugins --no-audit --no-security-blocking --ignore-platform-reqs

.DEFAULT_GOAL := help

CAKEPHP3_RELEASES := \
3.0|3.0.19|no-vendor \
3.1|3.1.14|no-vendor \
3.2|3.2.14|update \
3.3|3.3.16|update \
3.4|3.4.14|update \
3.5|3.5.18|update \
3.6|3.6.15|update \
3.7|3.7.9|update \
3.8|3.8.13|update \
3.9|3.9.10|update \
3.10|origin/3.x|update

CAKEPHP4_RELEASES := \
4.0|4.0.9|update \
4.1|4.1.7|update \
4.2|4.2.10|update \
4.3|4.3.10|update \
4.4|4.4.18|update \
4.5|4.5.10|update \
4.6|origin/4.x|update

CAKEPHP5_RELEASES := \
5.0|5.0.11|update \
5.1|5.1.9|update \
5.2|5.2.15|update \
5.3|5.3.7|update \
5.4|origin/5.x|update

CAKEPHP6_RELEASES := \
6.0|origin/6.x|update

CHRONOS_RELEASES := \
1.x|origin/1.x|update \
2.x|origin/2.x|update \
3.x|origin/3.x|update

ELASTIC_RELEASES := \
2.x|origin/2.x|update \
3.x|origin/3.x|update \
4.x|origin/4.x|update

QUEUE_RELEASES := \
1.x|origin/1.x|update \
2.x|origin/2.x|update

AUTHENTICATION_RELEASES := \
2.x|origin/2.x|update \
3.x|origin/3.x|update \
4.x|origin/4.x|update

AUTHORIZATION_RELEASES := \
2.x|origin/2.x|update \
3.x|origin/3.x|update
CAKEPHP3_RELEASES := $(shell $(PHP) bin/releases.php cakephp3)

CAKEPHP4_RELEASES := $(shell $(PHP) bin/releases.php cakephp4)

CAKEPHP5_RELEASES := $(shell $(PHP) bin/releases.php cakephp5)

CAKEPHP6_RELEASES := $(shell $(PHP) bin/releases.php cakephp6)

CHRONOS_RELEASES := $(shell $(PHP) bin/releases.php chronos)

ELASTIC_RELEASES := $(shell $(PHP) bin/releases.php elastic)

QUEUE_RELEASES := $(shell $(PHP) bin/releases.php queue)

AUTHENTICATION_RELEASES := $(shell $(PHP) bin/releases.php authentication)

AUTHORIZATION_RELEASES := $(shell $(PHP) bin/releases.php authorization)

RELEASE_GROUPS := CAKEPHP3 CAKEPHP4 CAKEPHP5 CAKEPHP6 CHRONOS ELASTIC QUEUE AUTHENTICATION AUTHORIZATION
$(foreach group,$(RELEASE_GROUPS),$(if $($(group)_RELEASES),,$(error Unable to load $(group) releases; check PHP and config/releases.php)))

# Releases share source checkouts; concurrent builds would race on git checkout.
.NOTPARALLEL:

release_version = $(word 1,$(subst |, ,$1))
release_tag = $(word 2,$(subst |, ,$1))
Expand Down Expand Up @@ -134,6 +105,8 @@ help:
@echo " AUTHENTICATION_SOURCE_DIR Location of the authentication clone."
@echo " AUTHORIZATION_SOURCE_DIR Location of the authorization clone."
@echo " BUILD_DIR Output directory. Default: $(BUILD_DIR)"
@echo " DOCS_CACHE_DIR Optional cache directory for completed release builds."
@echo " DOCS_CACHE_REFRESH Change this value to refresh cached dependency resolution."
@echo " DEPLOY_DIR Deployment directory. Default: $(DEPLOY_DIR)"
@echo ""
@echo "NOTE: Source directories will have their checkout branch changed."
Expand All @@ -158,18 +131,15 @@ deploy: $(DEPLOY_DIR)
composer.phar:
curl -sS https://getcomposer.org/installer | php

install: composer.phar
install: vendor/autoload.php

vendor/autoload.php: composer.json composer.lock composer.phar
$(PHP) $(COMPOSER) install

define build_docs
build-$(1)-$(5): install
cd $($(2)) && git checkout -f $(6)
$(if $(filter no-vendor,$(7)),cd $($(2)) && rm -rf ./vendor,cd $($(2)) && $(PHP) $(COMPOSER) update $(COMPOSER_UPDATE_FLAGS))
mkdir -p $(BUILD_DIR)/$(3)/$(5)
cp -r static/assets/* $(BUILD_DIR)/$(3)/$(5)

$(PHP) bin/apitool.php generate --config $(4) --version $(5) --tag $(6) \
--output-dir $(BUILD_DIR)/$(3)/$(5) $($(2))
sh bin/build-release.sh "$(PHP)" "$(COMPOSER)" "$($(2))" "$(BUILD_DIR)/$(3)/$(5)" \
"$(4)" "$(5)" "$(6)" "$(7)" "$(COMPOSER_UPDATE_FLAGS)" "$(DOCS_CACHE_DIR)"
endef

build-cakephp3-all: $(foreach version,$(CAKEPHP3_VERSIONS),build-cakephp-$(version))
Expand Down
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,57 @@ mkdir -p build/api/cakephp/6.0
cp -r static/assets/* build/api/cakephp/6.0/
php bin/apitool.php generate --config cakephp6 --version 6.0 --tag origin/6.x --output-dir build/api/cakephp/6.0/ ../cakephp
```

### Release definitions and cached builds

`config/releases.php` defines the versions, Git refs and dependency modes used by
Make targets. All CakePHP configurations derive their version selector from this
manifest; legacy 1.x and 2.x links are retained in `config/cakephp-versions.php`.
PHP is required when reading the Makefile, including for `make help`.

Docker uses BuildKit caches for source clones, Composer downloads and completed
release documentation. Generator dependencies are installed before application
sources are copied, so template edits reuse the Composer layer. Rendered releases
are keyed by the source commit, generator code, templates, assets, configuration,
Composer lock file, PHP major/minor version and dependency update flags. Only
successful builds are cached, and a complete output directory replaces the old one.

Local Make builds can opt into the same release cache:

```sh
make build-cakephp-6.0 DOCS_CACHE_DIR="$HOME/.cache/cakephp-api-docs"
```

Cached documentation retains its resolved source dependencies. To re-resolve them
without changing the source ref, set a new refresh value:

```sh
make build-cakephp-6.0 DOCS_CACHE_DIR="$HOME/.cache/cakephp-api-docs" DOCS_CACHE_REFRESH=2026-11-29
# Also invalidates Docker's build step so remote refs are fetched again:
docker build --build-arg DOCS_CACHE_REFRESH=2026-11-29 .
```

BuildKit caches are local to the builder. A fresh CI runner performs a full build
unless its builder cache is persisted. Changing templates or shared version links
correctly regenerates all affected release pages. README and test edits do not
change the rendered-release cache keys.

### Public URL routing

The `site-api` proxy forwards public `/6.0/...` requests to this image's internal
`/cakephp/6.0/...` path. Missing HTML pages redirect to the public `/6.0/` overview,
with a relative Location header so the internal prefix and upstream host do not
leak into public URLs. Missing assets retain a 404 response.

### Regression checks

After installing Composer dependencies:

```sh
php tests/loader.php
php tests/generator.php
php tests/releases.php
sh tests/build-release.sh
# Runs nginx and HTTP requests inside a disposable container:
docker run --rm -v "$PWD:/app:ro" -w /app nginx:alpine sh tests/nginx.sh
```
24 changes: 24 additions & 0 deletions bin/build-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
set -eu

# Source and rendered-documentation directories are Docker BuildKit cache mounts.
for project in cakephp authentication authorization chronos elastic-search queue; do
source_dir="/sources/$project"
if [ ! -d "$source_dir/.git" ]; then
git clone "https://github.com/cakephp/$project.git" "$source_dir"
else
git -C "$source_dir" fetch --prune --tags origin
fi
case "$project" in
cakephp)
for major in 3 4 5 6; do
make "build-cakephp$major-all" CAKEPHP_SOURCE_DIR="$source_dir"
done
;;
elastic-search) make build-elastic-all ELASTIC_SOURCE_DIR="$source_dir" ;;
*)
variable=$(printf '%s_SOURCE_DIR' "$project" | tr '[:lower:]' '[:upper:]')
make "build-$project-all" "$variable=$source_dir"
;;
esac
done
57 changes: 57 additions & 0 deletions bin/build-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/sh
set -eu

php=$1
composer=$2
source_dir=$(cd "$3" && pwd -P)
output=$4
config=$5
version=$6
tag=$7
mode=$8
update_flags=$9
cache_dir=${10}

commit=$(git -C "$source_dir" rev-parse "$tag^{commit}")
cache_entry=
if [ -n "$cache_dir" ]; then
mkdir -p "$cache_dir"
cache_dir=$(cd "$cache_dir" && pwd -P)
fingerprint=$("$php" bin/cache-key.php "$commit" "$config" "$version" "$mode" "$update_flags" "${DOCS_CACHE_REFRESH:-}")
cache_entry="$cache_dir/$config-$version-$fingerprint"
fi

mkdir -p "$(dirname "$output")"
stage=$(mktemp -d "$(dirname "$output")/.docs-XXXXXX")
trap 'rm -rf "$stage"' EXIT HUP INT TERM

if [ -n "$cache_entry" ] && [ -f "$cache_entry/.complete" ]; then
echo "Using cached documentation for $config $version ($commit)"
cp -a "$cache_entry/." "$stage/"
rm "$stage/.complete"
else
git -C "$source_dir" checkout -f "$tag"
if [ "$mode" = no-vendor ]; then
rm -rf "$source_dir/vendor"
else
# Flags are deliberately split into individual Composer arguments.
# shellcheck disable=SC2086
(cd "$source_dir" && "$php" "$composer" update $update_flags)
fi
cp -R static/assets/. "$stage/"
"$php" bin/apitool.php generate --config "$config" --version "$version" --tag "$tag" \
--output-dir "$stage" "$source_dir"
if [ -n "$cache_entry" ]; then
cache_stage=$(mktemp -d "$cache_dir/.docs-XXXXXX")
cp -a "$stage/." "$cache_stage/"
touch "$cache_stage/.complete"
rm -rf "$cache_entry"
mv "$cache_stage" "$cache_entry"
fi
fi

# Publish only after every page has been generated successfully.
# mktemp creates a private directory; nginx workers must be able to traverse it.
chmod 755 "$stage"
rm -rf "$output"
mv "$stage" "$output"
27 changes: 27 additions & 0 deletions bin/cache-key.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);

// Standalone: cache lookup must work before loading the generator's dependencies.
$files = ['composer.json', 'composer.lock'];
foreach (['src', 'templates', 'static', 'config', 'bin'] as $directory) {
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS)
);
foreach ($iterator as $file) {
if ($file->isFile()) {
$files[] = $file->getPathname();
}
}
}
sort($files, SORT_STRING);
$hash = hash_init('sha256');
foreach ($files as $file) {
$digest = hash_file('sha256', $file);
if ($digest === false) {
throw new RuntimeException(sprintf('Unable to fingerprint `%s`.', $file));
}
hash_update($hash, $file . "\0" . $digest . "\0");
}
hash_update($hash, json_encode(array_slice($argv, 1), JSON_THROW_ON_ERROR));
hash_update($hash, PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION);
echo hash_final($hash), "\n";
13 changes: 13 additions & 0 deletions bin/releases.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);

$releases = require dirname(__DIR__) . '/config/releases.php';
$group = $argv[1] ?? '';
if (!isset($releases[$group])) {
fwrite(STDERR, sprintf("Unknown release group `%s`.\n", $group));
exit(1);
}
foreach ($releases[$group] as $release) {
echo implode('|', [$release['version'], $release['tag'], $release['mode']]), ' ';
}
echo "\n";
Loading
Loading