Skip to content

Add a reusable PHPStan workflow and the canonical pre-push hook, PG-4897 - #44

Merged
chippison merged 12 commits into
mainfrom
PG-4897-shared-phpstan
Aug 12, 2026
Merged

Add a reusable PHPStan workflow and the canonical pre-push hook, PG-4897#44
chippison merged 12 commits into
mainfrom
PG-4897-shared-phpstan

Conversation

@snake14

@snake14 snake14 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Description

Centralizes the PHPStan CI logic that twelve plugin repositories currently carry as near-identical copies. Four rounds of fixes to the shared pre-push hook (ddev fallback, persist-credentials, merge-base base resolution, diffing pushed commits instead of the working tree) each required a pull request per plugin repo; with this change, such fixes land once here.

Two pieces:

  • .github/workflows/plugin-phpstan.yml — a reusable workflow (workflow_call). A plugin's own phpstan.yml shrinks to a ~10-line caller passing plugin-name, and optionally dependent-plugins (e.g. GoogleAnalyticsImporter needs MarketingCampaignsReporting + Funnels) and php-version (GoogleAnalyticsImporter runs on 8.2 because ConnectAccounts uses PHP 8 attribute syntax). The analysis level and phpVersion stay in each plugin's phpstan.neon.
  • hooks/pre-push — the canonical copy of the opt-in developer hook (byte-identical to what the twelve open PG-4897 PRs currently ship). Git hooks must exist as local files, so plugins keep their copy; the reusable workflow's new verify-hook step fails the build when a plugin's copy drifts from the canonical one, replacing silent divergence with a red check.

Migration of the twelve plugin repos to the caller form would follow as separate per-repo PRs once this shape is agreed.

Smoke-tested end to end from disposable caller branches: LogViewer (simple path) and GoogleAnalyticsImporter (dependent plugins, private-repo secret, PHP 8.2) both pass. The testing surfaced two fixes now included: minimal callee permissions (a blanket-read callee cannot be called from a default-permission caller at all) and the scripts-ref input (no GitHub context identifies the called workflow's own commit — github.job_workflow_sha evaluates to empty).

Open questions for review:

  1. CrashAnalytics splits its hook into a wrapper plus phpstan-pre-push.sh; it can either adopt the canonical single-file layout or call with verify-hook: false.
  2. Callers reference @main, matching how these workflows already consume scripts/bash/* — happy to pin to tags instead if preferred.
  3. The same pattern could later absorb phpcs.yml and matomo-tests.yml, which have the same duplication shape.

Ticket: PG-4897.

Checklist

  • [✔] I have understood, reviewed, and tested all AI outputs before use
  • [✔] All AI instructions respect security, IP, and privacy rules

Review

snake14 added 3 commits August 4, 2026 14:06
Plugin repos currently carry near-identical copies of both; four rounds
of hook fixes each meant twelve pull requests. The workflow also fails
when a plugin's hook copy drifts from the canonical one.
Pushing another local branch, or several refs at once, analysed the
checked-out branch instead of what was actually pushed.
snake14 added 6 commits August 4, 2026 14:21
A slug the derivation regex does not match passed through unchanged and
reached rm -rf. Also narrows the README example to pass only the secret
the workflow uses instead of secrets: inherit.
…in checkout

The name reaches path operations in checkout_matomo.sh, so reject
anything but an alphanumeric plugin name up front. Without
TARGET_BRANCH the dependent plugins silently stayed on their default
branch instead of the caller's base branch.
…tside plugins/

job.workflow_repository/job.workflow_sha make the caller's pin govern
the scripts too, instead of floating on main. The hook no longer
rejects pushes from standalone clones it cannot check.
@snake14
snake14 marked this pull request as ready for review August 4, 2026 02:57
snake14 added a commit that referenced this pull request Aug 4, 2026
Centralizing removes the reason the gate floated on main: an update is
now one SHA bump here instead of a change in every plugin repo. The
README section will conflict trivially with #44's; whichever merges
second rebases the append.
snake14 added 2 commits August 4, 2026 15:10
No GitHub context identifies the called workflow's own commit —
github.job_workflow_sha evaluates to empty (verified in a live run) —
so an explicit input is the only honest pinning mechanism.
@snake14 snake14 added the Needs Review For pull requests that need a code review. label Aug 4, 2026
lachiebol
lachiebol previously approved these changes Aug 4, 2026

@lachiebol lachiebol left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM, Codex is complaining about a documentation gap, might be good to address.

Medium

  1. The dependent-plugin validation rejects a documented repository form. scripts/bash/checkout_dependent_plugins.sh:12 only derives names from owner/plugin-PluginName; README.md:102
    promises support for both owner/PluginName and owner/plugin-PluginName. The new validation then silently skips the bare-name form. This breaks the declared input contract and can run
    PHPStan without a requested dependency.

    Parse and validate the complete slug explicitly, supporting both documented forms, for example ^owner/(plugin-)?PluginName$.

@snake14

snake14 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

LGTM, Codex is complaining about a documentation gap, might be good to address.

Medium

  1. The dependent-plugin validation rejects a documented repository form. scripts/bash/checkout_dependent_plugins.sh:12 only derives names from owner/plugin-PluginName; README.md:102
    promises support for both owner/PluginName and owner/plugin-PluginName. The new validation then silently skips the bare-name form. This breaks the declared input contract and can run
    PHPStan without a requested dependency.
    Parse and validate the complete slug explicitly, supporting both documented forms, for example ^owner/(plugin-)?PluginName$.

Thanks @lachiebol . It should now be addressed.

@snake14

snake14 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Can someone from @matomo-org/core-reviewers please merge this and #45 if they look alright?

@snake14
snake14 requested a review from a team August 6, 2026 01:58
@snake14

snake14 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

@caddoo Would someone from Core Team be able to review this PR soon? I'm unable to merge it despite Plugin Team approvals. Same with #45 and #46.

@chippison
chippison merged commit fddc11f into main Aug 12, 2026
1 check passed
@snake14
snake14 deleted the PG-4897-shared-phpstan branch August 18, 2026 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review For pull requests that need a code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants