Style actions#
Style actions verify code and documentation quality compliance with PyAnsys guidelines.
Code style action#
This action evaluates the code quality of your project by using pre-commit or prek (a faster alternative to pre-commit).
The action installs and runs the chosen tool depending on the input
configuration. It is assumed that your project contains a
.pre-commit-config.yaml file in the root directory. The action can also
be extended to lint docker files that are contained in the docker directory
and the .devcontainer directory.
Warning
If docker lint is enabled and directories docker or .devcontainer exist, the action will fail if it doesn’t find a Dockerfile.
Important
Required GitHub Permissions
contents:
read- Required to checkout repository code when the repository is not public
Input |
Description |
Required |
Type |
Default |
|---|---|---|---|---|
python-version |
Python version used for installing and running |
False |
string |
3.11 |
use-python-cache |
Whether to use the Python cache for installing previously downloaded
libraries. If |
False |
boolean |
True |
use-prek |
Whether to use prek instead of pre-commit. If |
False |
boolean |
True |
pre-commit-version |
The version of pre-commit to install. Only used when |
False |
string |
3.8.0 |
prek-version |
The version of prek to install. Only used when |
False |
string |
0.3.2 |
docker-lint |
Extend the workflow to lint Dockerfile(s). |
False |
bool |
False |
docker-recursive |
Search for Dockerfile(s) recursively. Only applies to allowed directories, i.e. docker and .devcontainer. |
False |
bool |
False |
docker-error-level |
Fail docker-style action based on hadolint output (-1: never, 0: error, 1: warning, 2: info) |
False |
int |
2 |
skip-install |
Whether to skip the installation of the project or not. If |
False |
boolean |
True |
show-diff-on-failure |
Whether to show the diff when a pre-commit/prek hook fails. |
False |
boolean |
True |
use-uv |
Whether to use uv as the default package manager instead of pip. Default value is |
False |
boolean |
True |
checkout |
Whether to do a checkout step or not. If |
False |
boolean |
True |
Examples#
Running code style checks
code-style:
name: "Running code style checks"
runs-on: ubuntu-latest
steps:
- name: "Run PyAnsys code style checks"
uses: ansys/actions/code-style@main
Doc style action#
Check documentation style using Vale. This action is a wrapper on top of the errata-ai/vale-action.
Important
Required GitHub Permissions
contents:
read- Required to checkout repository code when the repository is not publicpull-requests:
write- Required for Vale to add review comments and suggestions on pull requests
Input |
Description |
Required |
Type |
Default |
|---|---|---|---|---|
token |
The token value used to authorize Vale to add comments and suggestions in the file section. |
True |
string |
|
files |
Path to the directory containing the documentation files. |
False |
string |
doc |
vale-config |
Path to the Vale configuration file. |
False |
string |
doc/.vale.ini |
vale-version |
Version number for Vale. |
False |
string |
3.4.1 |
tomli-version |
Tomli version used for retrieving the towncrier directory. |
False |
string |
2.2.1 |
ignore-changelogd |
Whether or not to ignore markdown files in doc/changelog.d/. |
False |
bool |
True |
checkout |
Whether to clone the repository in the CI/CD machine. Default value is
|
False |
boolean |
True |
fail-level |
Report level used to control check results. Default value is |
False |
string |
error |
Examples#
Running documentation style checks
doc-style:
name: "Running documentation style checks"
runs-on: ubuntu-latest
steps:
- name: "Running documentation style checks"
uses: ansys/actions/doc-style@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
Docker style action#
Evaluate the quality of your project Dockerfile(s) by using hadolint. This action can be used to lint Dockerfile(s) from multiple directories, see input “directory” description. The action uses hadolint-gh-action behind the scenes. If you want to evaluate multiple Dockerfiles contained in various directories of the provided directory, use the recursive option. When linting a Dockerfile dedicated to Windows, one should use hadolint shell pragma to avoid false positives from ShellCheck, see hadolint shell pragma.
Note
This action emphasizes the fact of having Dockerfile(s) contained inside the ‘docker’ directory in the root of the project.
Warning
This action only looks for docker files named Dockerfile. A docker file like Dockerfile.linux will not be linted.
Important
Required GitHub Permissions
contents:
read- Required to checkout repository code when the repository is not public
Input |
Description |
Required |
Type |
Default |
|---|---|---|---|---|
directory |
Directory from which to search for Dockerfile(s). You can pass multiple directories for processing by separating them with spaces, e.g. “docker .devcontainer”. |
False |
string |
docker |
recursive |
Search for Dockerfile(s) recursively. |
False |
bool |
False |
error-level |
Fail action based on hadolint output (-1: never, 0: error, 1: warning, 2: info) |
False |
int |
2 |
checkout |
Whether to clone the repository in the CI/CD machine. Default value is
|
False |
boolean |
True |
Examples#
Docker style
docker-style:
name: "Docker style"
runs-on: ubuntu-latest
steps:
- uses: ansys/actions/docker-style@main
with:
directory: docker
recursive: true
error-level: 1
Pull request title action#
Action that checks if the title of the pull request is following the conventional commits standard.
Important
Required GitHub Permissions
pull-requests:
read- Required to read pull request title
Input |
Description |
Required |
Type |
Default |
|---|---|---|---|---|
token |
The token value used to authorize Vale to add comments and suggestions in the file section. |
False |
string |
|
use-upper-case |
Use of uppercase letters in the “type” field of the commit. For example, “FIX!: fix server crash issue” would be a valid commit. Note Expected type are upper cases of conventional commit types. |
False |
boolean |
False |
Examples#
Check pull-request title follows conventional commits
check-pr-title:
name: "Check pull-request title follows conventional commits"
runs-on: ubuntu-latest
steps:
- uses: ansys/actions/check-pr-title@main
with:
token: ${{ secrets.GITHUB_TOKEN }}