diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml index 83341576..02746ba3 100644 --- a/.github/workflows/cpp-linter.yml +++ b/.github/workflows/cpp-linter.yml @@ -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 diff --git a/.github/workflows/mkdocs-deploy.yml b/.github/workflows/mkdocs-deploy.yml index 7ca30a6f..8f178fd4 100644 --- a/.github/workflows/mkdocs-deploy.yml +++ b/.github/workflows/mkdocs-deploy.yml @@ -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' diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml deleted file mode 100644 index 00ad109a..00000000 --- a/.github/workflows/publish-pypi.yml +++ /dev/null @@ -1,51 +0,0 @@ -# This workflow will upload a Python Package using Twine when a release is created -# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries - -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: Upload Python Package - -on: - release: - branches: [master] - types: [published] - workflow_dispatch: - -permissions: - contents: read - -jobs: - deploy: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - # use fetch --all for setuptools_scm to work - with: - fetch-depth: 0 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.x' - - name: Install dependencies - run: python -m pip install --upgrade pip twine - - name: Build wheel - run: python -m pip wheel -w dist --no-deps . - - name: Check distribution - run: twine check dist/* - - name: Publish package (to TestPyPI) - if: github.event_name == 'workflow_dispatch' && github.repository == 'cpp-linter/cpp-linter-action' - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }} - run: twine upload --repository testpypi dist/* - - name: Publish package (to PyPI) - if: github.event_name != 'workflow_dispatch' && github.repository == 'cpp-linter/cpp-linter-action' - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} - run: twine upload dist/* diff --git a/.github/workflows/run-dev-tests.yml b/.github/workflows/run-dev-tests.yml index ae17ce5d..8edd2839 100644 --- a/.github/workflows/run-dev-tests.yml +++ b/.github/workflows/run-dev-tests.yml @@ -1,4 +1,4 @@ -name: "Check python code" +name: "Test python code" on: push: diff --git a/.github/workflows/pre-commit-hooks.yml b/.github/workflows/run-pre-commit.yml similarity index 100% rename from .github/workflows/pre-commit-hooks.yml rename to .github/workflows/run-pre-commit.yml diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml index a2f7ff7a..17296672 100644 --- a/.github/workflows/run-test.yml +++ b/.github/workflows/run-test.yml @@ -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: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..a0cbdc8d --- /dev/null +++ b/CONTRIBUTING.md @@ -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). diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index fbb6128b..00000000 --- a/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -FROM xianpengshen/clang-tools:all - -# WORKDIR option is set by the github action to the environment variable GITHUB_WORKSPACE. -# See https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions#workdir - - -LABEL com.github.actions.name="cpp-linter check" -LABEL com.github.actions.description="Lint your code with clang-tidy in parallel to your builds" -LABEL com.github.actions.icon="code" -LABEL com.github.actions.color="gray-dark" - -LABEL repository="https://github.com/cpp-linter/cpp-linter-action" -LABEL maintainer="shenxianpeng <20297606+shenxianpeng@users.noreply.github.com>" - -RUN apt-get update && apt-get -y install python3-pip - -COPY cpp_linter/ pkg/cpp_linter/ -COPY pyproject.toml pkg/pyproject.toml -RUN python3 -m pip install pkg/ - -# github action args use the CMD option -# See https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runsargs -# also https://docs.docker.com/engine/reference/builder/#cmd -ENTRYPOINT [ "python3", "-m", "cpp_linter.run" ] diff --git a/README.md b/README.md index b854411e..2b13e00d 100644 --- a/README.md +++ b/README.md @@ -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 }} @@ -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` @@ -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 ### 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) @@ -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) diff --git a/action.yml b/action.yml index 62673c57..ce226644 100644 --- a/action.yml +++ b/action.yml @@ -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 }}