Skip to content

Commit bfc328f

Browse files
authored
Change action from docker to composite (#83)
* 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
1 parent 8e8e8f7 commit bfc328f

10 files changed

+79
-209
lines changed

.github/workflows/cpp-linter.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v3
14-
- uses: cpp-linter/cpp-linter-action@master
14+
- uses: cpp-linter/cpp-linter-action@main
1515
id: linter
16+
continue-on-error: true
1617
env:
1718
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1819
with:
1920
style: file
21+
files-changed-only: false
2022

2123
- name: Fail fast?!
22-
if: steps.linter.outputs.checks-failed > 0
24+
if: steps.linter.outputs.checks-failed != 0
2325
run: |
24-
echo "Some files failed the linting checks!"
26+
echo "some linter checks failed. ${{ steps.linter.outputs.checks-failed }}"
2527
# for actual deployment
2628
# run: exit 1

.github/workflows/mkdocs-deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
- name: Install python action for doc extraction
1616
run: pip install . -r docs/requirements.txt
1717
- name: check mkdocs build
18-
if: github.ref != 'refs/heads/master'
18+
if: github.ref != 'refs/heads/main'
1919
run: mkdocs build
2020
- name: Build docs and deploy to gh-pages
21-
if: github.ref == 'refs/heads/master'
21+
if: github.ref == 'refs/heads/main'
2222
run: |
2323
git config user.name 'github-actions'
2424
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'

.github/workflows/publish-pypi.yml

Lines changed: 0 additions & 51 deletions
This file was deleted.

.github/workflows/run-dev-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Check python code"
1+
name: "Test python code"
22

33
on:
44
push:

.github/workflows/run-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ name: "Test action and package"
22

33
on:
44
push:
5-
branches: master
5+
branches: main
66
paths-ignore: "docs/**"
77
pull_request:
8-
branches: master
8+
branches: main
99
paths-ignore: "docs/**"
1010

1111
jobs:

CONTRIBUTING.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Contributing
2+
3+
Thank you for investing your time in contributing to our project! We welcome feedback, bug reports, and pull requests!
4+
5+
## New contributor guide
6+
7+
Ours develop branch is `main` not `master` (`master` used to be the develop branch for v1.x).
8+
9+
The reason we didn't delete the `master` branch is that there are still users whose workflows point to the `master` branch.
10+
11+
For pull requests, please stick to the following guidelines
12+
13+
* Add tests for any new features and bug fixes.
14+
* Put a reasonable amount of comments into the code.
15+
* 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.
16+
* Separate unrelated changes into multiple pull requests.
17+
18+
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.
19+
20+
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).

Dockerfile

Lines changed: 0 additions & 24 deletions
This file was deleted.

README.md

