Skip to content

feat: extra CI jobs with mago#170

Open
tijsverkoyen wants to merge 3 commits into
masterfrom
407-mago
Open

feat: extra CI jobs with mago#170
tijsverkoyen wants to merge 3 commits into
masterfrom
407-mago

Conversation

@tijsverkoyen

@tijsverkoyen tijsverkoyen commented May 22, 2026

Copy link
Copy Markdown
Member

https://next-app.activecollab.com/108877/projects/533/tasks/241804

Summary by Sourcery

Add Mago-based static analysis and formatting checks to the CI code quality stage and configure the tool for this project.

New Features:

  • Introduce multiple CI jobs using Mago for code formatting, linting, analysis, and structural guard checks.

Build:

  • Extend GitLab CI configuration to run Mago code style, lint, analysis, and guard jobs alongside existing code quality checks.

Documentation:

  • Add a Mago configuration file defining project-specific source paths, formatting rules, linting integrations, analysis settings, and guard rules.

Chores:

  • Declare the Mago package as a development dependency via Composer.

@sourcery-ai

sourcery-ai Bot commented May 22, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds Mago as a development dependency and wires multiple Mago-based code quality jobs into GitLab CI using a shared configuration file for formatting, linting, analysis, and structural guards.

Flow diagram for new Mago CI code quality jobs

flowchart LR
  InstallDeps["Install dependencies and build assets"]

  InstallDeps --> MagoFmtCheck["Mago - check code styling (fmt --check)"]
  InstallDeps --> MagoLint["Mago - lint (allow_failure)"]
  InstallDeps --> MagoAnalyse["Mago - analyse"]
  InstallDeps --> MagoGuard["Mago - guard (allow_failure)"]

  subgraph MagoContainer["Mago container image: ghcr.io/carthage-software/mago:1"]
    MagoFmtCheck
    MagoLint
    MagoAnalyse
    MagoGuard
  end
Loading

File-Level Changes

Change Details Files
Introduce Mago-based code quality jobs into the GitLab CI pipeline.
  • Add four new CI jobs (fmt check, lint, analyse, guard) in the code quality stage using the ghcr.io/carthage-software/mago:1 Docker image
  • Configure each job to depend on the existing "Install dependencies and build assets" job and run in the docker-tagged runners
  • Run formatter in --check mode and, on failure, re-run in --dry-run mode to print diffs
  • Allow failures for lint and guard jobs while keeping format and analyse jobs required
.gitlab-ci.yml
Add Mago as a dev dependency via Flex and configure its behaviour in the repository.
  • Register carthage-software/mago as a flex-require-dev dependency with a version constraint ^1.27
  • Add mago.dist.toml with project-wide settings for source paths, parser and formatter options, Symfony/Doctrine/PHPUnit-aware linting, analysis rules and ignores, and structural guard rules for controllers
composer.json
mago.dist.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot 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.

Hey - I've found 3 issues, and left some high level feedback:

  • The four Mago CI jobs repeat the same image, entrypoint, stage, needs, and tags; consider using YAML anchors or a shared template/extends to reduce duplication and ease future maintenance.
  • The reason string in the guard.structural.rules has a typo (exted instead of extend); updating this will make guard output clearer for developers.
  • All Mago jobs currently need the "Install dependencies and build assets" job even though they only operate on source files; you might want to drop that dependency (or split it) to shorten the pipeline when assets are not required.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The four Mago CI jobs repeat the same image, entrypoint, stage, needs, and tags; consider using YAML anchors or a shared template/extends to reduce duplication and ease future maintenance.
- The `reason` string in the `guard.structural.rules` has a typo (`exted` instead of `extend`); updating this will make guard output clearer for developers.
- All Mago jobs currently `need` the "Install dependencies and build assets" job even though they only operate on source files; you might want to drop that dependency (or split it) to shorten the pipeline when assets are not required.

## Individual Comments

### Comment 1
<location path=".gitlab-ci.yml" line_range="46" />
<code_context>
+    - mago --config=./mago.dist.toml --colors=always fmt --check
+  after_script:
+    - >
+      if [ $CI_JOB_STATUS != 'success' ]; then
+        mago --config=./mago.dist.toml --colors=always fmt --dry-run
+      fi
</code_context>
<issue_to_address>
**suggestion:** Quote CI_JOB_STATUS in the condition to avoid edge-case issues in the shell test.

Use `if [ "$CI_JOB_STATUS" != 'success' ]; then` so the condition still behaves correctly if the variable is unset or contains spaces/special characters.

```suggestion
      if [ "$CI_JOB_STATUS" != 'success' ]; then
```
</issue_to_address>

### Comment 2
<location path=".gitlab-ci.yml" line_range="66-52" />
<code_context>
+    - docker
+  allow_failure: true
+
+Mago - analyse:
+  image:
+    name: ghcr.io/carthage-software/mago:1
+    entrypoint: [ '' ]
+  script:
+    - mago --config=./mago.dist.toml --colors=always analyse --reporting-format=rich --minimum-fail-level=warning
+  stage: code quality
+  needs: [ "Install dependencies and build assets" ]
+  tags:
+    - docker
+
+Mago - guard:
</code_context>
<issue_to_address>
**suggestion:** Consider deduplicating shared job configuration using YAML anchors or extends.

These four Mago jobs duplicate `image`, `entrypoint`, `stage`, `needs`, and `tags`. To simplify maintenance, factor the shared config into a YAML anchor or GitLab `extends` template and override only `script` (and `allow_failure`) per job so changes to the base config are made in one place.

Suggested implementation:

```
Mago - analyse:
  extends: .mago-base-mago
  script:
    - mago --config=./mago.dist.toml --colors=always analyse --reporting-format=rich --minimum-fail-level=warning

```

```
Mago - guard:
  extends: .mago-base-mago
  script:
    - mago --config=./mago.dist.toml --colors=always guard --reporting-format=rich --minimum-fail-level=warning
  allow_failure: true

```

1. Add a hidden base job definition (anywhere near the top of your Mago jobs) that captures the shared configuration:

   ```yaml
   .mago-base-mago:
     image:
       name: ghcr.io/carthage-software/mago:1
       entrypoint: [ '' ]
     stage: code quality
     needs: [ "Install dependencies and build assets" ]
     tags:
       - docker
   ```

2. Update the `Mago - lint` (and any other Mago jobs not shown in the snippet) to also use `extends: .mago-base-mago`, keeping their specific `script` and `allow_failure` values, e.g.:

   ```yaml
   Mago - lint:
     extends: .mago-base-mago
     script:
       - mago --config=./mago.dist.toml --colors=always lint --reporting-format=rich --minimum-fail-level=warning
     allow_failure: true
   ```
</issue_to_address>

### Comment 3
<location path="mago.dist.toml" line_range="101" />
<code_context>
+target = "class"
+must-be-named = "*Controller"
+must-extend = "Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController"
+reason = "Controllers must exted AbstractController and name should end with *Controller."
</code_context>
<issue_to_address>
**suggestion (typo):** Fix the typo in the `reason` string for clarity.

Specifically, update `exted` to `extend` in the `reason` string so it reads: `Controllers must extend AbstractController and name should end with *Controller.`
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread .gitlab-ci.yml Outdated
Comment thread .gitlab-ci.yml
Comment thread mago.dist.toml Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants