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
2 changes: 1 addition & 1 deletion .github/workflows/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:

- name: Check openapi*.json and typescript changes
run: |
bash -c "[[ ! \"`git status --porcelain `\" ]] || (echo 'Please run \"composer run openapi\" and commit the openapi*.json files and (if applicable) src/types/openapi/openapi*.ts, see the section \"Show changes on failure\" for details' && exit 1)"
bash -c "[[ ! \"`git status --porcelain openapi.json src/types/openapi/openapi.ts `\" ]] || (echo 'Please run \"composer run openapi\" and commit the openapi*.json files and (if applicable) src/types/openapi/openapi*.ts, see the section \"Show changes on failure\" for details' && exit 1)"

- name: Show changes on failure
if: failure()
Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/php-scoper-dependencies.yml
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ tests/unit/.phpunit.result.cache
/cypress/videos
/cypress/downloads
/vendor-bin/*/vendor
/lib/Vendor/
84 changes: 84 additions & 0 deletions .lib-vendor-organizer.php
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);
}
6 changes: 6 additions & 0 deletions .nextcloudignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
/node_modules/
/renovate.json
/src/
/scoper.inc.php
/.scoper-production-dependencies
/.lib-vendor-organizer.php
/update-scoper-dependencies.sh
.gitattributes
.l10nignore
.php-cs-fixer.dist.php
Expand All @@ -49,5 +53,7 @@ stylelint.config.js
webpack.js
releaseNotes.md
/.scripts
/vendor/bamarni
/vendor/bin
/vendor-bin
/vite.config.ts
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
->notPath('l10n')
->notPath('src')
->notPath('vendor')
->notPath('lib/Vendor')
->in(__DIR__);
return $config;
9 changes: 9 additions & 0 deletions .scoper-production-dependencies
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
8 changes: 7 additions & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ precedence = "aggregate"
SPDX-FileCopyrightText = "2024 Nextcloud GmbH and Nextcloud contributors"
SPDX-License-Identifier = "AGPL-3.0-or-later"

[[annotations]]
path = [".scoper-production-dependencies", "vendor-bin/php-scoper/composer.json", "vendor-bin/php-scoper/composer.lock"]
precedence = "aggregate"
SPDX-FileCopyrightText = "2025 Nextcloud GmbH and Nextcloud contributors"
SPDX-License-Identifier = "AGPL-3.0-or-later"

[[annotations]]
path = ["img/app-dark.svg", "img/app.svg", "img/view.svg", "img/view-dark.svg", "img/material/*.svg"]
precedence = "aggregate"
Expand Down Expand Up @@ -113,4 +119,4 @@ SPDX-License-Identifier = "LicenseRef-GooglePlayBadge"
path = ["cypress/styleguide/assets/img/appstore.svg"]
precedence = "aggregate"
SPDX-FileCopyrightText = "2024 Apple Inc."
SPDX-License-Identifier = "LicenseRef-AppleAppStoreBadge"
SPDX-License-Identifier = "LicenseRef-AppleAppStoreBadge"
122 changes: 69 additions & 53 deletions composer.json
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"
]
Comment on lines +49 to +64

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with composer install and composer update, and effectively also with composer require and uninstall. Cf. https://getcomposer.org/doc/articles/scripts.md

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Member Author

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.

},
"require": {
"phpoffice/phpspreadsheet": "^5.1",
"ext-json": "*",
"bamarni/composer-bin-plugin": "*"
}
}
Loading
Loading