Skip to main content
Teams+

GitHub Actions

To use DCM with GitHub, install dedicated GitHub Actions: setup-dcm and dcm-action.

note

If you are migrating from @v1, replace all _ in the configuration option names with - (for example, github_token -> github-token). This change was made to make the github action options consistent with the CLI options.

Visit setup-dcm@v1 or dcm-action@v1 to access the docs for v1.

setup-dcm

setup-dcm installs and sets up DCM for use in GitHub Actions.

Usage Example

name: DCM

on:
pull_request:
branches: [main]
push:
branches: [main]

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Dart and Flutter
uses: subosito/flutter-action@v2

- name: Install dependencies
run: flutter pub get

- name: Install DCM
uses: CQLabs/setup-dcm@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Run DCM
run: dcm analyze --ci-key="${{ secrets.DCM_CI_KEY }}" --email="${{ secrets.DCM_EMAIL }}" lib
info

Even though DCM is no longer an analyzer plugin, it's important to install dependencies via pub get before running dcm checks.

Alternatively, you can install DCM on your CI directly
- name: Install DCM
run: |
sudo apt-get update
wget -qO- https://dcm.dev/pgp-key.public | sudo gpg --dearmor -o /usr/share/keyrings/dcm.gpg
echo 'deb [signed-by=/usr/share/keyrings/dcm.gpg arch=amd64] https://dcm.dev/debian stable main' | sudo tee /etc/apt/sources.list.d/dart_stable.list
sudo apt-get update
sudo apt-get install dcm

Inputs

The action takes the following inputs:

  • github-token: Used to get the latest DCM version from GitHub releases (required).
  • version: Which DCM version to setup:
    • A specific DCM version (e.g. 1.21.2)
    • or latest (default)
    • or auto (to reuse the version constraint from dcm_global.yaml described here)

Outputs

The action produces the following output:

  • dcm-version: The version of the DCM executable that was installed.

dcm-action

dcm-action runs DCM checks in GitHub Actions. It can also add a comment with dcm checks status to your Pull Requests.

info

This action requires write permissions for checks and pull-requests. For more information, refer to GitHub docs here and here.

Usage Example (combined with setup-dcm)

name: DCM

on:
pull_request:
branches: [main]
push:
branches: [main]

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Dart and Flutter
uses: subosito/flutter-action@v2

- name: Install dependencies
run: flutter pub get

- name: Install DCM
uses: CQLabs/setup-dcm@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Run DCM
uses: CQLabs/dcm-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
ci-key: ${{ secrets.DCM_CI_KEY }}
email: ${{ secrets.DCM_EMAIL }}
analyze: true
folders: lib
warning

working-directory option works only for run steps and has no effect when used with an action. You can find more info in GitHub docs.

Inputs

note

If you have a DCM Open Source license, pass oss to both CI key and email inputs.

NameRequiredDescriptionDefault
github-token☑️Required to post a report on GitHub. Note: the secret GITHUB_TOKEN is already provided by GitHub and you don't have to set it up yourself.
github-patIn some cases1Personal access token. Must have access to repo and read:user scopes.
ci-key☑️The license CI/CD key.
email☑️The license email.
pull-request-commentAdd a comment with a report overview to your pull requests.true
pull-request-comment-on-failAdd a comment with a report overview to your pull requests, but only when any DCM check fails. Note, when this option is enabled, pull-request-comment must be explicitly set to false.false
package-namePackage name to differentiate the report. Set when running several DCM runs at once.
### General:
foldersList of folders and files (comma separated) to scan.[lib]
excludeList of files to exclude (in Glob syntax). If passing more than 1 glob pattern, wrap the list of patters into {}.{**/*.g.dart, **/*.freezed.dart}
exclude-public-apiExclude publicly exported code from the analysis output.false
fatal-foundTreat any found issue as fatal.true
### Commands:
analyzeRun dcm analyze (docs).true
analyze-assetsRun dcm analyze-assets (docs). Supports additional options listed below.false
analyze-widgetsRun dcm analyze-widgets (docs). Supports additional options listed below.false
calculate-metricsRun dcm calculate-metrics (docs).false
check-code-duplicationRun dcm check-code-duplication (docs). Supports additional options listed below.false
check-dependenciesRun dcm check-dependencies (docs). Supports additional options listed below.false
check-exports-completenessRun dcm check-exports-completeness (docs).false
check-parametersRun dcm check-parameters (docs). Supports additional options listed below.false
check-unused-codeRun dcm check-unused-code (docs). Supports additional options listed below.false
check-unused-filesRun dcm check-unused-files (docs).false
check-unused-l10nRun dcm check-unused-l10n (docs). Supports additional options listed below.false
### Analyze Assets:
sizeSize limit for image assets (docs). Supported formats: 10KB, 1MB, 100B, etc.500KB
webpRequire converting .jpg and .png images to .webp (docs).false
namingRequired naming convention for image assets (pascal, kebab or snake) (docs).
resolutionFind missing or incorrect resolution-aware image assets (docs).true
allowed-formatsList of allowed formats for particular folders (e.g. icons:svg,img:jpg) (docs).
### Analyze Widgets:
show-similarityInclude similar widgets into the report (docs).false
similarity-thresholdSet a minimum threshold after which widgets are considered similar.0.2
### Check Code Duplication:
per-packageCompare code for duplications only within one package (docs).false
exclude-overridesExclude methods marked with @override (docs).false
statements-thresholdMinimum number of statements inside a declaration block (docs).3
### Check Dependencies:
ignored-packagesPackage names that should be ignored (docs).
### Check Parameters:
show-same-valueInclude parameters that always get the same constant argument (docs).false
show-unused-default-valueInclude parameters with default values that always get an argument (docs).false
show-redundantInclude parameters whose values are always passed with another parameter (docs).false
show-unused-vftInclude @visibleForTesting parameters that are never used in tests (docs).false
show-broad-typesInclude parameters whose types can be made more specific (docs).false
### Check Unused Code:
no-exclude-overriddenDo not treat overridden members as always used (docs).false
### Check Unused L10n:
class-patternRegular expression for class names to detect classes that provide localization (for example, ^AppLocalizations$).^AppLocalizations$

Outputs

Action Console

Action console

PR Summary

PR summary

PR Comment

PR comment

Footnotes

  1. Required if you have a private GitHub repository in the package dependencies.