Lines changed: 23 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,40 @@
77
[![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)
88
[![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)
99
![GitHub](https://img.shields.io/github/license/cpp-linter/cpp-linter-action?label=license&logo=github&style=flat-square)
10-
[![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)
10+
[![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)
1111

1212
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.
1313

14+
## What's New
15+
16+
v2
17+
18+
* Change action from using docker to composite steps
19+
* improve workflow runs times from 1m 24s (currently) to 6-20s.
20+
* better support for the database input option (which is currently broken with the docker env).
21+
* better support cross-compilation
22+
* better support 3rd party libraries
23+
* Includes many issues and enhancements. See [#87](https://github.com/cpp-linter/cpp-linter-action/issues/87) for details.
24+
25+
Refer [here](https://github.com/cpp-linter/cpp-linter-action/tree/v1) for previous versions.
26+
1427
## Usage
1528

16-
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)
29+
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)
1730

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

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

25-
on:
26-
pull_request:
27-
types: [opened, reopened] # let PR-synchronize events be handled by push events
28-
push:
36+
on: pull_request
2937

3038
jobs:
3139
cpp-linter:
3240
runs-on: ubuntu-latest
3341
steps:
3442
- uses: actions/checkout@v3
35-
- uses: cpp-linter/cpp-linter-action@v1
43+
- uses: cpp-linter/cpp-linter-action@v2
3644
id: linter
3745
env:
3846
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -74,9 +82,9 @@ jobs:
7482

7583
#### `version`
7684

77-
- **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.
85+
- **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.
7886
- Set this option to a blank string (`''`) to use the platform's default installed version.
79-
- 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)).
87+
- This value can also be a path to where the clang tools are installed (if using a custom install location).
8088
- Default: '12'
8189

8290
#### `verbosity`
@@ -130,119 +138,25 @@ jobs:
130138
#### `database`
131139

132140
- **Description**: The directory containing compilation database (like compile_commands.json) file.
133-
- 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).
134141
- Default: ''
135142

136143
### Outputs
137144

138145
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.
139146

140-
## Running without the docker container
141-
142-
Some Continuous Integration environments require access to non-default compilers
143-
and/or non-standard libraries. To do this properly, the docker container should
144-
not be used due to it's isolated file system. Instead, you should use this action's
145-
python source code as an installed python package (see below).
146-
147-
### Using the python source code
148-
149-
This action was originally designed to only be used on a runner with the Ubuntu
150-
Operating System. However, this action's source code (essentially a python package)
151-
can be used on any runner using the Windows, Ubuntu, or possibly even MacOS (untested)
152-
virtual environments.
153-
154-
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:
155-
156-
- `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).
157-
- `windows-latest` ships with v13. [More details](https://github.com/actions/virtual-environments/blob/win22/20220511.2/images/win/Windows2022-Readme.md).
158-
- `macos-latest` ships with v13. [More details](https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md).
159-
160-
This example makes use of another action
161-
([KyleMayes/install-llvm-action](https://github.com/KyleMayes/install-llvm-action))
162-
to install a certain version of clang-tidy and clang-format.
163-
164-
```yml
165-
on:
166-
pull_request:
167-
types: [opened, reopened] # let PR-synchronize events be handled by push events
168-
push:
169-
170-
jobs:
171-
cpp-linter:
172-
runs-on: windows-latest
173-
174-
steps:
175-
- uses: actions/checkout@v3
176-
- uses: actions/setup-python@v4
177-
178-
# this step can be skipped if the desired
179-
# version already comes with the runner's OS
180-
- name: Install clang-tools
181-
uses: KyleMayes/install-llvm-action@v1
182-
with:
183-
# v13 is the recommended minimum for the Visual Studio compiler (on Windows)
184-
version: 14
185-
# specifying an install path is required (on Windows) because installing
186-
# multiple versions on Windows runners needs non-default install paths.
187-
directory: ${{ runner.temp }}/llvm
188-
189-
- name: Install linter python package
190-
run: python3 -m pip install git+https://github.com/cpp-linter/cpp-linter-action@v1
191-
192-
- name: run linter as a python package
193-
id: linter
194-
# Pass the installed path to the '--version' argument.
195-
# Alternatively, pass the version number.
196-
# Example. run: cpp-linter --version=14
197-
# Omit the version option if using the default version available in the OS.
198-
run: cpp-linter --version=${{ runner.temp }}/llvm
199-
200-
- name: Fail fast?!
201-
if: steps.linter.outputs.checks-failed > 0
202-
run: echo "Some files failed the linting checks!"
203-
# for actual deployment
204-
# run: exit 1
205-
```
206-
207-
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:
208-
209-
```yaml
210-
- uses: cpp-linter/cpp-linter-action@v1
211-
with:
212-
style: file
213-
tidy-checks: '-*'
214-
files-changed-only: false
215-
ignore: 'dist/third-party-lib'
216-
```
217-
218-
is equivalent to
219-
220-
```yaml
221-
- name: Install linter python package
222-
run: python3 -m pip install git+https://github.com/cpp-linter/cpp-linter-action@v1
223-
224-
- name: run linter as a python package
225-
run: |
226-
cpp-linter \
227-
--style=file \
228-
--tidy-checks='-*' \
229-
--files-changed-only=false \
230-
--ignore='dist/third-party-lib'
231-
```
232-
233147
## Example
234148

235149
<!--intro-end-->
236150

237151
### Annotations
238152

239-
![clang-format annotations](https://github.com/raw/cpp-linter/cpp-linter-action/master/docs/images/annotations-clang-format.png)
153+
![clang-format annotations](https://github.com/raw/cpp-linter/cpp-linter-action/main/docs/images/annotations-clang-format.png)
240154

241-
![clang-tidy annotations](https://github.com/raw/cpp-linter/cpp-linter-action/master/docs/images/annotations-clang-tidy.png)
155+
![clang-tidy annotations](https://github.com/raw/cpp-linter/cpp-linter-action/main/docs/images/annotations-clang-tidy.png)
242156

243157
### Thread Comment
244158

245-
![sample comment](https://github.com/raw/cpp-linter/cpp-linter-action/master/docs/images/comment.png)
159+
![sample comment](https://github.com/raw/cpp-linter/cpp-linter-action/main/docs/images/comment.png)
246160

247161
<!--footer-start-->
248162

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

265179
## License
266180

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

269183
<!--footer-end-->

action.yml

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,30 @@ inputs:
7777
outputs:
7878
checks-failed:
7979
description: An integer that can be used as a boolean value to indicate if all checks failed.
80+
value: ${{ steps.cpp-linter.outputs.checks-failed }}
8081
runs:
81-
using: "docker"
82-
image: "Dockerfile"
83-
env:
84-
USING_CLANG_TOOLS_DOCKER: 'true'
85-
args:
86-
- --style=${{ inputs.style }}
87-
- --extensions=${{ inputs.extensions }}
88-
- --tidy-checks=${{ inputs.tidy-checks }}
89-
- --repo-root=${{ inputs.repo-root }}
90-
- --version=${{ inputs.version }}
91-
- --verbosity=${{ inputs.verbosity }}
92-
- --lines-changed-only=${{ inputs.lines-changed-only }}
93-
- --files-changed-only=${{ inputs.files-changed-only }}
94-
- --thread-comments=${{ inputs.thread-comments }}
95-
- --ignore=${{ inputs.ignore }}
96-
- --database=${{ inputs.database }}
97-
- --file-annotations=${{ inputs.file-annotations }}
82+
using: "composite"
83+
steps:
84+
- name: Install action dependencies
85+
shell: bash
86+
run: python3 -m pip install clang-tools cpp-linter
87+
- name: Install clang-tools binary executables
88+
shell: bash
89+
run: clang-tools -i ${{ inputs.version }} -b
90+
- name: Run cpp-linter
91+
id: cpp-linter
92+
shell: bash
93+
run: |
94+
cpp-linter \
95+
--style="${{ inputs.style }}" \
96+
--extensions=${{ inputs.extensions }} \
97+
--tidy-checks="${{ inputs.tidy-checks }}" \
98+
--repo-root=${{ inputs.repo-root }} \
99+
--version=${{ inputs.version }} \
100+
--verbosity=${{ inputs.verbosity }} \
101+
--lines-changed-only=${{ inputs.lines-changed-only }} \
102+
--files-changed-only=${{ inputs.files-changed-only }} \
103+
--thread-comments=${{ inputs.thread-comments }} \
104+
--ignore="${{ inputs.ignore }}" \
105+
--database=${{ inputs.database }} \
106+
--file-annotations=${{ inputs.file-annotations }}

0 commit comments

Comments
 (0)