From c9a0c0a86778975e4d31fa8a003fe152de5584b2 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Sun, 15 Nov 2026 02:00:25 +0000 Subject: [PATCH 1/4] fix(ci): preserve valid workflows when upstream patches cannot apply Avoid replacing catalog-locked workflow files or advancing the lock for a failed patch; propagate blocked status to the synchronizer. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- actions/sync-workflows/sync.py | 18 ++++++++++++------ tests/test_sync_workflows_action.py | 10 +++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/actions/sync-workflows/sync.py b/actions/sync-workflows/sync.py index ce2aa28..67b1aa5 100644 --- a/actions/sync-workflows/sync.py +++ b/actions/sync-workflows/sync.py @@ -335,15 +335,21 @@ def sync( unchanged.append(name) continue - shutil.copyfile(source_file, target_file) - patch_ok, patch_message = apply_patch(target, target_file) + # Evaluate the upstream file and its local patch in isolation first. + # Never replace the last known-good workflow or advance its lock on failure. + expected, patch_ok, patch_message = render_expected( + source_file, target, target_file + ) + if not patch_ok or expected is None: + failed.append(name) + details.append(f"- {name}: {patch_message}") + continue + + target_file.write_bytes(expected) entries[name] = desired updated.append(name) - if patch_message: details.append(f"- {name}: {patch_message}") - if not patch_ok: - failed.append(name) lock_changed = bool( updated or adopted or stale_entries or provenance_updated @@ -354,7 +360,7 @@ def sync( return { "changed": lock_changed, "patch_failed": bool(set(failed) - set(diverged)), - "blocked": bool(diverged), + "blocked": bool(diverged or failed), "updated": updated, "adopted": adopted, "unchanged": unchanged, diff --git a/tests/test_sync_workflows_action.py b/tests/test_sync_workflows_action.py index d47c88c..0e6c87d 100644 --- a/tests/test_sync_workflows_action.py +++ b/tests/test_sync_workflows_action.py @@ -268,13 +268,13 @@ def test_broken_patch_sets_draft_signal_and_keeps_catalog_lock(self) -> None: source, target, target / ".github/actions-lock.txt" ) - self.assertTrue(report["changed"]) + self.assertFalse(report["changed"]) + self.assertTrue(report["blocked"]) self.assertTrue(report["patch_failed"]) self.assertEqual(report["failed"], ["sync.yml"]) - self.assertEqual( - sync_module.parse_lock(target / ".github/actions-lock.txt")["sync.yml"], - sync_module.sha256(source_file), - ) + self.assertEqual(target_file.read_text(encoding="utf-8"), "name: Old\n") + lock = sync_module.parse_lock_records(target / ".github/actions-lock.txt") + self.assertEqual(lock["sync.yml"].digest, old_hash) def test_removes_lock_entries_missing_from_catalog(self) -> None: temporary, source, target = self.fixture() From 16a894703b0138edff7ca9041d0d16126d344724 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Sun, 15 Nov 2026 02:01:09 +0000 Subject: [PATCH 2/4] feat(ci): centralize official Nextcloud PHPStan, PHPUnit and Playwright templates Track immutable Nextcloud sources with checksums; render public runners in the LibreCode workflow catalog and distribute via the existing template synchronizer. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- REUSE.toml | 15 ++ docs/upstream-workflows.md | 22 ++ scripts/render_upstream.py | 27 ++- tests/test_render_upstream.py | 32 +++ upstream/sources.json | 45 ++++ upstream/templates.json | 35 ++- upstream/vendor/nextcloud/phpstan.yml | 61 +++++ upstream/vendor/nextcloud/phpunit-mariadb.yml | 205 +++++++++++++++++ upstream/vendor/nextcloud/phpunit-pgsql.yml | 201 +++++++++++++++++ upstream/vendor/nextcloud/phpunit-sqlite.yml | 190 ++++++++++++++++ upstream/vendor/nextcloud/playwright.yml | 208 ++++++++++++++++++ workflow-templates/phpstan.properties.json | 13 ++ workflow-templates/phpstan.yml | 61 +++++ .../phpunit-mariadb.properties.json | 13 ++ workflow-templates/phpunit-mariadb.yml | 205 +++++++++++++++++ .../phpunit-pgsql.properties.json | 13 ++ workflow-templates/phpunit-pgsql.yml | 201 +++++++++++++++++ .../phpunit-sqlite.properties.json | 13 ++ workflow-templates/phpunit-sqlite.yml | 190 ++++++++++++++++ workflow-templates/playwright.properties.json | 13 ++ workflow-templates/playwright.yml | 208 ++++++++++++++++++ 21 files changed, 1969 insertions(+), 2 deletions(-) create mode 100644 REUSE.toml create mode 100644 upstream/vendor/nextcloud/phpstan.yml create mode 100644 upstream/vendor/nextcloud/phpunit-mariadb.yml create mode 100644 upstream/vendor/nextcloud/phpunit-pgsql.yml create mode 100644 upstream/vendor/nextcloud/phpunit-sqlite.yml create mode 100644 upstream/vendor/nextcloud/playwright.yml create mode 100644 workflow-templates/phpstan.properties.json create mode 100644 workflow-templates/phpstan.yml create mode 100644 workflow-templates/phpunit-mariadb.properties.json create mode 100644 workflow-templates/phpunit-mariadb.yml create mode 100644 workflow-templates/phpunit-pgsql.properties.json create mode 100644 workflow-templates/phpunit-pgsql.yml create mode 100644 workflow-templates/phpunit-sqlite.properties.json create mode 100644 workflow-templates/phpunit-sqlite.yml create mode 100644 workflow-templates/playwright.properties.json create mode 100644 workflow-templates/playwright.yml diff --git a/REUSE.toml b/REUSE.toml new file mode 100644 index 0000000..5b9e904 --- /dev/null +++ b/REUSE.toml @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: 2026 LibreCode coop and contributors +# SPDX-License-Identifier: AGPL-3.0-or-later +version = 1 + +[[annotations]] +path = ["upstream/*.json", "workflow-templates/*.properties.json"] +precedence = "aggregate" +SPDX-FileCopyrightText = "2026 LibreCode coop and contributors" +SPDX-License-Identifier = "AGPL-3.0-or-later" + +[[annotations]] +path = "patches/nextcloud/*.yml.patch" +precedence = "aggregate" +SPDX-FileCopyrightText = "2026 LibreCode coop and contributors" +SPDX-License-Identifier = "MIT" diff --git a/docs/upstream-workflows.md b/docs/upstream-workflows.md index 81f3085..bff1a9d 100644 --- a/docs/upstream-workflows.md +++ b/docs/upstream-workflows.md @@ -29,6 +29,28 @@ Rendered downstream templates are declared separately in `upstream/templates.json`. Each template points to one vendored source, an ordered patch list and a generated workflow under GitHub's native `workflow-templates/` directory. Template metadata (`*.properties.json`) is maintained locally so LibreCode can provide its own names, descriptions, categories and icons without inheriting upstream branding. +## Standard PHP and browser-testing workflows + +The organization also publishes the official Nextcloud PHPStan, SQLite/MariaDB/PostgreSQL +PHPUnit, and Playwright templates. Their source files are vendored by immutable +Nextcloud commits and checksums. Unlike product-local workflow forks, these +shared templates are updated by the normal upstream refresh procedure. + +`upstream/templates.json` declares a single reusable runner mapping: +`ubuntu-latest-low` to `ubuntu-latest`, applied only to YAML `runs-on:` values +**after** upstream patches. It does not edit the vendored Nextcloud files, +change comments, or change any other workflow strings. This avoids repeated +consumer runner patches while preserving provenance and future updates. + +Consumer application behavior such as database/fixture provisioning, custom +Playwright assertions, or bespoke PHPStan policy belongs in a small local +`.github/workflows/.yml.patch`. Applications that use the official +Composer `phpstan` and `test:unit` contracts need no local PHP patches. + +A failed consumer patch is now a hard synchronization failure: the last known-good +workflow and its lock entry are preserved. The synchronization must not publish +a broken upstream workflow before a maintainer repairs the patch. + ## Dependency-audit workflow The `npm-audit-fix.yml` catalog template is derived from a pinned Nextcloud source diff --git a/scripts/render_upstream.py b/scripts/render_upstream.py index 6a0604b..7aa0020 100644 --- a/scripts/render_upstream.py +++ b/scripts/render_upstream.py @@ -14,6 +14,9 @@ from pathlib import Path +RUNNER_RE = re.compile(r"^(?P[ \t]*runs-on:[ \t]*)(?P[A-Za-z0-9_-]+)(?P[ \t]*(?:#.*)?)$", re.MULTILINE) +RUNNER_NAME_RE = re.compile(r"^[A-Za-z0-9_-]+$") + ACTION_USE_RE = re.compile( r"^(?P\s*uses:\s*)(?P[^@\s]+)@(?P[0-9a-f]{40})(?P\s*(?:#.*)?)$", re.MULTILINE, @@ -26,6 +29,7 @@ class Template: source: Path patches: tuple[Path, ...] destination: Path + runner_aliases: tuple[tuple[str, str], ...] = () def load_templates(manifest_path: Path) -> list[Template]: @@ -37,6 +41,15 @@ def load_templates(manifest_path: Path) -> list[Template]: if not isinstance(raw_templates, list): raise ValueError("manifest.templates must be an array") + aliases = payload.get("runner_aliases", {}) + if not isinstance(aliases, dict) or any( + not isinstance(old, str) or not isinstance(new, str) + or RUNNER_NAME_RE.fullmatch(old) is None + or RUNNER_NAME_RE.fullmatch(new) is None + for old, new in aliases.items() + ): + raise ValueError("manifest.runner_aliases must map safe runner names to safe runner names") + templates: list[Template] = [] for index, raw in enumerate(raw_templates): if not isinstance(raw, dict): @@ -63,6 +76,7 @@ def load_templates(manifest_path: Path) -> list[Template]: source=source, patches=tuple(Path(item) for item in raw_patches), destination=destination, + runner_aliases=tuple(sorted(aliases.items())), ) ) @@ -93,7 +107,18 @@ def render(template: Template, root: Path) -> bytes: details = (result.stderr or result.stdout).strip() raise ValueError(f"failed to apply {patch_path}: {details}") - return working.read_bytes() + content = working.read_text(encoding="utf-8") + if template.runner_aliases: + replacements = dict(template.runner_aliases) + content = RUNNER_RE.sub( + lambda match: ( + match.group("start") + + replacements.get(match.group("runner"), match.group("runner")) + + match.group("end") + ), + content, + ) + return content.encode("utf-8") def preserve_action_pins(rendered: bytes, current: bytes | None) -> bytes: diff --git a/tests/test_render_upstream.py b/tests/test_render_upstream.py index f34b7bf..9f62012 100644 --- a/tests/test_render_upstream.py +++ b/tests/test_render_upstream.py @@ -60,6 +60,38 @@ def fixture(self, directory: str) -> tuple[Path, Path]: ) return root, manifest + def test_nextcloud_runner_alias_is_generic_and_does_not_touch_other_text(self) -> None: + with tempfile.TemporaryDirectory() as directory: + root, manifest = self.fixture(directory) + source = root / "upstream/vendor/example.yml" + source.write_text( + "name: Test\n# ubuntu-latest-low in a comment\n" + "jobs:\n test:\n runs-on: ubuntu-latest-low\n" + " fallback:\n runs-on: ubuntu-latest\n", encoding="utf-8", + ) + payload = json.loads(manifest.read_text()) + payload["templates"][0]["patches"] = [] + payload["runner_aliases"] = {"ubuntu-latest-low": "ubuntu-latest"} + manifest.write_text(json.dumps(payload)) + templates = load_templates(manifest) + self.assertTrue(sync(templates, root)["ok"]) + generated = (root / "workflow-templates/example.yml").read_text() + self.assertEqual(generated.count("runs-on: ubuntu-latest"), 2) + self.assertIn("# ubuntu-latest-low in a comment", generated) + check(templates, root) + self.assertEqual(sync(templates, root)["unchanged"], 1) + + def test_runner_alias_rejects_invalid_names(self) -> None: + with tempfile.TemporaryDirectory() as directory: + _, manifest = self.fixture(directory) + payload = json.loads(manifest.read_text()) + for aliases in ([], {"bad run": "ubuntu-latest"}, {"ubuntu-latest-low": "x\ny"}): + with self.subTest(aliases=aliases): + payload["runner_aliases"] = aliases + manifest.write_text(json.dumps(payload)) + with self.assertRaisesRegex(ValueError, "runner_aliases"): + load_templates(manifest) + def test_sync_applies_patch(self) -> None: with tempfile.TemporaryDirectory() as directory: root, manifest = self.fixture(directory) diff --git a/upstream/sources.json b/upstream/sources.json index d8d0925..72081ab 100644 --- a/upstream/sources.json +++ b/upstream/sources.json @@ -134,6 +134,51 @@ "url": "https://raw.githubusercontent.com/nextcloud/.github/d17a1728cd176b54fe0be73407ed0062a7f4ec5a/workflow-templates/npm-audit-fix.yml", "sha256": "ae8743960f808afaf479d7c3aa0f7ee04b4ad13a52c5cafe9f7eb32b19807edc", "destination": "upstream/vendor/nextcloud/npm-audit-fix.yml" + }, + { + "name": "nextcloud-phpstan", + "repository": "nextcloud/.github", + "ref": "master", + "path": "workflow-templates/phpstan.yml", + "url": "https://raw.githubusercontent.com/nextcloud/.github/c2798fc61844a6420779add9f5e1b51f8aabfd87/workflow-templates/phpstan.yml", + "sha256": "3737c57183fb37a41d0fa4cf2efa55245e7fc8348dbad43faf9ee6197440edae", + "destination": "upstream/vendor/nextcloud/phpstan.yml" + }, + { + "name": "nextcloud-phpunit-sqlite", + "repository": "nextcloud/.github", + "ref": "master", + "path": "workflow-templates/phpunit-sqlite.yml", + "url": "https://raw.githubusercontent.com/nextcloud/.github/c2798fc61844a6420779add9f5e1b51f8aabfd87/workflow-templates/phpunit-sqlite.yml", + "sha256": "06642c0d4ee358baa079716426a2ae24d387d3cb04b00c88f50ea46f8da1a1e8", + "destination": "upstream/vendor/nextcloud/phpunit-sqlite.yml" + }, + { + "name": "nextcloud-phpunit-mariadb", + "repository": "nextcloud/.github", + "ref": "master", + "path": "workflow-templates/phpunit-mariadb.yml", + "url": "https://raw.githubusercontent.com/nextcloud/.github/c2798fc61844a6420779add9f5e1b51f8aabfd87/workflow-templates/phpunit-mariadb.yml", + "sha256": "706800a7d01034c9c4a657585a1b8c955259eb86869dadabafba046081fa1446", + "destination": "upstream/vendor/nextcloud/phpunit-mariadb.yml" + }, + { + "name": "nextcloud-phpunit-pgsql", + "repository": "nextcloud/.github", + "ref": "master", + "path": "workflow-templates/phpunit-pgsql.yml", + "url": "https://raw.githubusercontent.com/nextcloud/.github/c2798fc61844a6420779add9f5e1b51f8aabfd87/workflow-templates/phpunit-pgsql.yml", + "sha256": "e0a15c5d99b0ad092a5560660f712712b1cdcf0ede6e22fca15c8b591402eec3", + "destination": "upstream/vendor/nextcloud/phpunit-pgsql.yml" + }, + { + "name": "nextcloud-playwright", + "repository": "nextcloud/.github", + "ref": "master", + "path": "workflow-templates/playwright.yml", + "url": "https://raw.githubusercontent.com/nextcloud/.github/c2798fc61844a6420779add9f5e1b51f8aabfd87/workflow-templates/playwright.yml", + "sha256": "26106f8ae4bef2a191c445fb3a246ae6e1ab3f43348b8940feaf356768091a38", + "destination": "upstream/vendor/nextcloud/playwright.yml" } ] } diff --git a/upstream/templates.json b/upstream/templates.json index 91addea..a9b82c3 100644 --- a/upstream/templates.json +++ b/upstream/templates.json @@ -116,6 +116,39 @@ "patches/nextcloud/npm-audit-fix.yml.patch" ], "destination": "workflow-templates/npm-audit-fix.yml" + }, + { + "name": "nextcloud-phpstan", + "source": "upstream/vendor/nextcloud/phpstan.yml", + "patches": [], + "destination": "workflow-templates/phpstan.yml" + }, + { + "name": "nextcloud-phpunit-sqlite", + "source": "upstream/vendor/nextcloud/phpunit-sqlite.yml", + "patches": [], + "destination": "workflow-templates/phpunit-sqlite.yml" + }, + { + "name": "nextcloud-phpunit-mariadb", + "source": "upstream/vendor/nextcloud/phpunit-mariadb.yml", + "patches": [], + "destination": "workflow-templates/phpunit-mariadb.yml" + }, + { + "name": "nextcloud-phpunit-pgsql", + "source": "upstream/vendor/nextcloud/phpunit-pgsql.yml", + "patches": [], + "destination": "workflow-templates/phpunit-pgsql.yml" + }, + { + "name": "nextcloud-playwright", + "source": "upstream/vendor/nextcloud/playwright.yml", + "patches": [], + "destination": "workflow-templates/playwright.yml" } - ] + ], + "runner_aliases": { + "ubuntu-latest-low": "ubuntu-latest" + } } diff --git a/upstream/vendor/nextcloud/phpstan.yml b/upstream/vendor/nextcloud/phpstan.yml new file mode 100644 index 0000000..4cac929 --- /dev/null +++ b/upstream/vendor/nextcloud/phpstan.yml @@ -0,0 +1,61 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: Static analysis + +on: pull_request + +concurrency: + group: phpstan-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + static-analysis: + runs-on: ubuntu-latest + + name: static-phpstan-analysis + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Get php version + id: versions + uses: nextcloud-libraries/nextcloud-version-matrix@71959de73c244b11ecbf4503b87c41d65b0f64ae # v1.3.4 + + - name: Check enforcement of minimum PHP version ${{ steps.versions.outputs.php-min-id }} in phpstan.neon + run: "grep 'min: ${{ steps.versions.outputs.php-min-id }}' phpstan.neon" + + - name: Set up php${{ steps.versions.outputs.php-available }} + uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 + with: + php-version: ${{ steps.versions.outputs.php-available }} + 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 + # Temporary workaround for missing pcntl_* in PHP 8.3 + ini-values: disable_functions= + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Remove nextcloud/ocp + run: | + composer remove nextcloud/ocp --dev --no-scripts + + - name: Install composer dependencies + uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0 + + - name: Install nextcloud/ocp:dev-${{ steps.versions.outputs.branches-max }} + run: composer require --dev nextcloud/ocp:dev-${{ steps.versions.outputs.branches-max }} --ignore-platform-reqs --with-dependencies + + - name: Run coding standards check + run: composer run phpstan -- --no-progress diff --git a/upstream/vendor/nextcloud/phpunit-mariadb.yml b/upstream/vendor/nextcloud/phpunit-mariadb.yml new file mode 100644 index 0000000..c132ab9 --- /dev/null +++ b/upstream/vendor/nextcloud/phpunit-mariadb.yml @@ -0,0 +1,205 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: PHPUnit MariaDB + +on: pull_request + +permissions: + contents: read + +concurrency: + group: phpunit-mariadb-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + changes-and-matrix: + runs-on: ubuntu-latest-low + permissions: + contents: read + pull-requests: read + + outputs: + src: ${{ steps.changes.outputs.src }} + php-version: ${{ steps.versions.outputs.php-available-list }} + server-max: ${{ steps.versions.outputs.branches-max-list }} + + steps: + - uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3 + id: changes + continue-on-error: true + with: + filters: | + src: + - '.github/workflows/**' + - 'appinfo/**' + - 'lib/**' + - 'templates/**' + - 'tests/**' + - 'vendor/**' + - 'vendor-bin/**' + - '.php-cs-fixer.dist.php' + - 'composer.json' + - 'composer.lock' + + - name: Checkout app + if: steps.changes.outputs.src != 'false' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Get version matrix + if: steps.changes.outputs.src != 'false' + id: versions + uses: nextcloud-libraries/nextcloud-version-matrix@71959de73c244b11ecbf4503b87c41d65b0f64ae # v1.3.4 + + phpunit-mariadb: + runs-on: ubuntu-latest + + needs: changes-and-matrix + if: needs.changes-and-matrix.outputs.src != 'false' + + strategy: + fail-fast: false + matrix: + php-versions: ${{ fromJson(needs.changes-and-matrix.outputs.php-version) }} + server-versions: ${{ fromJson(needs.changes-and-matrix.outputs.server-max) }} + mariadb-versions: ['10.6', '11.4'] + + name: MariaDB ${{ matrix.mariadb-versions }} PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }} + + services: + mariadb: + image: ghcr.io/nextcloud/continuous-integration-mariadb-${{ matrix.mariadb-versions }}:latest # zizmor: ignore[unpinned-images] + ports: + - 4444:3306/tcp + env: + MARIADB_ROOT_PASSWORD: rootpassword + options: --health-cmd="mariadb-admin ping" --health-interval 5s --health-timeout 2s --health-retries 5 + + steps: + - name: Set app env + if: ${{ env.APP_NAME == '' }} + run: | + # Split and keep last + echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV + + - name: Checkout server + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + submodules: true + repository: nextcloud/server + ref: ${{ matrix.server-versions }} + + - name: Checkout app + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + path: apps/${{ env.APP_NAME }} + + - name: Set up php ${{ matrix.php-versions }} + uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 + with: + php-version: ${{ matrix.php-versions }} + # https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation + extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, mysql, pdo_mysql + coverage: none + ini-file: development + # Temporary workaround for missing pcntl_* in PHP 8.3 + ini-values: disable_functions= + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Enable ONLY_FULL_GROUP_BY MariaDB option + run: | + echo "SET GLOBAL sql_mode=(SELECT CONCAT(@@sql_mode,',ONLY_FULL_GROUP_BY'));" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword + echo 'SELECT @@sql_mode;' | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword + + - name: Check composer file existence + id: check_composer + uses: andstor/file-existence-action@558493d6c74bf472d87c84eab196434afc2fa029 # v3.1.0 + with: + files: apps/${{ env.APP_NAME }}/composer.json + + - name: Remove nextcloud/ocp + # Only run if phpunit config file exists + if: steps.check_composer.outputs.files_exists == 'true' + working-directory: apps/${{ env.APP_NAME }} + run: | + composer remove nextcloud/ocp --dev --no-scripts + + - name: Install composer dependencies + uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0 + with: + working-directory: apps/${{ env.APP_NAME }} + + - name: Set up Nextcloud + env: + DB_PORT: 4444 + run: | + mkdir data + ./occ maintenance:install --verbose --database=mysql --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin + ./occ app:enable --force ${{ env.APP_NAME }} + + - name: Check PHPUnit script is defined + id: check_phpunit + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:unit ' | wc -l | grep 1 + + - name: PHPUnit + # Only run if phpunit config file exists + if: steps.check_phpunit.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:unit + + - name: Check PHPUnit integration script is defined + id: check_integration + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:integration ' | wc -l | grep 1 + + - name: Run Nextcloud + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + run: php -S localhost:8080 & + + - name: PHPUnit integration + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:integration + + - name: Print logs + if: always() + run: | + cat data/nextcloud.log + + - name: Skipped + # Fail the action when neither unit nor integration tests ran + if: steps.check_phpunit.outcome == 'failure' && steps.check_integration.outcome == 'failure' + run: | + echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts' + exit 1 + + summary: + permissions: + contents: none + runs-on: ubuntu-latest-low + needs: [changes-and-matrix, phpunit-mariadb] + + if: always() + + name: phpunit-mariadb-summary + + steps: + - name: Summary status + run: if ${{ needs.changes-and-matrix.outputs.src != 'false' && needs.phpunit-mariadb.result != 'success' }}; then exit 1; fi diff --git a/upstream/vendor/nextcloud/phpunit-pgsql.yml b/upstream/vendor/nextcloud/phpunit-pgsql.yml new file mode 100644 index 0000000..f385461 --- /dev/null +++ b/upstream/vendor/nextcloud/phpunit-pgsql.yml @@ -0,0 +1,201 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: PHPUnit PostgreSQL + +on: pull_request + +permissions: + contents: read + +concurrency: + group: phpunit-pgsql-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + changes-and-matrix: + runs-on: ubuntu-latest-low + permissions: + contents: read + pull-requests: read + + outputs: + src: ${{ steps.changes.outputs.src }} + php-version: ${{ steps.versions.outputs.php-available-list }} + server-max: ${{ steps.versions.outputs.branches-max-list }} + + steps: + - uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3 + id: changes + continue-on-error: true + with: + filters: | + src: + - '.github/workflows/**' + - 'appinfo/**' + - 'lib/**' + - 'templates/**' + - 'tests/**' + - 'vendor/**' + - 'vendor-bin/**' + - '.php-cs-fixer.dist.php' + - 'composer.json' + - 'composer.lock' + + - name: Checkout app + if: steps.changes.outputs.src != 'false' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Get version matrix + if: steps.changes.outputs.src != 'false' + id: versions + uses: nextcloud-libraries/nextcloud-version-matrix@71959de73c244b11ecbf4503b87c41d65b0f64ae # v1.3.4 + + phpunit-pgsql: + runs-on: ubuntu-latest + + needs: changes-and-matrix + if: needs.changes-and-matrix.outputs.src != 'false' + + strategy: + fail-fast: false + matrix: + php-versions: ${{ fromJson(needs.changes-and-matrix.outputs.php-version) }} + server-versions: ${{ fromJson(needs.changes-and-matrix.outputs.server-max) }} + + name: PostgreSQL PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }} + + services: + postgres: + image: ghcr.io/nextcloud/continuous-integration-postgres-16:latest # zizmor: ignore[unpinned-images] + ports: + - 4444:5432/tcp + env: + POSTGRES_USER: root + POSTGRES_PASSWORD: rootpassword + POSTGRES_DB: nextcloud + options: --health-cmd pg_isready --health-interval 5s --health-timeout 2s --health-retries 5 + + steps: + - name: Set app env + if: ${{ env.APP_NAME == '' }} + run: | + # Split and keep last + echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV + + - name: Checkout server + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + submodules: true + repository: nextcloud/server + ref: ${{ matrix.server-versions }} + + - name: Checkout app + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + path: apps/${{ env.APP_NAME }} + + - name: Set up php ${{ matrix.php-versions }} + uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 + with: + php-version: ${{ matrix.php-versions }} + # https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation + extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, pgsql, pdo_pgsql + coverage: none + ini-file: development + # Temporary workaround for missing pcntl_* in PHP 8.3 + ini-values: disable_functions= + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check composer file existence + id: check_composer + uses: andstor/file-existence-action@558493d6c74bf472d87c84eab196434afc2fa029 # v3.1.0 + with: + files: apps/${{ env.APP_NAME }}/composer.json + + - name: Remove nextcloud/ocp + # Only run if phpunit config file exists + if: steps.check_composer.outputs.files_exists == 'true' + working-directory: apps/${{ env.APP_NAME }} + run: | + composer remove nextcloud/ocp --dev --no-scripts + + - name: Install composer dependencies + uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0 + with: + working-directory: apps/${{ env.APP_NAME }} + + - name: Set up Nextcloud + env: + DB_PORT: 4444 + run: | + mkdir data + ./occ maintenance:install --verbose --database=pgsql --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin + ./occ app:enable --force ${{ env.APP_NAME }} + + - name: Check PHPUnit script is defined + id: check_phpunit + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:unit ' | wc -l | grep 1 + + - name: PHPUnit + # Only run if phpunit config file exists + if: steps.check_phpunit.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:unit + + - name: Check PHPUnit integration script is defined + id: check_integration + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:integration ' | wc -l | grep 1 + + - name: Run Nextcloud + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + run: php -S localhost:8080 & + + - name: PHPUnit integration + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:integration + + - name: Print logs + if: always() + run: | + cat data/nextcloud.log + + - name: Skipped + # Fail the action when neither unit nor integration tests ran + if: steps.check_phpunit.outcome == 'failure' && steps.check_integration.outcome == 'failure' + run: | + echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts' + exit 1 + + summary: + permissions: + contents: none + runs-on: ubuntu-latest-low + needs: [changes-and-matrix, phpunit-pgsql] + + if: always() + + name: phpunit-pgsql-summary + + steps: + - name: Summary status + run: if ${{ needs.changes-and-matrix.outputs.src != 'false' && needs.phpunit-pgsql.result != 'success' }}; then exit 1; fi diff --git a/upstream/vendor/nextcloud/phpunit-sqlite.yml b/upstream/vendor/nextcloud/phpunit-sqlite.yml new file mode 100644 index 0000000..17db507 --- /dev/null +++ b/upstream/vendor/nextcloud/phpunit-sqlite.yml @@ -0,0 +1,190 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: PHPUnit SQLite + +on: pull_request + +permissions: + contents: read + +concurrency: + group: phpunit-sqlite-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + changes-and-matrix: + runs-on: ubuntu-latest-low + permissions: + contents: read + pull-requests: read + + outputs: + src: ${{ steps.changes.outputs.src }} + php-version: ${{ steps.versions.outputs.php-available-list }} + server-max: ${{ steps.versions.outputs.branches-max-list }} + + steps: + - uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3 + id: changes + continue-on-error: true + with: + filters: | + src: + - '.github/workflows/**' + - 'appinfo/**' + - 'lib/**' + - 'templates/**' + - 'tests/**' + - 'vendor/**' + - 'vendor-bin/**' + - '.php-cs-fixer.dist.php' + - 'composer.json' + - 'composer.lock' + + - name: Checkout app + if: steps.changes.outputs.src != 'false' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Get version matrix + if: steps.changes.outputs.src != 'false' + id: versions + uses: nextcloud-libraries/nextcloud-version-matrix@71959de73c244b11ecbf4503b87c41d65b0f64ae # v1.3.4 + + phpunit-sqlite: + runs-on: ubuntu-latest + + needs: changes-and-matrix + if: needs.changes-and-matrix.outputs.src != 'false' + + strategy: + fail-fast: false + matrix: + php-versions: ${{ fromJson(needs.changes-and-matrix.outputs.php-version) }} + server-versions: ${{ fromJson(needs.changes-and-matrix.outputs.server-max) }} + + name: SQLite PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }} + + steps: + - name: Set app env + if: ${{ env.APP_NAME == '' }} + run: | + # Split and keep last + echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV + + - name: Checkout server + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + submodules: true + repository: nextcloud/server + ref: ${{ matrix.server-versions }} + + - name: Checkout app + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + path: apps/${{ env.APP_NAME }} + + - name: Set up php ${{ matrix.php-versions }} + uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 + with: + php-version: ${{ matrix.php-versions }} + # https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation + 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 + # Temporary workaround for missing pcntl_* in PHP 8.3 + ini-values: disable_functions= + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check composer file existence + id: check_composer + uses: andstor/file-existence-action@558493d6c74bf472d87c84eab196434afc2fa029 # v3.1.0 + with: + files: apps/${{ env.APP_NAME }}/composer.json + + - name: Remove nextcloud/ocp + # Only run if phpunit config file exists + if: steps.check_composer.outputs.files_exists == 'true' + working-directory: apps/${{ env.APP_NAME }} + run: | + composer remove nextcloud/ocp --dev --no-scripts + + - name: Install composer dependencies + uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0 + with: + working-directory: apps/${{ env.APP_NAME }} + + - name: Set up Nextcloud + env: + DB_PORT: 4444 + run: | + mkdir data + ./occ maintenance:install --verbose --database=sqlite --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin + ./occ app:enable --force ${{ env.APP_NAME }} + + - name: Check PHPUnit script is defined + id: check_phpunit + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:unit ' | wc -l | grep 1 + + - name: PHPUnit + # Only run if phpunit config file exists + if: steps.check_phpunit.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:unit + + - name: Check PHPUnit integration script is defined + id: check_integration + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:integration ' | wc -l | grep 1 + + - name: Run Nextcloud + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + run: php -S localhost:8080 & + + - name: PHPUnit integration + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:integration + + - name: Print logs + if: always() + run: | + cat data/nextcloud.log + + - name: Skipped + # Fail the action when neither unit nor integration tests ran + if: steps.check_phpunit.outcome == 'failure' && steps.check_integration.outcome == 'failure' + run: | + echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts' + exit 1 + + summary: + permissions: + contents: none + runs-on: ubuntu-latest-low + needs: [changes-and-matrix, phpunit-sqlite] + + if: always() + + name: phpunit-sqlite-summary + + steps: + - name: Summary status + run: if ${{ needs.changes-and-matrix.outputs.src != 'false' && needs.phpunit-sqlite.result != 'success' }}; then exit 1; fi diff --git a/upstream/vendor/nextcloud/playwright.yml b/upstream/vendor/nextcloud/playwright.yml new file mode 100644 index 0000000..c824025 --- /dev/null +++ b/upstream/vendor/nextcloud/playwright.yml @@ -0,0 +1,208 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +# This workflow runs Playwright tests on pull requests to the master and stable branches. +# It expects the following npm scripts to be defined in package.json: +# - "playwright": runs the Playwright tests +# - "playwright:install-ci": installs the Playwright browsers for CI (optional) +# +# If you only use the "Desktop Chrome" browser with "channel: chrome" in your Playwright config, +# you can skip the "playwright:install-ci" script as the GitHub Actions runner already has Chrome Browser installed. +# +# For merging the reports, it expects a Playwright merge config file at tests/playwright/merge.config.ts. +# You can adjust the path in the "Merge into HTML Report" step if you have a different location for the merge config file. +# The default configuration would look like this: +# ```js +# export default { +# testDir: 'tests/playwright/e2e', // path to your Playwright tests +# reporter: [['html', { open: 'never' }]], +# } +# ``` + +name: Playwright Tests + +on: + pull_request: + branches: + - main + - master + - stable35 + - stable34 + - stable33 + +permissions: + contents: read +concurrency: + group: playwright-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + playwright-setup: + timeout-minutes: 10 + name: Playwright setup + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Read package.json + uses: nextcloud-libraries/parse-package-engines-action@39fcc545a815c353dd0a3fd8fd2ef6e59fd02b92 # v0.2.0 + id: versions + - name: Check composer.json + id: check_composer + uses: andstor/file-existence-action@558493d6c74bf472d87c84eab196434afc2fa029 # v3.1.0 + with: + files: 'composer.json' + - name: Install composer dependencies + if: steps.check_composer.outputs.files_exists == 'true' + uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0 + with: + composer-options: '--no-dev' + - name: Set up node + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: ${{ steps.versions.outputs.node-version }} + - name: Set up npm + run: npm i -g 'npm@${{ steps.versions.outputs.package-manager-version }}' + - name: Install dependencies and build + run: | + npm ci + npm run build --if-present + - name: Save context + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + key: playwright-context-${{ github.run_id }} + path: ./ + + playwright-tests: + needs: [playwright-setup] + timeout-minutes: 30 + name: Playwright tests ${{ matrix.shardIndex }} / ${{ matrix.shardTotal }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + shardIndex: [1, 2] # adjust to your needs + shardTotal: [2] + outputs: + node-version: ${{ steps.versions.outputs.node-version }} + package-manager-version: ${{ steps.versions.outputs.package-manager-version }} + + steps: + - name: Restore context + id: cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + key: playwright-context-${{ github.run_id }} + path: ./ + + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + if: steps.cache.outputs.cache-hit != 'true' + with: + persist-credentials: false + + - name: Read package.json + uses: nextcloud-libraries/parse-package-engines-action@39fcc545a815c353dd0a3fd8fd2ef6e59fd02b92 # v0.2.0 + id: versions + + - name: Set up node + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: ${{ steps.versions.outputs.node-version }} + + - name: Set up npm + run: npm i -g 'npm@${{ steps.versions.outputs.package-manager-version }}' + + - name: Install dependencies and build + if: steps.cache.outputs.cache-hit != 'true' + run: | + npm ci + npm run build --if-present + + - name: Install Playwright browsers + run: npm run playwright:install-ci --if-present + + - name: Run Playwright tests + run: npm run playwright -- --shard='${{ matrix.shardIndex }}/${{ matrix.shardTotal }}' + + - name: Upload blob report to GitHub Actions Artifacts + if: ${{ !cancelled() }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: blob-report-${{ matrix.shardIndex }} + path: blob-report + retention-days: 1 + + merge-reports: + # Merge reports after playwright-tests, even if some shards have failed + if: ${{ !cancelled() }} + needs: [playwright-tests] + + runs-on: ubuntu-latest-low + steps: + - name: Restore context + id: cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + key: playwright-context-${{ github.run_id }} + path: ./ + + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + if: steps.cache.outputs.cache-hit != 'true' + with: + persist-credentials: false + + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + if: steps.cache.outputs.cache-hit != 'true' + with: + node-version: ${{ needs.playwright-tests.outputs.node-version }} + + - name: Set up npm + if: steps.cache.outputs.cache-hit != 'true' + run: npm i -g 'npm@${{ needs.playwright-tests.outputs.package-manager-version }}' + + - name: Install dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: npm ci + + - name: Download blob reports from GitHub Actions Artifacts + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + path: all-blob-reports + pattern: blob-report-* + merge-multiple: true + + - name: Merge into HTML Report + run: npx playwright merge-reports --config tests/playwright/merge.config.ts --reporter html,github ./all-blob-reports + + - name: Upload HTML report + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: html-report--attempt-${{ github.run_attempt }} + path: playwright-report + retention-days: 7 + + - name: How to show the logs + run: | + echo 'To view the report:' + echo ' 1. Extract the folder from the zip file' + echo ' 2. run "npx playwright show-report name-of-my-extracted-playwright-report"' + + summary: + permissions: + contents: none + runs-on: ubuntu-latest-low + needs: [playwright-tests] + + if: always() + + name: playwright-test-summary + + steps: + - name: Summary status + run: if ${{ needs.playwright-tests.result != 'success' }}; then exit 1; fi diff --git a/workflow-templates/phpstan.properties.json b/workflow-templates/phpstan.properties.json new file mode 100644 index 0000000..826fec3 --- /dev/null +++ b/workflow-templates/phpstan.properties.json @@ -0,0 +1,13 @@ +{ + "name": "PHPStan static analysis", + "description": "Run official Nextcloud PHPStan static analysis against supported PHP and Nextcloud versions.", + "iconName": "octicon codescan-checkmark", + "categories": [ + "PHP", + "test" + ], + "filePatterns": [ + "^composer.json$", + "^phpstan.neon$" + ] +} diff --git a/workflow-templates/phpstan.yml b/workflow-templates/phpstan.yml new file mode 100644 index 0000000..4cac929 --- /dev/null +++ b/workflow-templates/phpstan.yml @@ -0,0 +1,61 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: Static analysis + +on: pull_request + +concurrency: + group: phpstan-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + static-analysis: + runs-on: ubuntu-latest + + name: static-phpstan-analysis + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Get php version + id: versions + uses: nextcloud-libraries/nextcloud-version-matrix@71959de73c244b11ecbf4503b87c41d65b0f64ae # v1.3.4 + + - name: Check enforcement of minimum PHP version ${{ steps.versions.outputs.php-min-id }} in phpstan.neon + run: "grep 'min: ${{ steps.versions.outputs.php-min-id }}' phpstan.neon" + + - name: Set up php${{ steps.versions.outputs.php-available }} + uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 + with: + php-version: ${{ steps.versions.outputs.php-available }} + 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 + # Temporary workaround for missing pcntl_* in PHP 8.3 + ini-values: disable_functions= + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Remove nextcloud/ocp + run: | + composer remove nextcloud/ocp --dev --no-scripts + + - name: Install composer dependencies + uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0 + + - name: Install nextcloud/ocp:dev-${{ steps.versions.outputs.branches-max }} + run: composer require --dev nextcloud/ocp:dev-${{ steps.versions.outputs.branches-max }} --ignore-platform-reqs --with-dependencies + + - name: Run coding standards check + run: composer run phpstan -- --no-progress diff --git a/workflow-templates/phpunit-mariadb.properties.json b/workflow-templates/phpunit-mariadb.properties.json new file mode 100644 index 0000000..8076543 --- /dev/null +++ b/workflow-templates/phpunit-mariadb.properties.json @@ -0,0 +1,13 @@ +{ + "name": "PHPUnit MariaDB", + "description": "Run standard Nextcloud PHPUnit unit and integration tests with MariaDB.", + "iconName": "octicon codescan-checkmark", + "categories": [ + "PHP", + "test" + ], + "filePatterns": [ + "^composer.json$", + "^phpunit.xml.*$" + ] +} diff --git a/workflow-templates/phpunit-mariadb.yml b/workflow-templates/phpunit-mariadb.yml new file mode 100644 index 0000000..ff8167a --- /dev/null +++ b/workflow-templates/phpunit-mariadb.yml @@ -0,0 +1,205 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: PHPUnit MariaDB + +on: pull_request + +permissions: + contents: read + +concurrency: + group: phpunit-mariadb-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + changes-and-matrix: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + + outputs: + src: ${{ steps.changes.outputs.src }} + php-version: ${{ steps.versions.outputs.php-available-list }} + server-max: ${{ steps.versions.outputs.branches-max-list }} + + steps: + - uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3 + id: changes + continue-on-error: true + with: + filters: | + src: + - '.github/workflows/**' + - 'appinfo/**' + - 'lib/**' + - 'templates/**' + - 'tests/**' + - 'vendor/**' + - 'vendor-bin/**' + - '.php-cs-fixer.dist.php' + - 'composer.json' + - 'composer.lock' + + - name: Checkout app + if: steps.changes.outputs.src != 'false' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Get version matrix + if: steps.changes.outputs.src != 'false' + id: versions + uses: nextcloud-libraries/nextcloud-version-matrix@71959de73c244b11ecbf4503b87c41d65b0f64ae # v1.3.4 + + phpunit-mariadb: + runs-on: ubuntu-latest + + needs: changes-and-matrix + if: needs.changes-and-matrix.outputs.src != 'false' + + strategy: + fail-fast: false + matrix: + php-versions: ${{ fromJson(needs.changes-and-matrix.outputs.php-version) }} + server-versions: ${{ fromJson(needs.changes-and-matrix.outputs.server-max) }} + mariadb-versions: ['10.6', '11.4'] + + name: MariaDB ${{ matrix.mariadb-versions }} PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }} + + services: + mariadb: + image: ghcr.io/nextcloud/continuous-integration-mariadb-${{ matrix.mariadb-versions }}:latest # zizmor: ignore[unpinned-images] + ports: + - 4444:3306/tcp + env: + MARIADB_ROOT_PASSWORD: rootpassword + options: --health-cmd="mariadb-admin ping" --health-interval 5s --health-timeout 2s --health-retries 5 + + steps: + - name: Set app env + if: ${{ env.APP_NAME == '' }} + run: | + # Split and keep last + echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV + + - name: Checkout server + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + submodules: true + repository: nextcloud/server + ref: ${{ matrix.server-versions }} + + - name: Checkout app + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + path: apps/${{ env.APP_NAME }} + + - name: Set up php ${{ matrix.php-versions }} + uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 + with: + php-version: ${{ matrix.php-versions }} + # https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation + extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, mysql, pdo_mysql + coverage: none + ini-file: development + # Temporary workaround for missing pcntl_* in PHP 8.3 + ini-values: disable_functions= + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Enable ONLY_FULL_GROUP_BY MariaDB option + run: | + echo "SET GLOBAL sql_mode=(SELECT CONCAT(@@sql_mode,',ONLY_FULL_GROUP_BY'));" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword + echo 'SELECT @@sql_mode;' | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword + + - name: Check composer file existence + id: check_composer + uses: andstor/file-existence-action@558493d6c74bf472d87c84eab196434afc2fa029 # v3.1.0 + with: + files: apps/${{ env.APP_NAME }}/composer.json + + - name: Remove nextcloud/ocp + # Only run if phpunit config file exists + if: steps.check_composer.outputs.files_exists == 'true' + working-directory: apps/${{ env.APP_NAME }} + run: | + composer remove nextcloud/ocp --dev --no-scripts + + - name: Install composer dependencies + uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0 + with: + working-directory: apps/${{ env.APP_NAME }} + + - name: Set up Nextcloud + env: + DB_PORT: 4444 + run: | + mkdir data + ./occ maintenance:install --verbose --database=mysql --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin + ./occ app:enable --force ${{ env.APP_NAME }} + + - name: Check PHPUnit script is defined + id: check_phpunit + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:unit ' | wc -l | grep 1 + + - name: PHPUnit + # Only run if phpunit config file exists + if: steps.check_phpunit.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:unit + + - name: Check PHPUnit integration script is defined + id: check_integration + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:integration ' | wc -l | grep 1 + + - name: Run Nextcloud + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + run: php -S localhost:8080 & + + - name: PHPUnit integration + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:integration + + - name: Print logs + if: always() + run: | + cat data/nextcloud.log + + - name: Skipped + # Fail the action when neither unit nor integration tests ran + if: steps.check_phpunit.outcome == 'failure' && steps.check_integration.outcome == 'failure' + run: | + echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts' + exit 1 + + summary: + permissions: + contents: none + runs-on: ubuntu-latest + needs: [changes-and-matrix, phpunit-mariadb] + + if: always() + + name: phpunit-mariadb-summary + + steps: + - name: Summary status + run: if ${{ needs.changes-and-matrix.outputs.src != 'false' && needs.phpunit-mariadb.result != 'success' }}; then exit 1; fi diff --git a/workflow-templates/phpunit-pgsql.properties.json b/workflow-templates/phpunit-pgsql.properties.json new file mode 100644 index 0000000..499537e --- /dev/null +++ b/workflow-templates/phpunit-pgsql.properties.json @@ -0,0 +1,13 @@ +{ + "name": "PHPUnit PostgreSQL", + "description": "Run standard Nextcloud PHPUnit unit and integration tests with PostgreSQL.", + "iconName": "octicon codescan-checkmark", + "categories": [ + "PHP", + "test" + ], + "filePatterns": [ + "^composer.json$", + "^phpunit.xml.*$" + ] +} diff --git a/workflow-templates/phpunit-pgsql.yml b/workflow-templates/phpunit-pgsql.yml new file mode 100644 index 0000000..4c1490a --- /dev/null +++ b/workflow-templates/phpunit-pgsql.yml @@ -0,0 +1,201 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: PHPUnit PostgreSQL + +on: pull_request + +permissions: + contents: read + +concurrency: + group: phpunit-pgsql-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + changes-and-matrix: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + + outputs: + src: ${{ steps.changes.outputs.src }} + php-version: ${{ steps.versions.outputs.php-available-list }} + server-max: ${{ steps.versions.outputs.branches-max-list }} + + steps: + - uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3 + id: changes + continue-on-error: true + with: + filters: | + src: + - '.github/workflows/**' + - 'appinfo/**' + - 'lib/**' + - 'templates/**' + - 'tests/**' + - 'vendor/**' + - 'vendor-bin/**' + - '.php-cs-fixer.dist.php' + - 'composer.json' + - 'composer.lock' + + - name: Checkout app + if: steps.changes.outputs.src != 'false' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Get version matrix + if: steps.changes.outputs.src != 'false' + id: versions + uses: nextcloud-libraries/nextcloud-version-matrix@71959de73c244b11ecbf4503b87c41d65b0f64ae # v1.3.4 + + phpunit-pgsql: + runs-on: ubuntu-latest + + needs: changes-and-matrix + if: needs.changes-and-matrix.outputs.src != 'false' + + strategy: + fail-fast: false + matrix: + php-versions: ${{ fromJson(needs.changes-and-matrix.outputs.php-version) }} + server-versions: ${{ fromJson(needs.changes-and-matrix.outputs.server-max) }} + + name: PostgreSQL PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }} + + services: + postgres: + image: ghcr.io/nextcloud/continuous-integration-postgres-16:latest # zizmor: ignore[unpinned-images] + ports: + - 4444:5432/tcp + env: + POSTGRES_USER: root + POSTGRES_PASSWORD: rootpassword + POSTGRES_DB: nextcloud + options: --health-cmd pg_isready --health-interval 5s --health-timeout 2s --health-retries 5 + + steps: + - name: Set app env + if: ${{ env.APP_NAME == '' }} + run: | + # Split and keep last + echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV + + - name: Checkout server + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + submodules: true + repository: nextcloud/server + ref: ${{ matrix.server-versions }} + + - name: Checkout app + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + path: apps/${{ env.APP_NAME }} + + - name: Set up php ${{ matrix.php-versions }} + uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 + with: + php-version: ${{ matrix.php-versions }} + # https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation + extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, pgsql, pdo_pgsql + coverage: none + ini-file: development + # Temporary workaround for missing pcntl_* in PHP 8.3 + ini-values: disable_functions= + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check composer file existence + id: check_composer + uses: andstor/file-existence-action@558493d6c74bf472d87c84eab196434afc2fa029 # v3.1.0 + with: + files: apps/${{ env.APP_NAME }}/composer.json + + - name: Remove nextcloud/ocp + # Only run if phpunit config file exists + if: steps.check_composer.outputs.files_exists == 'true' + working-directory: apps/${{ env.APP_NAME }} + run: | + composer remove nextcloud/ocp --dev --no-scripts + + - name: Install composer dependencies + uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0 + with: + working-directory: apps/${{ env.APP_NAME }} + + - name: Set up Nextcloud + env: + DB_PORT: 4444 + run: | + mkdir data + ./occ maintenance:install --verbose --database=pgsql --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin + ./occ app:enable --force ${{ env.APP_NAME }} + + - name: Check PHPUnit script is defined + id: check_phpunit + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:unit ' | wc -l | grep 1 + + - name: PHPUnit + # Only run if phpunit config file exists + if: steps.check_phpunit.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:unit + + - name: Check PHPUnit integration script is defined + id: check_integration + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:integration ' | wc -l | grep 1 + + - name: Run Nextcloud + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + run: php -S localhost:8080 & + + - name: PHPUnit integration + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:integration + + - name: Print logs + if: always() + run: | + cat data/nextcloud.log + + - name: Skipped + # Fail the action when neither unit nor integration tests ran + if: steps.check_phpunit.outcome == 'failure' && steps.check_integration.outcome == 'failure' + run: | + echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts' + exit 1 + + summary: + permissions: + contents: none + runs-on: ubuntu-latest + needs: [changes-and-matrix, phpunit-pgsql] + + if: always() + + name: phpunit-pgsql-summary + + steps: + - name: Summary status + run: if ${{ needs.changes-and-matrix.outputs.src != 'false' && needs.phpunit-pgsql.result != 'success' }}; then exit 1; fi diff --git a/workflow-templates/phpunit-sqlite.properties.json b/workflow-templates/phpunit-sqlite.properties.json new file mode 100644 index 0000000..a42d5a8 --- /dev/null +++ b/workflow-templates/phpunit-sqlite.properties.json @@ -0,0 +1,13 @@ +{ + "name": "PHPUnit SQLite", + "description": "Run standard Nextcloud PHPUnit unit and integration tests with SQLite.", + "iconName": "octicon codescan-checkmark", + "categories": [ + "PHP", + "test" + ], + "filePatterns": [ + "^composer.json$", + "^phpunit.xml.*$" + ] +} diff --git a/workflow-templates/phpunit-sqlite.yml b/workflow-templates/phpunit-sqlite.yml new file mode 100644 index 0000000..c77dd8a --- /dev/null +++ b/workflow-templates/phpunit-sqlite.yml @@ -0,0 +1,190 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: PHPUnit SQLite + +on: pull_request + +permissions: + contents: read + +concurrency: + group: phpunit-sqlite-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + changes-and-matrix: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + + outputs: + src: ${{ steps.changes.outputs.src }} + php-version: ${{ steps.versions.outputs.php-available-list }} + server-max: ${{ steps.versions.outputs.branches-max-list }} + + steps: + - uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3 + id: changes + continue-on-error: true + with: + filters: | + src: + - '.github/workflows/**' + - 'appinfo/**' + - 'lib/**' + - 'templates/**' + - 'tests/**' + - 'vendor/**' + - 'vendor-bin/**' + - '.php-cs-fixer.dist.php' + - 'composer.json' + - 'composer.lock' + + - name: Checkout app + if: steps.changes.outputs.src != 'false' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Get version matrix + if: steps.changes.outputs.src != 'false' + id: versions + uses: nextcloud-libraries/nextcloud-version-matrix@71959de73c244b11ecbf4503b87c41d65b0f64ae # v1.3.4 + + phpunit-sqlite: + runs-on: ubuntu-latest + + needs: changes-and-matrix + if: needs.changes-and-matrix.outputs.src != 'false' + + strategy: + fail-fast: false + matrix: + php-versions: ${{ fromJson(needs.changes-and-matrix.outputs.php-version) }} + server-versions: ${{ fromJson(needs.changes-and-matrix.outputs.server-max) }} + + name: SQLite PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }} + + steps: + - name: Set app env + if: ${{ env.APP_NAME == '' }} + run: | + # Split and keep last + echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV + + - name: Checkout server + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + submodules: true + repository: nextcloud/server + ref: ${{ matrix.server-versions }} + + - name: Checkout app + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + path: apps/${{ env.APP_NAME }} + + - name: Set up php ${{ matrix.php-versions }} + uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 + with: + php-version: ${{ matrix.php-versions }} + # https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation + 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 + # Temporary workaround for missing pcntl_* in PHP 8.3 + ini-values: disable_functions= + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check composer file existence + id: check_composer + uses: andstor/file-existence-action@558493d6c74bf472d87c84eab196434afc2fa029 # v3.1.0 + with: + files: apps/${{ env.APP_NAME }}/composer.json + + - name: Remove nextcloud/ocp + # Only run if phpunit config file exists + if: steps.check_composer.outputs.files_exists == 'true' + working-directory: apps/${{ env.APP_NAME }} + run: | + composer remove nextcloud/ocp --dev --no-scripts + + - name: Install composer dependencies + uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0 + with: + working-directory: apps/${{ env.APP_NAME }} + + - name: Set up Nextcloud + env: + DB_PORT: 4444 + run: | + mkdir data + ./occ maintenance:install --verbose --database=sqlite --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin + ./occ app:enable --force ${{ env.APP_NAME }} + + - name: Check PHPUnit script is defined + id: check_phpunit + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:unit ' | wc -l | grep 1 + + - name: PHPUnit + # Only run if phpunit config file exists + if: steps.check_phpunit.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:unit + + - name: Check PHPUnit integration script is defined + id: check_integration + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:integration ' | wc -l | grep 1 + + - name: Run Nextcloud + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + run: php -S localhost:8080 & + + - name: PHPUnit integration + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:integration + + - name: Print logs + if: always() + run: | + cat data/nextcloud.log + + - name: Skipped + # Fail the action when neither unit nor integration tests ran + if: steps.check_phpunit.outcome == 'failure' && steps.check_integration.outcome == 'failure' + run: | + echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts' + exit 1 + + summary: + permissions: + contents: none + runs-on: ubuntu-latest + needs: [changes-and-matrix, phpunit-sqlite] + + if: always() + + name: phpunit-sqlite-summary + + steps: + - name: Summary status + run: if ${{ needs.changes-and-matrix.outputs.src != 'false' && needs.phpunit-sqlite.result != 'success' }}; then exit 1; fi diff --git a/workflow-templates/playwright.properties.json b/workflow-templates/playwright.properties.json new file mode 100644 index 0000000..5abbc43 --- /dev/null +++ b/workflow-templates/playwright.properties.json @@ -0,0 +1,13 @@ +{ + "name": "Playwright end-to-end tests", + "description": "Run official Nextcloud Playwright browser tests with report aggregation.", + "iconName": "octicon codescan-checkmark", + "categories": [ + "JavaScript", + "test" + ], + "filePatterns": [ + "^package.json$", + "^playwright.config.*$" + ] +} diff --git a/workflow-templates/playwright.yml b/workflow-templates/playwright.yml new file mode 100644 index 0000000..36b4f8c --- /dev/null +++ b/workflow-templates/playwright.yml @@ -0,0 +1,208 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +# This workflow runs Playwright tests on pull requests to the master and stable branches. +# It expects the following npm scripts to be defined in package.json: +# - "playwright": runs the Playwright tests +# - "playwright:install-ci": installs the Playwright browsers for CI (optional) +# +# If you only use the "Desktop Chrome" browser with "channel: chrome" in your Playwright config, +# you can skip the "playwright:install-ci" script as the GitHub Actions runner already has Chrome Browser installed. +# +# For merging the reports, it expects a Playwright merge config file at tests/playwright/merge.config.ts. +# You can adjust the path in the "Merge into HTML Report" step if you have a different location for the merge config file. +# The default configuration would look like this: +# ```js +# export default { +# testDir: 'tests/playwright/e2e', // path to your Playwright tests +# reporter: [['html', { open: 'never' }]], +# } +# ``` + +name: Playwright Tests + +on: + pull_request: + branches: + - main + - master + - stable35 + - stable34 + - stable33 + +permissions: + contents: read +concurrency: + group: playwright-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + playwright-setup: + timeout-minutes: 10 + name: Playwright setup + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Read package.json + uses: nextcloud-libraries/parse-package-engines-action@39fcc545a815c353dd0a3fd8fd2ef6e59fd02b92 # v0.2.0 + id: versions + - name: Check composer.json + id: check_composer + uses: andstor/file-existence-action@558493d6c74bf472d87c84eab196434afc2fa029 # v3.1.0 + with: + files: 'composer.json' + - name: Install composer dependencies + if: steps.check_composer.outputs.files_exists == 'true' + uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0 + with: + composer-options: '--no-dev' + - name: Set up node + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: ${{ steps.versions.outputs.node-version }} + - name: Set up npm + run: npm i -g 'npm@${{ steps.versions.outputs.package-manager-version }}' + - name: Install dependencies and build + run: | + npm ci + npm run build --if-present + - name: Save context + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + key: playwright-context-${{ github.run_id }} + path: ./ + + playwright-tests: + needs: [playwright-setup] + timeout-minutes: 30 + name: Playwright tests ${{ matrix.shardIndex }} / ${{ matrix.shardTotal }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + shardIndex: [1, 2] # adjust to your needs + shardTotal: [2] + outputs: + node-version: ${{ steps.versions.outputs.node-version }} + package-manager-version: ${{ steps.versions.outputs.package-manager-version }} + + steps: + - name: Restore context + id: cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + key: playwright-context-${{ github.run_id }} + path: ./ + + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + if: steps.cache.outputs.cache-hit != 'true' + with: + persist-credentials: false + + - name: Read package.json + uses: nextcloud-libraries/parse-package-engines-action@39fcc545a815c353dd0a3fd8fd2ef6e59fd02b92 # v0.2.0 + id: versions + + - name: Set up node + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: ${{ steps.versions.outputs.node-version }} + + - name: Set up npm + run: npm i -g 'npm@${{ steps.versions.outputs.package-manager-version }}' + + - name: Install dependencies and build + if: steps.cache.outputs.cache-hit != 'true' + run: | + npm ci + npm run build --if-present + + - name: Install Playwright browsers + run: npm run playwright:install-ci --if-present + + - name: Run Playwright tests + run: npm run playwright -- --shard='${{ matrix.shardIndex }}/${{ matrix.shardTotal }}' + + - name: Upload blob report to GitHub Actions Artifacts + if: ${{ !cancelled() }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: blob-report-${{ matrix.shardIndex }} + path: blob-report + retention-days: 1 + + merge-reports: + # Merge reports after playwright-tests, even if some shards have failed + if: ${{ !cancelled() }} + needs: [playwright-tests] + + runs-on: ubuntu-latest + steps: + - name: Restore context + id: cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + key: playwright-context-${{ github.run_id }} + path: ./ + + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + if: steps.cache.outputs.cache-hit != 'true' + with: + persist-credentials: false + + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + if: steps.cache.outputs.cache-hit != 'true' + with: + node-version: ${{ needs.playwright-tests.outputs.node-version }} + + - name: Set up npm + if: steps.cache.outputs.cache-hit != 'true' + run: npm i -g 'npm@${{ needs.playwright-tests.outputs.package-manager-version }}' + + - name: Install dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: npm ci + + - name: Download blob reports from GitHub Actions Artifacts + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + path: all-blob-reports + pattern: blob-report-* + merge-multiple: true + + - name: Merge into HTML Report + run: npx playwright merge-reports --config tests/playwright/merge.config.ts --reporter html,github ./all-blob-reports + + - name: Upload HTML report + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: html-report--attempt-${{ github.run_attempt }} + path: playwright-report + retention-days: 7 + + - name: How to show the logs + run: | + echo 'To view the report:' + echo ' 1. Extract the folder from the zip file' + echo ' 2. run "npx playwright show-report name-of-my-extracted-playwright-report"' + + summary: + permissions: + contents: none + runs-on: ubuntu-latest + needs: [playwright-tests] + + if: always() + + name: playwright-test-summary + + steps: + - name: Summary status + run: if ${{ needs.playwright-tests.result != 'success' }}; then exit 1; fi From 28ef81b27ffe591b70bd54fada230e48d8634a75 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Sun, 15 Nov 2026 02:20:17 +0000 Subject: [PATCH 3/4] style: indent REUSE annotations and clarify workflow sync Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- REUSE.toml | 16 ++++++++-------- actions/sync-workflows/action.yml | 2 +- actions/sync-workflows/sync.py | 7 +++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/REUSE.toml b/REUSE.toml index 5b9e904..72e85d8 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -3,13 +3,13 @@ version = 1 [[annotations]] -path = ["upstream/*.json", "workflow-templates/*.properties.json"] -precedence = "aggregate" -SPDX-FileCopyrightText = "2026 LibreCode coop and contributors" -SPDX-License-Identifier = "AGPL-3.0-or-later" + path = ["upstream/*.json", "workflow-templates/*.properties.json"] + precedence = "aggregate" + SPDX-FileCopyrightText = "2026 LibreCode coop and contributors" + SPDX-License-Identifier = "AGPL-3.0-or-later" [[annotations]] -path = "patches/nextcloud/*.yml.patch" -precedence = "aggregate" -SPDX-FileCopyrightText = "2026 LibreCode coop and contributors" -SPDX-License-Identifier = "MIT" + path = "patches/nextcloud/*.yml.patch" + precedence = "aggregate" + SPDX-FileCopyrightText = "2026 LibreCode coop and contributors" + SPDX-License-Identifier = "MIT" diff --git a/actions/sync-workflows/action.yml b/actions/sync-workflows/action.yml index 0e49edb..566ffa3 100644 --- a/actions/sync-workflows/action.yml +++ b/actions/sync-workflows/action.yml @@ -32,7 +32,7 @@ outputs: description: Whether at least one local workflow patch failed to apply. value: ${{ steps.sync.outputs.patch_failed }} blocked: - description: Whether synchronization was blocked by unmanaged local divergence. + description: Whether synchronization was blocked by local divergence or a patch failure. value: ${{ steps.sync.outputs.blocked }} updated: description: JSON array of updated workflow names. diff --git a/actions/sync-workflows/sync.py b/actions/sync-workflows/sync.py index 67b1aa5..795442e 100644 --- a/actions/sync-workflows/sync.py +++ b/actions/sync-workflows/sync.py @@ -190,7 +190,6 @@ def apply_patch(target_root: Path, target_file: Path) -> tuple[bool, str]: def render_expected( source_file: Path, - target_root: Path, target_file: Path, ) -> tuple[bytes | None, bool, str]: patch_file = Path(f"{target_file}.patch") @@ -287,7 +286,7 @@ def sync( if locked is None: expected, patch_ok, patch_message = render_expected( - source_file, target, target_file + source_file, target_file ) if not patch_ok: failed.append(name) @@ -310,7 +309,7 @@ def sync( if matches_source(locked, source_file): expected, patch_ok, patch_message = render_expected( - source_file, target, target_file + source_file, target_file ) if not patch_ok: failed.append(name) @@ -338,7 +337,7 @@ def sync( # Evaluate the upstream file and its local patch in isolation first. # Never replace the last known-good workflow or advance its lock on failure. expected, patch_ok, patch_message = render_expected( - source_file, target, target_file + source_file, target_file ) if not patch_ok or expected is None: failed.append(name) From 297c9cee2c030613d238851b5427fce5d179e75d Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Sun, 15 Nov 2026 02:28:18 +0000 Subject: [PATCH 4/4] style: format REUSE path array like LibreSign Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- REUSE.toml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/REUSE.toml b/REUSE.toml index 72e85d8..8c83a7c 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -3,13 +3,16 @@ version = 1 [[annotations]] - path = ["upstream/*.json", "workflow-templates/*.properties.json"] - precedence = "aggregate" - SPDX-FileCopyrightText = "2026 LibreCode coop and contributors" - SPDX-License-Identifier = "AGPL-3.0-or-later" +path = [ + "upstream/*.json", + "workflow-templates/*.properties.json" +] +precedence = "aggregate" +SPDX-FileCopyrightText = "2026 LibreCode coop and contributors" +SPDX-License-Identifier = "AGPL-3.0-or-later" [[annotations]] - path = "patches/nextcloud/*.yml.patch" - precedence = "aggregate" - SPDX-FileCopyrightText = "2026 LibreCode coop and contributors" - SPDX-License-Identifier = "MIT" +path = "patches/nextcloud/*.yml.patch" +precedence = "aggregate" +SPDX-FileCopyrightText = "2026 LibreCode coop and contributors" +SPDX-License-Identifier = "MIT"