Skip to content

Commit

Permalink
Change action from docker to composite (#83)
Browse files Browse the repository at this point in the history
* Change action from docker to composite
* Remove Dockerfile
* install cpp-linter pkg from PyPI
* Remove publish-pypi.yml #91
* Switch from master to main branch
* Add CONTRIBUTING.md
  • Loading branch information
shenxianpeng authored Sep 1, 2022
1 parent 8e8e8f7 commit bfc328f
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 209 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/cpp-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cpp-linter/cpp-linter-action@master
- uses: cpp-linter/cpp-linter-action@main
id: linter
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
style: file
files-changed-only: false

- name: Fail fast?!
if: steps.linter.outputs.checks-failed > 0
if: steps.linter.outputs.checks-failed != 0
run: |
echo "Some files failed the linting checks!"
echo "some linter checks failed. ${{ steps.linter.outputs.checks-failed }}"
# for actual deployment
# run: exit 1
4 changes: 2 additions & 2 deletions .github/workflows/mkdocs-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
- name: Install python action for doc extraction
run: pip install . -r docs/requirements.txt
- name: check mkdocs build
if: github.ref != 'refs/heads/master'
if: github.ref != 'refs/heads/main'
run: mkdocs build
- name: Build docs and deploy to gh-pages
if: github.ref == 'refs/heads/master'
if: github.ref == 'refs/heads/main'
run: |
git config user.name 'github-actions'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
Expand Down
51 changes: 0 additions & 51 deletions .github/workflows/publish-pypi.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/run-dev-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Check python code"
name: "Test python code"

on:
push:
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: "Test action and package"

on:
push:
branches: master
branches: main
paths-ignore: "docs/**"
pull_request:
branches: master
branches: main
paths-ignore: "docs/**"

jobs:
Expand Down
20 changes: 20 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Contributing

Thank you for investing your time in contributing to our project! We welcome feedback, bug reports, and pull requests!

## New contributor guide

Ours develop branch is `main` not `master` (`master` used to be the develop branch for v1.x).

The reason we didn't delete the `master` branch is that there are still users whose workflows point to the `master` branch.

For pull requests, please stick to the following guidelines

* Add tests for any new features and bug fixes.
* Put a reasonable amount of comments into the code.
* Fork cpp-linter-action on your GitHub user account, do your changes there and then create a PR against `main` branch of cpp-linter-action repository.
* Separate unrelated changes into multiple pull requests.

If you wish to contribute to the python source package used by this action, then that has moved to it's own repository named [cpp-linter](https://github.com/cpp-linter/cpp-linter) as of v2 of this action.

Please note that by contributing any code or documentation to this repository (by raising pull requests, or otherwise) you explicitly agree to the [License Agreement](LICENSE).
24 changes: 0 additions & 24 deletions Dockerfile

This file was deleted.

132 changes: 23 additions & 109 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,40 @@
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/cpp-linter/cpp-linter-action/cpp-linter?label=cpp-linter&logo=Github&style=flat-square)](https://github.com/cpp-linter/cpp-linter-action/actions/workflows/cpp-linter.yml)
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/cpp-linter/cpp-linter-action/MkDocs%20Deploy?label=docs&logo=Github&style=flat-square)](https://github.com/cpp-linter/cpp-linter-action/actions/workflows/mkdocs-deploy.yml)
![GitHub](https://img.shields.io/github/license/cpp-linter/cpp-linter-action?label=license&logo=github&style=flat-square)
[![codecov](https://codecov.io/gh/cpp-linter/cpp-linter-action/branch/master/graph/badge.svg?token=4SF7UEDEZ2)](https://codecov.io/gh/cpp-linter/cpp-linter-action)
[![codecov](https://codecov.io/gh/cpp-linter/cpp-linter-action/branch/main/graph/badge.svg?token=4SF7UEDEZ2)](https://codecov.io/gh/cpp-linter/cpp-linter-action)

A Github Action for linting C/C++ code integrating clang-tidy and clang-format to collect feedback provided in the form of thread comments and/or annotations.

## What's New

v2

* Change action from using docker to composite steps
* improve workflow runs times from 1m 24s (currently) to 6-20s.
* better support for the database input option (which is currently broken with the docker env).
* better support cross-compilation
* better support 3rd party libraries
* Includes many issues and enhancements. See [#87](https://github.com/cpp-linter/cpp-linter-action/issues/87) for details.

Refer [here](https://github.com/cpp-linter/cpp-linter-action/tree/v1) for previous versions.

## Usage

Create a new GitHub Actions workflow in your project, e.g. at [.github/workflows/cpp-linter.yml](https://github.com/cpp-linter/cpp-linter-action/blob/master/.github/workflows/cpp-linter.yml)
Create a new GitHub Actions workflow in your project, e.g. at [.github/workflows/cpp-linter.yml](https://github.com/cpp-linter/cpp-linter-action/blob/main/.github/workflows/cpp-linter.yml)

The content of the file should be in the following format.

```yaml
# Workflow syntax:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
name: cpp-linter

on:
pull_request:
types: [opened, reopened] # let PR-synchronize events be handled by push events
push:
on: pull_request

jobs:
cpp-linter:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cpp-linter/cpp-linter-action@v1
- uses: cpp-linter/cpp-linter-action@v2
id: linter
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -74,9 +82,9 @@ jobs:

#### `version`

- **Description**: The desired version of the [clang-tools](https://hub.docker.com/r/xianpengshen/clang-tools) to use. Accepted options are strings which can be 14, 13, 12, 11, 10, 9, or 8.
- **Description**: The desired version of the [clang-tools](https://github.com/cpp-linter/clang-tools-pip) to use. Accepted options are strings which can be 14, 13, 12, 11, 10, 9, 8,7, 6, 5, 4 or 3.9.
- Set this option to a blank string (`''`) to use the platform's default installed version.
- This value can also be a path to where the clang tools are installed (if using a custom install location). Because all paths specified here are converted to absolute, using a relative path as a value may not be compatible when using the docker environment (see [Running without the docker container](#running-without-the-docker-container)).
- This value can also be a path to where the clang tools are installed (if using a custom install location).
- Default: '12'

#### `verbosity`
Expand Down Expand Up @@ -130,119 +138,25 @@ jobs:
#### `database`

- **Description**: The directory containing compilation database (like compile_commands.json) file.
- This option doesn't seems to work properly from the docker environment. Instead we recommend using this option when see [running without the docker container](#running-without-the-docker-container).
- Default: ''

### Outputs

This action creates 1 output variable named `checks-failed`. Even if the linting checks fail for source files this action will still pass, but users' CI workflows can use this action's output to exit the workflow early if that is desired.

## Running without the docker container

Some Continuous Integration environments require access to non-default compilers
and/or non-standard libraries. To do this properly, the docker container should
not be used due to it's isolated file system. Instead, you should use this action's
python source code as an installed python package (see below).

### Using the python source code

This action was originally designed to only be used on a runner with the Ubuntu
Operating System. However, this action's source code (essentially a python package)
can be used on any runner using the Windows, Ubuntu, or possibly even MacOS (untested)
virtual environments.

Note, some runners already ship with clang-format and/or clang-tidy. As of this writing, the following versions of clang-format and clang-tidy are already available:

- `ubuntu-latest` ships with v10, v11, and v12. [More details](https://github.com/actions/virtual-environments/blob/ubuntu20/20220508.1/images/linux/Ubuntu2004-Readme.md).
- `windows-latest` ships with v13. [More details](https://github.com/actions/virtual-environments/blob/win22/20220511.2/images/win/Windows2022-Readme.md).
- `macos-latest` ships with v13. [More details](https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md).

This example makes use of another action
([KyleMayes/install-llvm-action](https://github.com/KyleMayes/install-llvm-action))
to install a certain version of clang-tidy and clang-format.

```yml
on:
pull_request:
types: [opened, reopened] # let PR-synchronize events be handled by push events
push:

jobs:
cpp-linter:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4

# this step can be skipped if the desired
# version already comes with the runner's OS
- name: Install clang-tools
uses: KyleMayes/install-llvm-action@v1
with:
# v13 is the recommended minimum for the Visual Studio compiler (on Windows)
version: 14
# specifying an install path is required (on Windows) because installing
# multiple versions on Windows runners needs non-default install paths.
directory: ${{ runner.temp }}/llvm

- name: Install linter python package
run: python3 -m pip install git+https://github.com/cpp-linter/cpp-linter-action@v1

- name: run linter as a python package
id: linter
# Pass the installed path to the '--version' argument.
# Alternatively, pass the version number.
# Example. run: cpp-linter --version=14
# Omit the version option if using the default version available in the OS.
run: cpp-linter --version=${{ runner.temp }}/llvm

- name: Fail fast?!
if: steps.linter.outputs.checks-failed > 0
run: echo "Some files failed the linting checks!"
# for actual deployment
# run: exit 1
```

All input options listed above are specified by pre-pending a `--`. You can also install this repo locally and run `cpp-linter -h` for more detail. For example:

```yaml
- uses: cpp-linter/cpp-linter-action@v1
with:
style: file
tidy-checks: '-*'
files-changed-only: false
ignore: 'dist/third-party-lib'
```
is equivalent to
```yaml
- name: Install linter python package
run: python3 -m pip install git+https://github.com/cpp-linter/cpp-linter-action@v1

- name: run linter as a python package
run: |
cpp-linter \
--style=file \
--tidy-checks='-*' \
--files-changed-only=false \
--ignore='dist/third-party-lib'
```
## Example

<!--intro-end-->

### Annotations

![clang-format annotations](https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/master/docs/images/annotations-clang-format.png)
![clang-format annotations](https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/annotations-clang-format.png)

![clang-tidy annotations](https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/master/docs/images/annotations-clang-tidy.png)
![clang-tidy annotations](https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/annotations-clang-tidy.png)

### Thread Comment

![sample comment](https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/master/docs/images/comment.png)
![sample comment](https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/comment.png)

<!--footer-start-->

Expand All @@ -264,6 +178,6 @@ To provide feedback (requesting a feature or reporting a bug) please post to [is

## License

The scripts and documentation in this project are released under the [MIT License](https://github.com/cpp-linter/cpp-linter-action/blob/master/LICENSE)
The scripts and documentation in this project are released under the [MIT License](https://github.com/cpp-linter/cpp-linter-action/blob/main/LICENSE)

<!--footer-end-->
43 changes: 26 additions & 17 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,30 @@ inputs:
outputs:
checks-failed:
description: An integer that can be used as a boolean value to indicate if all checks failed.
value: ${{ steps.cpp-linter.outputs.checks-failed }}
runs:
using: "docker"
image: "Dockerfile"
env:
USING_CLANG_TOOLS_DOCKER: 'true'
args:
- --style=${{ inputs.style }}
- --extensions=${{ inputs.extensions }}
- --tidy-checks=${{ inputs.tidy-checks }}
- --repo-root=${{ inputs.repo-root }}
- --version=${{ inputs.version }}
- --verbosity=${{ inputs.verbosity }}
- --lines-changed-only=${{ inputs.lines-changed-only }}
- --files-changed-only=${{ inputs.files-changed-only }}
- --thread-comments=${{ inputs.thread-comments }}
- --ignore=${{ inputs.ignore }}
- --database=${{ inputs.database }}
- --file-annotations=${{ inputs.file-annotations }}
using: "composite"
steps:
- name: Install action dependencies
shell: bash
run: python3 -m pip install clang-tools cpp-linter
- name: Install clang-tools binary executables
shell: bash
run: clang-tools -i ${{ inputs.version }} -b
- name: Run cpp-linter
id: cpp-linter
shell: bash
run: |
cpp-linter \
--style="${{ inputs.style }}" \
--extensions=${{ inputs.extensions }} \
--tidy-checks="${{ inputs.tidy-checks }}" \
--repo-root=${{ inputs.repo-root }} \
--version=${{ inputs.version }} \
--verbosity=${{ inputs.verbosity }} \
--lines-changed-only=${{ inputs.lines-changed-only }} \
--files-changed-only=${{ inputs.files-changed-only }} \
--thread-comments=${{ inputs.thread-comments }} \
--ignore="${{ inputs.ignore }}" \
--database=${{ inputs.database }} \
--file-annotations=${{ inputs.file-annotations }}

0 comments on commit bfc328f

Please sign in to comment.