Skip to content

Release 1.11.1

Latest

Choose a tag to compare

@github-actions github-actions released this 24 May 13:11
36a2acd

1.11.1 - GitHub Action, CI Docs & Configuration Refinements

What's Changed

✨ New Features

  • GitHub Action for Pull Request Analysis by @floriankraemer in #72

    • Added a composite GitHub Action in a dedicated repository: cognitive-code-analysis-github-action
    • Install via PHAR download or existing Composer binary (install-mode: phar | composer)
    • Analyses changed .php files on pull requests (comma-separated path support)
    • Configurable PR comments, workflow annotations, artifacts, SARIF upload, and optional threshold failure
    • Example workflow added to this repository: .github/workflows/cognitive-code-analysis.yaml
    • Use Phauthentic/cognitive-code-analysis-github-action@v1 in consumer projects
  • Runtime Configuration Feedback by @floriankraemer in #72

    • analyse and churn now print the active config source and cache status at startup
    • Example console output:
      Config: ./phpcca.yaml
      Cache: enabled
      
    • New RuntimeStatusRenderer class used by both Cognitive and Churn configuration pipeline stages
    • Relative paths are shown when the config file is inside the working directory
  • CI Integration Guide by @floriankraemer in #72

    • New docs/CI-Integration.md with end-to-end CI setup documentation
    • GitHub Actions workflow examples (Markdown PR comments, SARIF upload, artifacts)
    • GitLab CI workflow examples (merge request notes, Code Quality widget)
    • Correct comma-separated path usage for analysing multiple changed files in one invocation
    • Linked from readme.md

🔧 Configuration Enhancements

  • Standardized Config Filename: phpcca.yaml by @floriankraemer in #72

    • Renamed bundled project config from config.yml to phpcca.yaml
    • bin/phpcca init now creates phpcca.yaml in the current directory (was cca.yaml in 1.11.0)
    • Auto-discovery updated: analyse and churn load ./phpcca.yaml when present
    • Explicit --config always takes precedence over auto-discovery
    • PHAR bundle (box.json.dist), ConfigService, and ConfigInitializer updated to reference phpcca.yaml
  • Focused Default Output by @floriankraemer in #72

    • Bundled phpcca.yaml sets showOnlyMethodsExceedingThreshold: true by default
    • Console and Markdown output focus on methods exceeding scoreThreshold
    • Reduces noise in local runs and CI reports when using the default configuration

🏗️ Architecture Improvements

  • Configuration Pipeline Refactoring by @floriankraemer in #72

    • Simplified ConfigurationStage in both Cognitive and Churn pipelines
    • Centralized runtime status rendering via RuntimeStatusRenderer
    • Clearer error handling when configuration loading fails

🧪 Testing & Quality Assurance

  • Updated Golden-File Tests by @floriankraemer in #72

    • Console output fixtures updated to include Config: and Cache: status lines
    • CognitiveMetricsCommandCoverageTest uses an explicit test config to avoid coupling to bundled defaults
    • Added RuntimeStatusRendererTest for built-in config, relative path, and absolute path formatting
    • Updated InitCommandTest and ConfigInitializerTest for phpcca.yaml naming

📚 Documentation

  • Configuration & README Updates by @floriankraemer in #72

    • docs/Configuration.md updated for phpcca.yaml naming and auto-discovery
    • readme.md updated with init workflow and phpcca.yaml references
    • docs/CI-Integration.md documents GitHub Action usage alongside manual workflow snippets

Changes

Full Changelog: 1.11.0...1.11.1

Key Highlights

  • One-Line CI Setup: The new GitHub Action lets teams add cognitive complexity checks to pull requests without writing shell scripts
  • Clearer Runtime Feedback: Config source and cache status are visible at the start of every analyse and churn run
  • Consistent Config Naming: phpcca.yaml is now the single recommended filename for project configuration, init output, and auto-discovery
  • Less Noisy Defaults: Threshold filtering is enabled in the bundled config so reports highlight methods that actually need attention
  • CI Documentation: A dedicated integration guide covers GitHub Actions, GitLab CI, report formats, and changed-file analysis

Migration Guide

If you're upgrading from 1.11.0, please note:

  1. Rename Your Config File: If you use cca.yaml or config.yml, rename it to phpcca.yaml (or keep your filename and pass --config explicitly)
  2. Init Output Changed: bin/phpcca init now creates phpcca.yaml instead of cca.yaml
  3. Auto-Discovery Updated: analyse and churn look for ./phpcca.yaml in the working directory when --config is omitted
  4. Default Filtering: The bundled config enables showOnlyMethodsExceedingThreshold: true — set it to false in your phpcca.yaml if you want all methods listed
  5. GitHub Action Available: For PR workflows, consider cognitive-code-analysis-github-action@v1 instead of maintaining a custom workflow
  6. No Breaking CLI Changes: All existing commands, report types, and --config behaviour remain compatible

Example Usage

Project Setup

bin/phpcca init                  # interactive setup → creates phpcca.yaml
bin/phpcca init --silent         # non-interactive, all defaults
bin/phpcca init --path=./phpcca.yaml

Analyse with Auto-Discovered Config

bin/phpcca analyse src/          # auto-loads ./phpcca.yaml when present
bin/phpcca analyse src/ --config=custom.yaml  # explicit config overrides auto-discovery

GitHub Action (New)

# .github/workflows/cognitive-code-analysis.yaml
name: Cognitive Code Analysis

on:
  pull_request:
    paths:
      - '**/*.php'

permissions:
  pull-requests: write
  contents: read

jobs:
  analyse:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - uses: Phauthentic/cognitive-code-analysis-github-action@v1
        with:
          install-mode: phar
          post-comment: true
          upload-artifact: true
          emit-annotations: true

Analyse Multiple Changed Files in CI

CHANGED_FILES=$(git diff --name-only --diff-filter=ACMR $BASE_SHA...$HEAD_SHA | grep '\.php$' | tr '\n' ' ')
ANALYSE_PATH=$(echo "$CHANGED_FILES" | tr ' ' ',')
bin/phpcca analyse "$ANALYSE_PATH" --report-type=markdown --report-file=cca-report.md

See docs/CI-Integration.md and docs/Configuration.md for complete documentation.

Contributors