Skip to content
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Cognitive Code Analysis GitHub Action

Composite GitHub Action that runs Cognitive Code Analysis (phpcca) in pull-request workflows. Install via PHAR or Composer, analyse changed PHP files, and optionally publish Markdown PR comments, workflow annotations, artifacts, and SARIF uploads.

Repository:Phauthentic/cognitive-code-analysis-github-action

This repository is separate from the main cognitive-code-analysis package (issue #29).

Quick start

Add this workflow to your repository (.github/workflows/cognitive-code-analysis.yml):

name: Cognitive Code Analysison:
pull_request:
paths:
- '**/*.php'permissions:
pull-requests: writecontents: readjobs:
analyse:
runs-on: ubuntu-24.04steps:
- uses: actions/checkout@v4with:
fetch-depth: 0
- uses: Phauthentic/cognitive-code-analysis-github-action@v1with:
install-mode: pharpost-comment: trueupload-artifact: trueemit-annotations: true

When cca.yaml exists in your project root, phpcca loads it automatically. See the main CI integration guide for manual workflow snippets.

Inputs

InputDefaultDescription
install-modepharphar or composer
phar-version1.11.0Release tag to download from Phauthentic/cognitive-code-analysis
phar-url(empty)Override PHAR download URL (for forks/testing)
composer-commandvendor/bin/phpccaPath to phpcca when install-mode=composer
config(empty)Config file path; empty = auto cca.yaml in CWD
php-version8.4PHP version via shivammathur/setup-php
analyze-changed-files-onlytrueDiff PR base...head for .php files; if false, use paths
pathssrcSpace-separated paths when not using changed-files mode
post-commenttruePost Markdown report as PR comment via actions/github-script
upload-artifacttrueUpload report files as artifact
artifact-namecca-reportArtifact name
emit-annotationstrueRun --report-type=github-actions and print to stdout
upload-sariffalseGenerate SARIF and upload via github/codeql-action/upload-sarif
fail-on-thresholdfalseFail job if methods exceed threshold (JUnit report)
token${{ github.token }}Token for PR comments / SARIF upload

Outputs

OutputDescription
has-reporttrue when a Markdown or SARIF report was generated
changed-files-countNumber of PHP files analysed
report-pathPath to the Markdown report file, if generated
sarif-pathPath to the SARIF report file, if generated

Permissions

Grant only the permissions you need:

permissions:
contents: read # always requiredpull-requests: write # post-comment: truesecurity-events: write # upload-sarif: true

Install modes

PHAR (default)

Downloads phpcca.phar from GitHub Releases. No Composer install step required in your workflow.

- uses: Phauthentic/cognitive-code-analysis-github-action@v1with:
install-mode: pharphar-version: '1.11.0'

Composer

Install dependencies first, then point the action at your binary:

- uses: shivammathur/setup-php@v2with:
php-version: '8.4'tools: composer
- run: composer install --prefer-dist --no-ansi --no-interaction --no-progress
- uses: Phauthentic/cognitive-code-analysis-github-action@v1with:
install-mode: composercomposer-command: vendor/bin/phpcca

Feature toggles

Each report type requires a separate phpcca invocation (one --report-type per run). The action runs only the passes you enable:

ToggleReport typeBehaviour
post-comment or upload-artifactmarkdownWrites cca-report.md
emit-annotationsgithub-actionsPrints ::warning / ::error lines to the log
upload-sarifsarifWrites cca-results.sarif and uploads to Code Scanning
fail-on-thresholdjunitWrites cca-junit.xml; fails when failures > 0

fail-on-threshold is off by default. Enable it when you want the job to fail on threshold violations.

Examples

See examples/minimal.yml for a PHAR workflow with PR comments, and examples/full-featured.yml for all toggles documented.

Local / path reference

Pin a stable release (recommended):

- uses: Phauthentic/cognitive-code-analysis-github-action@v1

Test the action from the default branch before a release:

- uses: Phauthentic/cognitive-code-analysis-github-action@master

Or reference a checkout of this repo:

- uses: ./path/to/cognitive-code-analysis-github-actionwith:
analyze-changed-files-only: 'false'paths: src/post-comment: false

Development

shellcheck scripts/**/*.sh

The ci.yml workflow runs Shellcheck and a dogfood job against fixtures/.

License

GPL-3.0-only — see LICENSE.

About

Composite GitHub Action that runs Cognitive Code Analysis (phpcca) in pull-request workflows. Install via PHAR or Composer, analyse changed PHP files, and optionally publish Markdown PR comments, workflow annotations, artifacts, and SARIF uploads.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages