StaticTypeCheck

This job template runs a static type check using mypy and collects the results. These results can be converted to a HTML report and uploaded as an artifact.

Instantiation

Simple Example

This example runs mypy for the Python package myPackage according to the configuration stored in pyproject.toml. It prints a report into the job’s log. In addition is generates a report in HTML format into the directory report/typing.

jobs:
  StaticTypeCheck:
    uses: pyTooling/Actions/.github/workflows/StaticTypeCheck.yml@r8
    with:
      cobertura_artifact: 'TypeChecking-Cobertura'
      junit_artifact:     'TypeChecking-JUnit'
      html_artifact:      'TypeChecking-HTML'
[tool.mypy]
packages = ["myPackage"]
strict = true
pretty = true

html_report = "report/typing/html"
junit_xml = "report/typing/StaticTypingSummary.xml"
cobertura_xml_report = "report/typing"

Complex Example

To ease the handling of mypy parameters stored in pyproject.toml, the ExtractConfiguration is used to extract the set configuration parameters for later usage. Similarly, Parameters is used to precompute the artifact’s name.

jobs:
  ConfigParams:
    uses: pyTooling/Actions/.github/workflows/ExtractConfiguration.yml@r8
    with:
      package_name: myPackage

  Params:
    uses: pyTooling/Actions/.github/workflows/Parameters.yml@r8
    with:
      package_name: myPackage

  StaticTypeCheck:
    uses: pyTooling/Actions/.github/workflows/StaticTypeCheck.yml@r8
    needs:
      - ConfigParams
      - Params
    with:
      python_version: ${{ needs.Params.outputs.python_version }}
      junit_report:   ${{ needs.ConfigParams.outputs.typing_report_junit }}
      junit_artifact: ${{ fromJson(needs.Params.outputs.artifact_names).statictyping_junit }}

Parameter Summary

Goto input parameters

Parameter Name

Required

Type

Default

ubuntu_image_version

no

string

'26.04'

python_version

no

string

'3.14'

requirements

no

string

'-r ./requirements.txt'

mypy_options

no

string

''

root_directory

no

string

'.'

tests_directory

no

string

'tests'

typing_directory

no

string

'typing'

cobertura_report

no

string (JSON)

{"fullpath": "report/typing/cobertura.xml", "directory": "report/typing", "filename": "cobertura.xml"}

junit_report

no

string (JSON)

{"fullpath": "report/typing/StaticTypingSummary.xml", "directory": "report/typing", "filename": "StaticTypingSummary.xml"}

html_report

no

string (JSON)

{"directory": "report/typing/html"}

cobertura_artifact

no

string

''

junit_artifact

no

string

''

html_artifact

no

string

''

Goto secrets

This job template needs no secrets.

Goto output parameters

This job template has no output parameters.

Input Parameters

ubuntu_image_version

Type:

string

Required:

no

Default Value:

'26.04'

Possible Values:

See actions/runner-images - Available Images for available Ubuntu image versions.

Description:

Version of the Ubuntu image used to run the job.

Note

Unfortunately, GitHub Actions has only a limited set of functions, thus, the usual Ubuntu image name like 'ubuntu-26.04' can’t be split into image name and image version.

python_version

Type:

string

Required:

no

Default Value:

'3.14'

Possible Values:

Any valid Python version conforming to the pattern <major>.<minor> or pypy-<major>.<minor>.
See actions/python-versions - available Python versions and actions/setup-python - configurable Python versions.

Description:

Python version used to run Python code in the job.

requirements

Type:

string

Required:

no

Default Value:

'-r ./requirements.txt'

Possible Values:

Any valid list of parameters for pip install.
Either a requirements file can be referenced using '-r path/to/requirements.txt', or a list of packages can be specified using a space separated list like 'mypy lxml'.

Description:

Python dependencies to be installed through pip.

A requirements file is looked up in one of two ways, depending on the path:

  • A path starting with ./ is resolved relative to the static typing directory, which is the concatenation of root_directory, tests_directory and typing_directory.
    With the defaults, '-r ./requirements.txt' refers to ./tests/typing/requirements.txt.

  • Any other path is used as given, thus relative to the repository root.

Attention

The resolved file’s existence is checked before the installation. If it is missing, the job is aborted with a FileNotFoundError annotation naming the resolved path.

mypy_options

Type:

string

Required:

no

Default Value:

''

Possible Values:

Any valid command line options for mypy.

Description:

Additional options handed over to mypy as mypy ${mypy_options}.

root_directory

Type:

string

Required:

no

Default Value:

'.'

Possible Values:

Any valid directory path relative to the repository root.

Description:

Working directory for running mypy.
It is also the first part of the directory a ./-prefixed requirements is resolved against.

Attention

The report paths (cobertura_report, junit_report, html_report) are written by mypy relative to this directory, but uploaded relative to the repository root. With a non-default value, both have to account for it.

tests_directory

Type:

string

Required:

no

Default Value:

'tests'

Possible Values:

Any valid directory path relative to root_directory.

Description:

Path to the directory containing tests.
Used only to resolve a ./-prefixed requirements.

typing_directory

Type:

string

Required:

no

Default Value:

'typing'

Possible Values:

Any valid directory path relative to tests_directory.

Description:

Path to the directory containing the static type checking tests.
Used only to resolve a ./-prefixed requirements.

cobertura_report

Type:

string (JSON)

Required:

no

Default Value:
{ "directory": "report/typing",
  "filename":  "cobertura.xml",
  "fullpath":  "report/typing/cobertura.xml"
}
Possible Values:

Any valid JSON string containing a JSON object with fields:

directory:

Directory or sub-directory where the type checking report in Cobertura XML format will be saved.

filename:

Filename of the generated type checking report in Cobertura XML format.
Currently, this filename is hardcoded within mypy as cobertura.xml.

fullpath:

The concatenation of both previous fields using the / separator.

Description:

Directory, filename and fullpath as JSON object where the type checking report in Cobertura XML format will be saved.
This path is configured in pyproject.toml and can be extracted by ExtractConfiguration.

Example:
ConfigParams:
  uses: pyTooling/Actions/.github/workflows/ExtractConfiguration.yml@r8

UnitTesting:
  uses: pyTooling/Actions/.github/workflows/StaticTypeCheck.yml@r8
  needs:
    - ConfigParams
  with:
    ...
    cobertura_report: ${{ needs.ConfigParams.outputs.statictyping_cobertura }}

junit_report

Type:

string (JSON)

Required:

no

Default Value:
{ "directory": "report/typing",
  "filename":  "StaticTypingSummary.xml",
  "fullpath":  "report/typing/StaticTypingSummary.xml"
}
Possible Values:

Any valid JSON string containing a JSON object with fields:

directory:

Directory or sub-directory where the type checking report in JUnit XML format will be saved.

filename:

Filename of the generated type checking report in JUnit XML format.
Any valid file name for mypy’s JUnit XML report.

fullpath:

The concatenation of both previous fields using the / separator.

Description:

Directory, filename and fullpath as JSON object where the type checking report in JUnit XML format will be saved.
This path is configured in pyproject.toml and can be extracted by ExtractConfiguration.

Example:
ConfigParams:
  uses: pyTooling/Actions/.github/workflows/ExtractConfiguration.yml@r8

UnitTesting:
  uses: pyTooling/Actions/.github/workflows/StaticTypeCheck.yml@r8
  needs:
    - ConfigParams
  with:
    ...
    junit_report: ${{ needs.ConfigParams.outputs.statictyping_junit }}

html_report

Type:

string (JSON)

Required:

no

Default Value:
{ "directory": "report/typing/html"
}
Possible Values:

Any valid JSON string containing a JSON object with fields:

directory:

Directory or sub-directory where the type checking report in HTML format will be saved.

Description:

Directory as JSON object where the type checking report in HTML format will be saved.
This path is configured in pyproject.toml and can be extracted by ExtractConfiguration.

Example:
ConfigParams:
  uses: pyTooling/Actions/.github/workflows/ExtractConfiguration.yml@r8

UnitTesting:
  uses: pyTooling/Actions/.github/workflows/StaticTypeCheck.yml@r8
  needs:
    - ConfigParams
  with:
    ...
    html_report: ${{ needs.ConfigParams.outputs.statictyping_html }}

cobertura_artifact

Type:

string

Required:

no

Default Value:

''

Possible Values:

Any valid artifact name.

Description:

Name of the artifact containing the Cobertura XML report.

junit_artifact

Type:

string

Required:

no

Default Value:

''

Possible Values:

Any valid artifact name.

Description:

Name of the artifact containing the JUnit XML report.

html_artifact

Type:

string

Required:

no

Default Value:

''

Possible Values:

Any valid artifact name.

Description:

Name of the artifact containing the HTML report.

Secrets

This job template needs no secrets.

Outputs

This job template has no output parameters.

Optimizations

This template offers no optimizations (reduced job runtime).