-
Notifications
You must be signed in to change notification settings - Fork 8k
Verify bundled sources using CI - boost.context & uriparser #20438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mvorisek
wants to merge
11
commits into
php:master
Choose a base branch
from
mvorisek:verify_bundled_boost_context
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
990a848
add workflow & skeleton generator
mvorisek 594d236
add download for boost.context
mvorisek 9579b4f
unify/generate tmp_dir
mvorisek ce8632b
add uriparser ci
mvorisek a0d6b68
rm original/duplicate src/UriConfig.h.in
mvorisek 7b17461
fix outdated config/comment
mvorisek 9e24050
patch config to minimize changes between the official config
mvorisek 285de52
"base" param for dorny/paths-filter is not used for PR
mvorisek 5d7c21f
do not use "escapeshellarg" function as it generates different result…
mvorisek 8fa12a3
always use topmost/repo's .git as "--git-dir"
mvorisek e065fc1
run "Detect changed files" step only for push/PR events
mvorisek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| !*.patch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #!/bin/sh | ||
| set -ex | ||
| cd "$(dirname "$0")/../../.." | ||
|
|
||
| tmp_dir=/tmp/php-src-download-bundled/boost-context | ||
| rm -rf "$tmp_dir" | ||
|
|
||
| revision=refs/tags/boost-1.86.0 | ||
|
|
||
| git clone --depth 1 --revision="$revision" https://github.com/boostorg/context.git "$tmp_dir" | ||
|
|
||
| rm -rf Zend/asm | ||
| cp -R "$tmp_dir"/src/asm Zend/asm | ||
|
|
||
| cd Zend/asm | ||
|
|
||
| # remove unneeded files | ||
| rm jump_arm_aapcs_pe_armasm.asm | ||
| rm jump_i386_ms_pe_clang_gas.S | ||
| rm jump_i386_ms_pe_gas.asm | ||
| rm jump_i386_x86_64_sysv_macho_gas.S | ||
| rm jump_ppc32_ppc64_sysv_macho_gas.S | ||
| rm jump_x86_64_ms_pe_clang_gas.S | ||
| rm make_arm_aapcs_pe_armasm.asm | ||
| rm make_i386_ms_pe_clang_gas.S | ||
| rm make_i386_ms_pe_gas.asm | ||
| rm make_i386_x86_64_sysv_macho_gas.S | ||
| rm make_ppc32_ppc64_sysv_macho_gas.S | ||
| rm make_x86_64_ms_pe_clang_gas.S | ||
| rm ontop_*.S | ||
| rm ontop_*.asm | ||
| rm tail_ontop_ppc32_sysv.cpp | ||
|
|
||
| # move renamed files | ||
| # GH-13896 introduced these 2 files named as .S but since https://github.com/boostorg/context/pull/265 they are named as .asm | ||
| mv jump_x86_64_ms_pe_gas.asm jump_x86_64_ms_pe_gas.S | ||
| mv make_x86_64_ms_pe_gas.asm make_x86_64_ms_pe_gas.S | ||
|
|
||
| # add extra files | ||
| git restore LICENSE | ||
| git restore save_xmm_x86_64_ms_masm.asm # added in GH-18352, not an upstream boost.context file |
207 changes: 207 additions & 0 deletions
207
.github/scripts/download-bundled/make-workflow-file.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| #!/usr/bin/env php | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Phpsrc\Ci\DownloadBundled; | ||
|
|
||
| $bundles = [ | ||
| new Bundle('boost.context', ['Zend/asm']), | ||
| new Bundle('PCRE2', ['ext/pcre/pcre2lib']), | ||
| new Bundle('uriparser', ['ext/uri/uriparser']), | ||
| ]; | ||
|
|
||
| class Bundle | ||
| { | ||
| /** | ||
| * @param list<string> $directories | ||
| */ | ||
| public function __construct( | ||
| public string $name, | ||
| public array $directories | ||
| ) {} | ||
|
|
||
| public function getNameForPath(): string | ||
| { | ||
| return preg_replace('~\W+~', '-', strtolower($this->name)); | ||
| } | ||
| } | ||
|
|
||
| class Generator | ||
| { | ||
| /** | ||
| * @param list<Bundle> $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: | ||
| name: Verify Bundled Files | ||
| runs-on: ubuntu-24.04 | ||
| steps: | ||
| - name: git checkout | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - 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 . '\'', $bundle->directories), | ||
| '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), | ||
| ]; | ||
| } | ||
|
|
||
| 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(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| diff --git a/ext/uri/uriparser/src/UriConfig.h b/ext/uri/uriparser/src/UriConfig.h | ||
| index b9a85a8..ab78b96 100644 | ||
| --- a/ext/uri/uriparser/src/UriConfig.h | ||
| +++ b/ext/uri/uriparser/src/UriConfig.h | ||
| @@ -41,7 +41,9 @@ | ||
|
|
||
| # define PACKAGE_VERSION "@PROJECT_VERSION@" | ||
|
|
||
| +/* | ||
| #cmakedefine HAVE_WPRINTF | ||
| #cmakedefine HAVE_REALLOCARRAY | ||
| +*/ | ||
|
|
||
| #endif /* !defined(URI_CONFIG_H) */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #!/bin/sh | ||
| set -ex | ||
| cd "$(dirname "$0")/../../.." | ||
|
|
||
| tmp_dir=/tmp/php-src-download-bundled/uriparser | ||
| rm -rf "$tmp_dir" | ||
|
|
||
| revision=c3b49569f1f25550a16d9a18207e498d77458b27 # refs/tags/uriparser-0.9.9 with https://github.com/uriparser/uriparser/pull/276 | ||
|
|
||
| git clone --depth 1 --revision="$revision" https://github.com/uriparser/uriparser.git "$tmp_dir" | ||
|
|
||
| rm -rf ext/uri/uriparser | ||
| mkdir ext/uri/uriparser | ||
| cp -R "$tmp_dir"/src ext/uri/uriparser | ||
| cp -R "$tmp_dir"/include ext/uri/uriparser | ||
| cp "$tmp_dir"/COPYING.BSD-3-Clause ext/uri/uriparser | ||
|
|
||
| cd ext/uri/uriparser | ||
|
|
||
| # move renamed files | ||
| mv src/UriConfig.h.in src/UriConfig.h | ||
|
|
||
| # patch customized files | ||
| git apply -v ../../../.github/scripts/download-bundled/uriparser.config.patch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,16 @@ | ||
| #!/bin/sh | ||
| set -ex | ||
|
|
||
| cd "$(dirname "$0")/../../$1" | ||
| # use the repo root directory as "--git-dir" | ||
| cd "$(dirname "$0")/../.." | ||
|
Comment on lines
+4
to
+5
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI only: This is important as the original Example: |
||
|
|
||
| dir="$1" | ||
|
|
||
| # notify git about untracked (except ignored) files | ||
| git add -N . | ||
| git add -N "$dir" | ||
|
|
||
| # display overview of changed files | ||
| git status . | ||
| git status "$dir" | ||
|
|
||
| # display diff of working directory vs HEAD commit and set exit code | ||
| git diff -a --exit-code HEAD . | ||
| git diff -a --exit-code HEAD "$dir" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.