├── .github ├── renovate.json └── workflows │ ├── reviewdog.yml │ ├── depup.yml │ └── release.yml ├── testdata └── test.yml ├── LICENSE ├── script.sh ├── action.yml └── README.md /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ], 5 | "labels": [ 6 | "bump:patch" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /testdata/test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Test Ansible PlayBook 3 | hosts: all 4 | 5 | tasks: 6 | - name: Test Command 7 | command: ls -la 8 | - name: Test Shell 9 | shell: ls 10 | 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 takezyou 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/workflows/reviewdog.yml: -------------------------------------------------------------------------------- 1 | name: reviewdog 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | jobs: 8 | ansible-lint: 9 | name: runner / ansible-lint 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 13 | 14 | - uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0 15 | with: 16 | python-version: "3.13" 17 | 18 | - name: ansible-lint github-pr-check 19 | uses: ./ 20 | with: 21 | github_token: ${{ secrets.github_token }} 22 | reporter: github-pr-check 23 | ansiblelint_flags: "testdata/test.yml" 24 | 25 | - name: ansible-lint github-check 26 | uses: ./ 27 | with: 28 | github_token: ${{ secrets.github_token }} 29 | reporter: github-check 30 | level: warning 31 | ansiblelint_flags: "testdata/test.yml" 32 | 33 | - name: ansible-lint github-pr-review 34 | uses: ./ 35 | with: 36 | github_token: ${{ secrets.github_token }} 37 | reporter: github-pr-review 38 | ansiblelint_flags: "testdata/test.yml" 39 | -------------------------------------------------------------------------------- /script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd "${GITHUB_WORKSPACE}/${INPUT_WORKING_DIRECTORY}" || exit 4 | 5 | TEMP_PATH="$(mktemp -d)" 6 | PATH="${TEMP_PATH}:$PATH" 7 | 8 | echo '::group::🐶 Installing reviewdog ... https://github.com/reviewdog/reviewdog' 9 | curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/fd59714416d6d9a1c0692d872e38e7f8448df4fc/install.sh | sh -s -- -b "${TEMP_PATH}" "${REVIEWDOG_VERSION}" 2>&1 10 | echo '::endgroup::' 11 | 12 | echo '::group:: Installing ansible-lint ... https://github.com/ansible/ansible-lint' 13 | pip3 install --no-cache-dir ansible-lint=="${INPUT_ANSIBLELINT_VERSION}" "ansible>=2.9,<2.11" 14 | echo '::endgroup::' 15 | 16 | export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" 17 | 18 | echo '::group:: Running ansible-lint with reviewdog 🐶 ...' 19 | ansible-lint -p ${INPUT_ANSIBLELINT_FLAGS} \ 20 | | reviewdog -efm="%f:%l: %m" \ 21 | -name="ansible-lint" \ 22 | -reporter="${INPUT_REPORTER:-github-pr-check}" \ 23 | -level="${INPUT_LEVEL}" \ 24 | -filter-mode="${INPUT_FILTER_MODE}" \ 25 | -fail-level="${INPUT_FAIL_LEVEL}" \ 26 | -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ 27 | ${INPUT_REVIEWDOG_FLAGS} 28 | exit_code=$? 29 | echo '::endgroup::' 30 | 31 | exit $exit_code 32 | -------------------------------------------------------------------------------- /.github/workflows/depup.yml: -------------------------------------------------------------------------------- 1 | name: depup 2 | on: 3 | schedule: 4 | - cron: '14 14 * * *' # Runs at 14:14 UTC every day 5 | repository_dispatch: 6 | types: [depup] 7 | workflow_dispatch: 8 | 9 | jobs: 10 | reviewdog: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 14 | - uses: haya14busa/action-depup@94a1aaf4e4923064019214b48a43276218af7ad5 # v1.6.4 15 | id: depup 16 | with: 17 | file: action.yml 18 | version_name: REVIEWDOG_VERSION 19 | repo: reviewdog/reviewdog 20 | 21 | - name: Create Pull Request 22 | uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8 23 | with: 24 | token: ${{ secrets.GITHUB_TOKEN }} 25 | title: "chore(deps): update reviewdog to ${{ steps.depup.outputs.latest }}" 26 | commit-message: "chore(deps): update reviewdog to ${{ steps.depup.outputs.latest }}" 27 | body: | 28 | Update reviewdog to [v${{ steps.depup.outputs.latest }}](https://github.com/reviewdog/reviewdog/releases/tag/v${{ steps.depup.outputs.latest }}) 29 | Compare [v${{ steps.depup.outputs.current }}...v${{ steps.depup.outputs.latest }}](https://github.com/reviewdog/reviewdog/compare/v${{ steps.depup.outputs.current }}...v${{ steps.depup.outputs.latest }}) 30 | This PR is auto generated by [depup workflow](https://github.com/${{ github.repository }}/actions?query=workflow%3Adepup). 31 | branch: depup/reviewdog 32 | base: master 33 | labels: "bump:minor" 34 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | on: 3 | push: 4 | branches: 5 | - master 6 | tags: 7 | - 'v*.*.*' 8 | pull_request: 9 | types: 10 | - labeled 11 | 12 | jobs: 13 | release: 14 | if: github.event.action != 'labeled' 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 18 | 19 | # Bump version on merging Pull Requests with specific labels. 20 | # (bump:major,bump:minor,bump:patch) 21 | - id: bumpr 22 | if: "!startsWith(github.ref, 'refs/tags/')" 23 | uses: haya14busa/action-bumpr@78ab5a104d20896c9c9122c64221b3aecf1a8cbb # v1.10.0 24 | 25 | # Update corresponding major and minor tag. 26 | # e.g. Update v1 and v1.2 when releasing v1.2.3 27 | - uses: haya14busa/action-update-semver@fb48464b2438ae82cc78237be61afb4f461265a1 # v1.2.1 28 | if: "!steps.bumpr.outputs.skip" 29 | with: 30 | tag: ${{ steps.bumpr.outputs.next_version }} 31 | 32 | # Get tag name. 33 | - id: tag 34 | uses: haya14busa/action-cond@94f77f7a80cd666cb3155084e428254fea4281fd # v1.2.1 35 | with: 36 | cond: "${{ startsWith(github.ref, 'refs/tags/') }}" 37 | if_true: ${{ github.ref }} 38 | if_false: ${{ steps.bumpr.outputs.next_version }} 39 | 40 | # Create release. 41 | - if: "steps.tag.outputs.value != ''" 42 | env: 43 | TAG_NAME: ${{ steps.tag.outputs.value }} 44 | BODY: ${{ steps.bumpr.outputs.message }} 45 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 46 | run: | 47 | gh release create "${TAG_NAME}" -t "Release ${TAG_NAME/refs\/tags\//}" --notes "${BODY}" 48 | 49 | release-check: 50 | if: github.event.action == 'labeled' 51 | runs-on: ubuntu-latest 52 | steps: 53 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 54 | - name: Post bumpr status comment 55 | uses: haya14busa/action-bumpr@78ab5a104d20896c9c9122c64221b3aecf1a8cbb # v1.10.0 56 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: "Run ansible-lint with reviewdog" 2 | description: "🐶 Run ansible-lint with reviewdog on pull requests to improve code review experience." 3 | author: "takezyou" 4 | inputs: 5 | github_token: 6 | description: "GITHUB_TOKEN" 7 | required: true 8 | default: ${{ github.token }} 9 | level: 10 | description: "Report level for reviewdog [info,warning,error]" 11 | default: "error" 12 | reporter: 13 | description: | 14 | Reporter of reviewdog command [github-pr-check,github-pr-review]. 15 | Default is github-pr-check. 16 | default: "github-pr-check" 17 | filter_mode: 18 | description: | 19 | Filtering mode for the reviewdog command [added,diff_context,file,nofilter]. 20 | Default is added. 21 | default: "added" 22 | fail_level: 23 | description: | 24 | If set to `none`, always use exit code 0 for reviewdog. 25 | Otherwise, exit code 1 for reviewdog if it finds at least 1 issue with severity greater than or equal to the given level. 26 | Possible values: [none,any,info,warning,error] 27 | Default is `none`. 28 | default: 'none' 29 | fail_on_error: 30 | description: | 31 | Deprecated, use `fail_level` instead. 32 | Exit code for reviewdog when errors are found [true,false] 33 | Default is `false`. 34 | deprecationMessage: Deprecated, use `fail_level` instead. 35 | default: "false" 36 | reviewdog_flags: 37 | description: "Additional reviewdog flags" 38 | default: "" 39 | workdir: 40 | description: "Working directory relative to the root directory." 41 | default: "." 42 | ansiblelint_version: 43 | description: "The ansible-lint version to use" 44 | default: "5.3.2" 45 | ansiblelint_flags: 46 | description: "Flags and args of ansible-lint command" 47 | default: "" 48 | 49 | runs: 50 | using: "composite" 51 | steps: 52 | - run: $GITHUB_ACTION_PATH/script.sh 53 | id: ansible-lint 54 | shell: bash 55 | env: 56 | # We may want to allow specifying reviewdog version as 57 | # action's input, but let's start with hard coded latest stable version for reviewdog 58 | REVIEWDOG_VERSION: v0.20.3 59 | # INPUT_ is not available in Composite run steps 60 | # https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611 61 | INPUT_ANSIBLELINT_VERSION: ${{ inputs.ansiblelint_version }} 62 | INPUT_ANSIBLELINT_FLAGS: ${{ inputs.ansiblelint_flags }} 63 | INPUT_GITHUB_TOKEN: ${{ inputs.github_token }} 64 | INPUT_LEVEL: ${{ inputs.level }} 65 | INPUT_REPORTER: ${{ inputs.reporter }} 66 | INPUT_FILTER_MODE: ${{ inputs.filter_mode }} 67 | INPUT_FAIL_LEVEL: ${{ inputs.fail_level }} 68 | INPUT_FAIL_ON_ERROR: ${{ inputs.fail_on_error }} 69 | INPUT_WORKING_DIRECTORY: ${{ inputs.workdir }} 70 | INPUT_REVIEWDOG_FLAGS: ${{ inputs.reviewdog_flags }} 71 | 72 | branding: 73 | icon: "check-circle" 74 | color: "orange" 75 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitHub Action: Run ansible-lint with reviewdog 🐕 2 | 3 | [![Docker Image CI](https://github.com/reviewdog/action-ansiblelint/workflows/Docker%20Image%20CI/badge.svg?branch=master)](https://github.com/reviewdog/action-ansiblelint/actions) 4 | [![Release](https://img.shields.io/github/v/release/reviewdog/action-ansiblelint?logoColor=orange)](https://github.com/reviewdog/action-ansiblelint/releases) 5 | 6 | 7 | This action runs [ansible-lint](https://github.com/ansible/ansible-lint) with 8 | [reviewdog](https://github.com/reviewdog/reviewdog) on pull requests to improve 9 | code review experience. 10 | 11 | [![github-pr-check sample](https://user-images.githubusercontent.com/20274882/90307579-67142400-df12-11ea-96e9-62710cb1fff0.png)](https://github.com/reviewdog/action-ansiblelint/pull/1) 12 | [![github-pr-review sample](https://user-images.githubusercontent.com/20274882/90307608-c70aca80-df12-11ea-9556-921f1e7e6281.png)](https://github.com/reviewdog/action-ansiblelint/pull/1) 13 | 14 | ## Inputs 15 | 16 | ### `github_token` 17 | 18 | Optional. `${{ github.token }}` is used by default. 19 | 20 | ### `level` 21 | 22 | Optional. Report level for reviewdog [info,warning,error]. 23 | It's same as `-level` flag of reviewdog. 24 | 25 | ### `reporter` 26 | 27 | Reporter of reviewdog command [github-pr-check,github-check,github-pr-review]. 28 | Default is github-pr-check. 29 | It's same as `-reporter` flag of reviewdog. 30 | 31 | github-pr-review can use Markdown and add a link to rule page in reviewdog reports. 32 | 33 | ### `filter_mode` 34 | 35 | Optional. Filtering mode for the reviewdog command [added,diff_context,file,nofilter]. Default is added. 36 | 37 | ### `fail_level` 38 | 39 | Optional. If set to `none`, always use exit code 0 for reviewdog. 40 | Otherwise, exit code 1 for reviewdog if it finds at least 1 issue with severity greater than or equal to the given level. 41 | Possible values: [`none`, `any`, `info`, `warning`, `error`] 42 | Default is `none`. 43 | 44 | ### `fail_on_error` 45 | 46 | Deprecated, use `fail_level` instead. 47 | Optional. Exit code for reviewdog when errors are found [true,false]. Default is `false`. 48 | 49 | ### `reviewdog_flags` 50 | 51 | Optional. Additional reviewdog flags. 52 | 53 | ### `ansiblelint_version` 54 | 55 | Optional. The ansible-lint version to use. Default is `5.3.2`. 56 | 57 | ### `ansiblelint_flags` 58 | 59 | Optional. Flags and args of ansible-lint command. 60 | 61 | ## Example usage 62 | 63 | You can create [ansible-lint config](https://docs.ansible.com/ansible-lint/configuring/configuring.html). 64 | 65 | ### [.github/workflows/reviewdog.yml](.github/workflows/reviewdog.yml) 66 | 67 | ```yml 68 | name: reviewdog 69 | on: [pull_request] 70 | jobs: 71 | ansible-lint: 72 | name: runner / ansible-lint 73 | runs-on: ubuntu-latest 74 | steps: 75 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 76 | - uses: actions/setup-python@e9aba2c848f5ebd159c070c61ea2c4e2b122355e # v2.3.4 77 | with: 78 | python-version: "3.6" 79 | - name: ansible-lint 80 | uses: reviewdog/action-ansiblelint@5b8ca4b12dcbcdf63d4739dacd90609abafe8924 # v1.17.0 81 | with: 82 | github_token: ${{ secrets.github_token }} 83 | reporter: github-pr-review # Change reporter. 84 | ansiblelint_flags: '-x core playbook/*' 85 | ``` 86 | --------------------------------------------------------------------------------