From 67f684d48758b23b9ad6a2e7beb71e2ecad952f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Fri, 6 Nov 2026 00:18:30 +0100 Subject: [PATCH 1/3] add "download-bundled" generator --- .../actions/verify-generated-files/action.yml | 1 + .../download-bundled/make-workflow-file.php | 214 ++++++++++++++++++ .github/workflows/verify-bundled-files.yml | 6 +- 3 files changed, 218 insertions(+), 3 deletions(-) create mode 100755 .github/scripts/download-bundled/make-workflow-file.php diff --git a/.github/actions/verify-generated-files/action.yml b/.github/actions/verify-generated-files/action.yml index 79c49dbfcfff..3f3dea73c4dc 100644 --- a/.github/actions/verify-generated-files/action.yml +++ b/.github/actions/verify-generated-files/action.yml @@ -13,4 +13,5 @@ runs: ext/tokenizer/tokenizer_data_gen.php build/gen_stub.php -f --generate-optimizer-info --verify ext/phar/makestub.php + .github/scripts/download-bundled/make-workflow-file.php .github/scripts/test-directory-unchanged.sh . diff --git a/.github/scripts/download-bundled/make-workflow-file.php b/.github/scripts/download-bundled/make-workflow-file.php new file mode 100755 index 000000000000..0268803a91bb --- /dev/null +++ b/.github/scripts/download-bundled/make-workflow-file.php @@ -0,0 +1,214 @@ +#!/usr/bin/env php + $directories + * @param list $files + */ + public function __construct( + public string $name, + public array $directories, + public array $files = [] + ) {} + + public function getNameForPath(): string + { + return preg_replace('~\W+~', '-', strtolower($this->name)); + } +} + +class Generator +{ + /** + * @param list $bundles + */ + public function __construct( + public array $bundles + ) {} + + protected function getRepoDirectory(): string + { + return dirname(__DIR__, 3); + } + + protected function indentString(string $value, int $levels, bool $inclFirstLine): string + { + return preg_replace( + '~' . ($inclFirstLine ? '^|' : '') . '(?<=\n)~', + str_repeat(' ', $levels), + $value + ); + } + + /** + * @param mixed $data + */ + protected function encodeYml($data): string + { + if (is_array($data)) { + $isList = array_is_list($data); + $resParts = []; + foreach ($data as $k => $v) { + $kEncoded = $isList + ? '-' + : $this->encodeYml($k) . ':'; + $vEncoded = $this->encodeYml($v); + + $resParts[] = $kEncoded + . (!$isList && is_array($v) && $v !== [] ? "\n " : ' ') + . (is_array($v) ? $this->indentString($vEncoded, 1, false) : $vEncoded); + } + + return implode("\n", $resParts); + } + + if (preg_match('~^(\w+|\$\{\{[^\}]+\}\})$~', $data)) { + return $data; + } + + return strpos($data, "\n") !== false + ? '|' . "\n" . $this->indentString($data, 1, true) + : '\'' . str_replace('\'', '\'\'', $data) . '\''; + } + + public function makeWorkflowFile(): void + { + $content = <<<'EOD' + name: Verify Bundled Files + + on: + push: + paths: &paths + %paths% + pull_request: + paths: *paths + schedule: + - cron: "0 1 * * *" + workflow_dispatch: ~ + + permissions: + contents: read + + jobs: + VERIFY_BUNDLED_FILES: + if: github.repository == 'php/php-src' || github.event_name == 'workflow_dispatch' + name: Verify Bundled Files + runs-on: ubuntu-24.04 + steps: + - name: git checkout + uses: actions/checkout@v7 + + - name: Detect changed files + if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }} + uses: dorny/paths-filter@v3 + id: changes + with: + filters: %filters% + + %steps% + + EOD; + + $paths = [ + '.github/scripts/download-bundled/**', + ]; + foreach ($this->bundles as $bundle) { + foreach ($this->makeDornyPathsFilterFilters($bundle) as $p) { + if (str_starts_with($p, '.github/scripts/download-bundled/')) { + continue; + } + + $paths[] = $p; + } + } + $content = str_replace('%paths%', $this->indentString($this->encodeYml($paths), 3, false), $content); + + $filters = []; + foreach ($this->bundles as $bundle) { + $filters[$bundle->getNameForPath()] = $this->makeDornyPathsFilterFilters($bundle); + } + $content = str_replace('%filters%', $this->indentString($this->encodeYml($this->encodeYml($filters)), 5, false), $content); + + $steps = []; + foreach ($this->bundles as $bundle) { + $steps[] = [ + 'name' => $bundle->name, + 'if' => '${{ !cancelled() && (steps.changes.outputs.' . $bundle->getNameForPath() . ' == \'true\' || github.event_name == \'schedule\' || github.event_name == \'workflow_dispatch\') }}', + 'run' => implode("\n", [ + 'echo "::group::Download"', + '.github/scripts/download-bundled/' . $bundle->getNameForPath() . '.sh', + 'echo "::endgroup::"', + 'echo "::group::Verify files"', + ...array_map(static fn ($v) => '.github/scripts/test-directory-unchanged.sh \'' . $v . '\'', array_merge($bundle->directories, $bundle->files)), + 'echo "::endgroup::"', + ]), + ]; + } + $content = str_replace('%steps%', $this->indentString($this->encodeYml($steps), 3, false), $content); + + file_put_contents($this->getRepoDirectory() . '/.github/workflows/verify-bundled-files.yml', $content); + } + + protected function makeDornyPathsFilterFilters(Bundle $bundle): array + { + return [ + '.github/scripts/download-bundled/' . $bundle->getNameForPath() . '.*', + ...array_map(static fn ($v) => $v . '/**', $bundle->directories), + ...$bundle->files, + ]; + } + + public function makeDownloadScriptHeaders(): void + { + foreach ($this->bundles as $bundle) { + $this->makeDownloadScriptHeader($bundle); + } + } + + protected function makeDownloadScriptHeader(Bundle $bundle): void + { + $scriptPath = $this->getRepoDirectory() . '/.github/scripts/download-bundled/' . $bundle->getNameForPath() . '.sh'; + + $content = !file_exists($scriptPath) + ? "# TODO\n" + : file_get_contents($scriptPath); + + $header = <<<'EOD' + #!/bin/sh + set -ex + cd "$(dirname "$0")/../../.." + + tmp_dir=%tmp_dir% + rm -rf "$tmp_dir" + + + EOD; + + $header = str_replace('%tmp_dir%', '/tmp/php-src-download-bundled/' . $bundle->getNameForPath(), $header); + + if (!str_starts_with($content, $header)) { + $content = $header . $content; + } + + file_put_contents($scriptPath, $content); + } +} + +$generator = new Generator($bundles); +$generator->makeWorkflowFile(); +$generator->makeDownloadScriptHeaders(); diff --git a/.github/workflows/verify-bundled-files.yml b/.github/workflows/verify-bundled-files.yml index a287e1229305..069ff97fe90c 100644 --- a/.github/workflows/verify-bundled-files.yml +++ b/.github/workflows/verify-bundled-files.yml @@ -60,7 +60,7 @@ jobs: .github/scripts/download-bundled/boost-context.sh echo "::endgroup::" echo "::group::Verify files" - .github/scripts/test-directory-unchanged.sh Zend/asm + .github/scripts/test-directory-unchanged.sh 'Zend/asm' echo "::endgroup::" - name: XSSE if: ${{ !cancelled() && (steps.changes.outputs.xsse == 'true' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') }} @@ -96,7 +96,7 @@ jobs: .github/scripts/download-bundled/pcre2.sh echo "::endgroup::" echo "::group::Verify files" - .github/scripts/test-directory-unchanged.sh ext/pcre/pcre2lib + .github/scripts/test-directory-unchanged.sh 'ext/pcre/pcre2lib' echo "::endgroup::" - name: uriparser if: ${{ !cancelled() && (steps.changes.outputs.uriparser == 'true' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') }} @@ -105,5 +105,5 @@ jobs: .github/scripts/download-bundled/uriparser.sh echo "::endgroup::" echo "::group::Verify files" - .github/scripts/test-directory-unchanged.sh ext/uri/uriparser + .github/scripts/test-directory-unchanged.sh 'ext/uri/uriparser' echo "::endgroup::" From cda670f110766edde599f23b3693b0f4a90b0e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Fri, 6 Nov 2026 00:46:39 +0100 Subject: [PATCH 2/3] add manual --- .../download-bundled/make-workflow-file.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/scripts/download-bundled/make-workflow-file.php b/.github/scripts/download-bundled/make-workflow-file.php index 0268803a91bb..0892f8fb0fc3 100755 --- a/.github/scripts/download-bundled/make-workflow-file.php +++ b/.github/scripts/download-bundled/make-workflow-file.php @@ -5,6 +5,24 @@ namespace Phpsrc\Ci\DownloadBundled; +// How to add a new bundled source? +// 1. add a new entry for the source into $bundles variable below +// 2. run this make-workflow-file.php generator +// 3. edit the generated .github/scripts/download-bundled/.sh file, see and be consistent with other files + +// How to run this make-workflow-file.php generator? +// ``` +// docker run --rm -v "$(git rev-parse --show-toplevel)":/h php:latest /h/.github/scripts/download-bundled/make-workflow-file.php +// ``` + +// How to update/download specific bundled source? +// 1. edit the bundled version inside relevant .github/scripts/download-bundled/.sh file +// 2. run: +// ``` +// docker run --rm -v "$(git rev-parse --show-toplevel)":/f alpine:latest sh -c "apk add git && /f/.github/scripts/download-bundled/.sh" +// ``` +// 3. review git changes and commit the changes + $bundles = [ new Bundle('boost.context', ['Zend/asm']), new Bundle('XSSE', [], ['Zend/zend_simd.h']), From c5d6bec7a367d49ec664cb727f3b86188f6cf31b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Fri, 6 Nov 2026 01:31:11 +0100 Subject: [PATCH 3/3] verify "ext/lexbor" bundle using CI --- .github/scripts/download-bundled/lexbor.sh | 8 ++++++++ .../download-bundled/make-workflow-file.php | 1 + .github/workflows/verify-bundled-files.yml | 16 ++++++++++++++++ ext/lexbor/patches/update-lexbor.sh | 4 ++-- 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100755 .github/scripts/download-bundled/lexbor.sh diff --git a/.github/scripts/download-bundled/lexbor.sh b/.github/scripts/download-bundled/lexbor.sh new file mode 100755 index 000000000000..d70131504c6c --- /dev/null +++ b/.github/scripts/download-bundled/lexbor.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -ex +cd "$(dirname "$0")/../../.." + +tmp_dir=/tmp/php-src-download-bundled/lexbor +rm -rf "$tmp_dir" + +ext/lexbor/patches/update-lexbor.sh diff --git a/.github/scripts/download-bundled/make-workflow-file.php b/.github/scripts/download-bundled/make-workflow-file.php index 0892f8fb0fc3..ecfc93c62c3a 100755 --- a/.github/scripts/download-bundled/make-workflow-file.php +++ b/.github/scripts/download-bundled/make-workflow-file.php @@ -28,6 +28,7 @@ new Bundle('XSSE', [], ['Zend/zend_simd.h']), new Bundle('JIT IR', ['ext/opcache/jit/ir']), new Bundle('xxHash', ['ext/hash/xxhash']), + new Bundle('lexbor', ['ext/lexbor/lexbor', 'ext/lexbor/patches']), new Bundle('PCRE2', ['ext/pcre/pcre2lib']), new Bundle('uriparser', ['ext/uri/uriparser']), ]; diff --git a/.github/workflows/verify-bundled-files.yml b/.github/workflows/verify-bundled-files.yml index 069ff97fe90c..cfcdd52eb4f0 100644 --- a/.github/workflows/verify-bundled-files.yml +++ b/.github/workflows/verify-bundled-files.yml @@ -8,6 +8,8 @@ on: - 'Zend/zend_simd.h' - 'ext/opcache/jit/ir/**' - 'ext/hash/xxhash/**' + - 'ext/lexbor/lexbor/**' + - 'ext/lexbor/patches/**' - 'ext/pcre/pcre2lib/**' - 'ext/uri/uriparser/**' pull_request: @@ -46,6 +48,10 @@ jobs: xxhash: - '.github/scripts/download-bundled/xxhash.*' - 'ext/hash/xxhash/**' + lexbor: + - '.github/scripts/download-bundled/lexbor.*' + - 'ext/lexbor/lexbor/**' + - 'ext/lexbor/patches/**' pcre2: - '.github/scripts/download-bundled/pcre2.*' - 'ext/pcre/pcre2lib/**' @@ -89,6 +95,16 @@ jobs: echo "::group::Verify files" .github/scripts/test-directory-unchanged.sh 'ext/hash/xxhash' echo "::endgroup::" + - name: lexbor + if: ${{ !cancelled() && (steps.changes.outputs.lexbor == 'true' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') }} + run: | + echo "::group::Download" + .github/scripts/download-bundled/lexbor.sh + echo "::endgroup::" + echo "::group::Verify files" + .github/scripts/test-directory-unchanged.sh 'ext/lexbor/lexbor' + .github/scripts/test-directory-unchanged.sh 'ext/lexbor/patches' + echo "::endgroup::" - name: PCRE2 if: ${{ !cancelled() && (steps.changes.outputs.pcre2 == 'true' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') }} run: | diff --git a/ext/lexbor/patches/update-lexbor.sh b/ext/lexbor/patches/update-lexbor.sh index 92ef8aa58f66..5647d6bd4fef 100755 --- a/ext/lexbor/patches/update-lexbor.sh +++ b/ext/lexbor/patches/update-lexbor.sh @@ -21,9 +21,9 @@ for f in "$PATCHES_DIR"/*.patch; do done cd "$LEXBOR_TMP_DIR" for patch in "${patches[@]}"; do - if ! git am -3 "$patch"; then + if ! git -c user.name=x -c user.email=x am -3 "$patch"; then read -p "Patch $(basename "$patch") did not apply cleanly. Resolve, stage and press Enter to continue. " - git am --continue + git -c user.name=x -c user.email=x am --continue fi done