-
Notifications
You must be signed in to change notification settings - Fork 50
build(dependencies): scope dependencies in lib/Vendor #2136
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,57 @@ | ||
| # SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| # SPDX-License-Identifier: MIT | ||
| name: PHP Scoper Dependencies | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: main | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: openapi-${{ github.head_ref || github.run_id }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| php-scoper-deps: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| if: ${{ github.repository_owner != 'nextcloud-gmbh' }} | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Get php version | ||
| id: versions | ||
| uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1 | ||
|
|
||
| - name: Set up php${{ steps.versions.outputs.php-min }} | ||
| uses: shivammathur/setup-php@bf6b4fbd49ca58e4608c9c89fba0b8d90bd2a39f # v2.35.5 | ||
| with: | ||
| php-version: ${{ steps.versions.outputs.php-min }} | ||
| extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, sqlite, pdo_sqlite | ||
| coverage: none | ||
| ini-file: development | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Install production dependencies, bypassing scripts | ||
| run: composer i --no-dev --no-scripts | ||
|
|
||
| - name: Update php-scoper dependency file | ||
| run: composer run scoper:update-deps | ||
|
|
||
| - name: Check for changes against .scoper-production-dependencies | ||
| run: | | ||
| bash -c "[[ ! \"`git status --porcelain `\" ]] || (echo 'Please run composer run scoper:update-deps and commit the changes' && exit 1)" | ||
|
|
||
| - name: Show changes on failure | ||
| if: failure() | ||
| run: | | ||
| git status | ||
| git --no-pager diff | ||
| exit 1 # make it red to grab attention |
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 |
|---|---|---|
|
|
@@ -20,3 +20,4 @@ tests/unit/.phpunit.result.cache | |
| /cypress/videos | ||
| /cypress/downloads | ||
| /vendor-bin/*/vendor | ||
| /lib/Vendor/ | ||
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,84 @@ | ||
| #!/usr/bin/env php | ||
| <?php | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| $sourceDirectory = $argv[1]; | ||
| $sourceDirectory = rtrim($sourceDirectory, '/') . '/'; | ||
|
|
||
| if (!str_starts_with($sourceDirectory, '/')) { | ||
| $sourceDirectory = getcwd() . '/' . $sourceDirectory; | ||
| } | ||
|
|
||
| $stripNamespacePrefix = $argv[2] ?? ''; | ||
| if ($stripNamespacePrefix) { | ||
| printf("Namespace Prefix to strip from destination dir is %s%s", $stripNamespacePrefix, PHP_EOL); | ||
| } | ||
|
|
||
| if (!file_exists($sourceDirectory) || !is_dir($sourceDirectory)) { | ||
| print("Directory not found"); | ||
| exit(1); | ||
| } | ||
| $organizationList = []; | ||
| foreach(scandir($sourceDirectory) as $file) { | ||
| if (!is_dir($sourceDirectory . $file) || $file === '.' || $file === '..') { | ||
| continue; | ||
| } | ||
| $organizationList[] = $sourceDirectory . $file . '/'; | ||
| } | ||
|
|
||
| $projectList = []; | ||
| foreach($organizationList as $organizationDir) { | ||
| foreach(scandir($organizationDir) as $file) { | ||
| if (!is_dir($organizationDir . $file) || $file === '.' || $file === '..') { | ||
| continue; | ||
| } | ||
| $projectList[] = $organizationDir . $file . '/'; | ||
| } | ||
| } | ||
|
|
||
| foreach ($projectList as $projectDir) { | ||
| if (!file_exists($projectDir . 'composer.json')) { | ||
| continue; | ||
| } | ||
| $projectInfo = json_decode(file_get_contents($projectDir . 'composer.json'), true); | ||
| if (!isset($projectInfo['autoload']['psr-4'])) { | ||
| printf("No supported autoload configuration in %s" . PHP_EOL, $projectDir); | ||
| exit(2); | ||
| } | ||
| foreach ($projectInfo['autoload']['psr-4'] as $namespace => $codeDir) { | ||
| if ($stripNamespacePrefix !== '' && strpos($namespace, $stripNamespacePrefix) === 0) { | ||
| $namespace = str_replace($stripNamespacePrefix, '', $namespace); | ||
| } | ||
| $destination = $sourceDirectory . str_replace('\\', '/', $namespace); | ||
| if (file_exists($destination)) { | ||
| rmdir_recursive($destination); | ||
| } | ||
| mkdir($destination, 0777, true); | ||
| if (!rename($projectDir . $codeDir, $destination)) { | ||
| printf("Failed to move %s to %s" . PHP_EOL, $projectDir . $codeDir, $destination); | ||
| exit(3); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| foreach($organizationList as $organizationDir) { | ||
| rmdir_recursive($organizationDir); | ||
| } | ||
|
|
||
| function rmdir_recursive($dir) { | ||
| foreach(scandir($dir) as $file) { | ||
| if ('.' === $file || '..' === $file) { | ||
| continue; | ||
| } | ||
| if (is_dir("$dir/$file")) { | ||
| rmdir_recursive("$dir/$file"); | ||
| } else { | ||
| unlink("$dir/$file"); | ||
| } | ||
| } | ||
| rmdir($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
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 |
|---|---|---|
|
|
@@ -18,5 +18,6 @@ | |
| ->notPath('l10n') | ||
| ->notPath('src') | ||
| ->notPath('vendor') | ||
| ->notPath('lib/Vendor') | ||
| ->in(__DIR__); | ||
| return $config; | ||
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,9 @@ | ||
| phpoffice/phpspreadsheet | ||
| composer/pcre | ||
| maennchen/zipstream-php | ||
| markbaker/complex | ||
| markbaker/matrix | ||
| psr/http-client | ||
| psr/http-factory | ||
| psr/http-message | ||
| psr/simple-cache |
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 |
|---|---|---|
| @@ -1,55 +1,71 @@ | ||
| { | ||
| "name": "nextcloud/tables", | ||
| "description": "This app is for managing data in tables.", | ||
| "type": "project", | ||
| "license": "AGPL", | ||
| "authors": [ | ||
| { | ||
| "name": "Florian Steffens", | ||
| "email": "florian@nextcloud.com" | ||
| } | ||
| ], | ||
| "require-dev": { | ||
| "nextcloud/coding-standard": "^v1.4.0", | ||
| "nextcloud/ocp": "dev-stable30", | ||
| "staabm/annotate-pull-request-from-checkstyle": "^1.8.6", | ||
| "phpunit/phpunit": "^9", | ||
| "psalm/phar": "^5.26.1", | ||
| "bamarni/composer-bin-plugin": "^1.8.2" | ||
| }, | ||
| "config": { | ||
| "optimize-autoloader": true, | ||
| "classmap-authoritative": true, | ||
| "platform": { | ||
| "php": "8.1" | ||
| }, | ||
| "allow-plugins": { | ||
| "bamarni/composer-bin-plugin": true | ||
| } | ||
| }, | ||
| "scripts": { | ||
| "test": [ | ||
| "@test:unit" | ||
| ], | ||
| "test:unit": "./vendor/bin/phpunit -c tests/unit/phpunit.xml", | ||
| "test:unit:local": "TEST_MODE=local composer test:unit", | ||
| "lint": "find . -name \\*.php -not -path './vendor/*' -not -path './build/*' -print0 | xargs -0 -n1 php -l", | ||
| "cs:check": "php-cs-fixer fix --dry-run --diff", | ||
| "cs:fix": "php-cs-fixer fix", | ||
| "psalm": "./vendor/bin/psalm.phar --show-info=false --no-cache", | ||
| "psalm:update-baseline": "./vendor/bin/psalm.phar --update-baseline", | ||
| "psalm:fix": "./vendor/bin/psalm.phar --no-cache --alter --issues=InvalidReturnType,InvalidNullableReturnType,MismatchingDocblockParamType,MismatchingDocblockReturnType,MissingParamType,InvalidFalsableReturnType", | ||
| "psalm:fix:dry": "./vendor/bin/psalm.phar --no-cache --alter --issues=InvalidReturnType,InvalidNullableReturnType,MismatchingDocblockParamType,MismatchingDocblockReturnType,MissingParamType,InvalidFalsableReturnType --dry-run", | ||
| "openapi": "generate-spec --verbose && (npm run typescript:generate || echo 'Please manually regenerate the typescript OpenAPI models')", | ||
| "post-install-cmd": [ | ||
| "[ $COMPOSER_DEV_MODE -eq 0 ] || composer bin all install --ansi" | ||
| ], | ||
| "post-update-cmd": [ | ||
| "[ $COMPOSER_DEV_MODE -eq 0 ] || composer bin all update --ansi" | ||
| ] | ||
| }, | ||
| "require": { | ||
| "phpoffice/phpspreadsheet": "^5.1", | ||
| "ext-json": "*" | ||
| } | ||
| "name": "nextcloud/tables", | ||
| "description": "This app is for managing data in tables.", | ||
| "type": "project", | ||
| "license": "AGPL", | ||
| "authors": [ | ||
| { | ||
| "name": "Florian Steffens", | ||
| "email": "florian@nextcloud.com" | ||
| } | ||
| ], | ||
| "autoload": { | ||
| "psr-4": { | ||
| "OCA\\Tables\\": "lib/" | ||
| } | ||
| }, | ||
| "require-dev": { | ||
| "nextcloud/coding-standard": "^v1.4.0", | ||
| "nextcloud/ocp": "dev-stable30", | ||
| "staabm/annotate-pull-request-from-checkstyle": "^1.8.6", | ||
| "phpunit/phpunit": "^9", | ||
| "psalm/phar": "^5.26.1" | ||
| }, | ||
| "config": { | ||
| "optimize-autoloader": true, | ||
| "classmap-authoritative": true, | ||
| "platform": { | ||
| "php": "8.1" | ||
| }, | ||
| "allow-plugins": { | ||
| "bamarni/composer-bin-plugin": true | ||
| } | ||
| }, | ||
| "scripts": { | ||
| "test": [ | ||
| "@test:unit" | ||
| ], | ||
| "test:unit": "./vendor/bin/phpunit -c tests/unit/phpunit.xml", | ||
| "test:unit:local": "TEST_MODE=local composer test:unit", | ||
| "lint": "find . -name \\*.php -not -path './vendor/*' -not -path './build/*' -print0 | xargs -0 -n1 php -l", | ||
| "cs:check": "php-cs-fixer fix --dry-run --diff", | ||
| "cs:fix": "php-cs-fixer fix", | ||
| "psalm": "./vendor/bin/psalm.phar --show-info=false --no-cache", | ||
| "psalm:update-baseline": "./vendor/bin/psalm.phar --update-baseline", | ||
| "psalm:fix": "./vendor/bin/psalm.phar --no-cache --alter --issues=InvalidReturnType,InvalidNullableReturnType,MismatchingDocblockParamType,MismatchingDocblockReturnType,MissingParamType,InvalidFalsableReturnType", | ||
| "psalm:fix:dry": "./vendor/bin/psalm.phar --no-cache --alter --issues=InvalidReturnType,InvalidNullableReturnType,MismatchingDocblockParamType,MismatchingDocblockReturnType,MissingParamType,InvalidFalsableReturnType --dry-run", | ||
| "openapi": "generate-spec --verbose && (npm run typescript:generate || echo 'Please manually regenerate the typescript OpenAPI models')", | ||
| "scoper:update-deps": "./update-scoper-dependencies.sh", | ||
| "post-install-cmd": [ | ||
| "composer bin all install --ansi", | ||
| "vendor/bin/php-scoper add-prefix --force", | ||
| "@php .lib-vendor-organizer.php lib/Vendor/ OCA\\\\Tables\\\\Vendor", | ||
| "cat .scoper-production-dependencies | uniq | xargs -I {} rm -Rf vendor/{} # Remove origins", | ||
| "cat .scoper-production-dependencies | cut -d / -f1 | uniq | xargs -I {} rmdir vendor/{} || true # Remove empty directories", | ||
| "composer dump-autoload -o" | ||
| ], | ||
| "post-update-cmd": [ | ||
| "composer bin all update --ansi", | ||
| "vendor/bin/php-scoper add-prefix --force", | ||
| "@php .lib-vendor-organizer.php lib/Vendor/ OCA\\\\Tables\\\\Vendor", | ||
| "cat .scoper-production-dependencies | uniq | xargs -I {} rm -Rf vendor/{} # Remove origins", | ||
| "cat .scoper-production-dependencies | cut -d / -f1 | uniq | xargs -I {} rmdir vendor/{} || true # Remove empty directories", | ||
| "composer dump-autoload -o" | ||
| ] | ||
| }, | ||
| "require": { | ||
| "phpoffice/phpspreadsheet": "^5.1", | ||
| "ext-json": "*", | ||
| "bamarni/composer-bin-plugin": "*" | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At what point does one run these new commands? After installing any new library?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with
composer installandcomposer update, and effectively also withcomposer requireanduninstall. Cf. https://getcomposer.org/doc/articles/scripts.mdThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh, cool. What about for
scoper:update-deps? When do I run it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After installing, updating or removing a dependency. But CI will also tell you.