Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add lint actions #19

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/linters/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Linter actions
This folder contains the actions that can be used to lint files automatically.

### Lint commit message
This action lints commit name with [Conventional Commits](https://www.conventionalcommits.org) rules and fails if not following it.

#### Links
- [Action](./lint-commit-message.yml)

#### Source
- [wagoid/commitlint-github-action : OSS(MIT)](https://github.com/wagoid/commitlint-github-action)
- [conventional-changelog/commitlint : OSS(MIT)](https://github.com/conventional-changelog/commitlint)
- [@commitlint/config-conventional(default settings)](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional)
- [commitlint の紹介 : @ybiquitous / Qiita](https://qiita.com/ybiquitous/items/74225bc4bf0a9ddcd7dd)


### Lint pull request title
This action lints pull request title with [Conventional Commits](https://www.conventionalcommits.org) and fails if something is not valid.

#### Links
- [Action](./lint-pr-title.yml)

#### Source
- [amannn/action-semantic-pull-request : OSS(MIT)](https://github.com/amannn/action-semantic-pull-request)


### Lint target branch
This action lint the pull request target branch is not main. If the pull request target is main and not by moderator, it just fails.

#### Links
- [Action](./lint-target-branch.yml)

#### Source
- [superbrothers/close-pull-request : OSS(MIT)](https://github.com/superbrothers/close-pull-request)


### Scan with codeQL
This action scan the pull request with [codeQL](https://codeql.github.com/) and fails if something is not valid.

#### Links
- [Action](./scan-with-codeql.yml)

#### Source
- [CodeQL](https://codeql.github.com/)


### Reviewdog actions
Reviewdog is linter output tool. It posts lint result as a review at pull request. At reviewdog folder, there are many linters runs with this. But I'm sorry but they are too many and I put all sources at here.

#### Source
- [hadolint/hadolint-action : OSS(MIT)](https://github.com/hadolint/hadolint-action)
- [hadolint/hadolint : OSS(GPLv3)](https://github.com/hadolint/hadolint)
- [hadolintを利用して容易にベストプラクティスに基づいたDocker環境を構築する : @t_o_d / DevelopersIO](https://dev.classmethod.jp/articles/hadolint-docker/)
- [あなたのDockerfileはベストプラクティスに従っていますか?(ベストプラクティスとチェックツール) : @yoshii0110 / Qiita](https://qiita.com/yoshii0110/items/0accb7f21fa1c375e0d7)
- [DavidAnson/markdownlint : OSS(MIT)](https://github.com/DavidAnson/markdownlint)
- [nosborn/github-action-markdown-cli : OSS(MIT)](https://github.com/nosborn/github-action-markdown-cli)
- [TODO: Add more sources...](#)
18 changes: 18 additions & 0 deletions .github/workflows/linters/lint-commit-message.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "✒ Lint commit messages with commitlint"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
commit-lint:
name: "✒ lint commit message"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v5
17 changes: 17 additions & 0 deletions .github/workflows/linters/lint-pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "✒ Lint pull request title"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
semantic-pull-request:
name: "✒ Lint PR title"
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21 changes: 21 additions & 0 deletions .github/workflows/linters/lint-target-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "✒ Close Pull Request if it targets main"

on:
pull_request_target:
types: [opened]
branches:
- main
- master

jobs:
run:
name: "✒ Lint target branch"
runs-on: ubuntu-latest
steps:
- name: Assign variable
id: secret
run: echo '::set-output name=secret::${{secrets.MERGE_ACCEPTED_USERS}}'
- uses: superbrothers/close-pull-request@v3
if: ${{ !contains(steps.secret.outputs.secret, GITHUB_ACTOR) }}
with:
comment: "Hey! Please do not to pull request to main branch! Please try request to develop instead!"
24 changes: 24 additions & 0 deletions .github/workflows/linters/reviewdog/lint-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: "✑ Lint action with actionlint using reviewdog"

on:
pull_request_target:
types:
- opened
- synchronize
branches:
- develop
paths:
- ".github/workflows/**/*.yml"
- ".github/workflows/**/*.yaml"

jobs:
actionlint:
name: "✒ lint actions"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: reviewdog/action-actionlint@v1
with:
github_token: ${{ secrets.KIRARI_TOKEN }}
reporter: github-pr-review
level: error
27 changes: 27 additions & 0 deletions .github/workflows/linters/reviewdog/lint-dockerfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "✒ Lint dockerfile with hadolint using reviewdog"

on:
pull_request_target:
types:
- opened
- synchronize
branches:
- develop
paths:
- '**/Dockerfile'
- '*_Dockerfile'
- 'Dockerfile_*'

jobs:
hadolint:
name: "✒ lint dockerfile"
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v1
- name: hadolint
uses: reviewdog/action-hadolint@v1
with:
github_token: ${{ secrets.KIRARI_TOKEN }}
reporter: github-pr-review
level: error
26 changes: 26 additions & 0 deletions .github/workflows/linters/reviewdog/lint-dotenv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "✒ Lint dotenv with dotenv-linter using reviewdog"

on:
pull_request_target:
types:
- opened
- synchronize
branches:
- develop
paths:
- '**/.env_*'
- '**/*.env'
- '.env_*'

jobs:
dotenv-linter:
name: "✒ lint dotenv"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run dotenv-linter with code suggestions
uses: dotenv-linter/action-dotenv-linter@v2
with:
github_token: ${{ secrets.KIRARI_TOKEN }}
reporter: github-code-suggestions
level: error
23 changes: 23 additions & 0 deletions .github/workflows/linters/reviewdog/lint-markdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "✒ Lint markdown files with markdownlint using reviewdog"

on:
pull_request_target:
types:
- opened
- synchronize
branches:
- develop
paths:
- '**/*.md'

jobs:
markdownlint:
name: "✒ lint markdown"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: markdownlint
uses: reviewdog/action-markdownlint@v0
with:
github_token: ${{ secrets.KIRARI_TOKEN }}
reporter: github-pr-review
27 changes: 27 additions & 0 deletions .github/workflows/linters/reviewdog/lint-style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "✒ Lint style files with stylelint using reviewdog"

on:
pull_request_target:
types:
- opened
- synchronize
branches:
- develop
paths:
- '**/*.css'
- '**/*.scss'

jobs:
stylelint:
name: "✒ lint css/scss"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: stylelint
uses: reviewdog/action-stylelint@v1
with:
github_token: ${{ secrets.KIRARI_TOKEN }}
reporter: github-pr-review
stylelint_input:
- '**/*.css'
- '**/*.scss'
27 changes: 27 additions & 0 deletions .github/workflows/linters/reviewdog/lint-text.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "✒ Lint text files with textlint using reviewdog"

on:
pull_request_target:
types:
- opened
- synchronize
branches:
- develop
paths:
- 'docs/*.md'

jobs:
reviewdog-github-check:
name: "✒ lint text"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
- name: textlint-github-pr-review
uses: tsuyoshicho/action-textlint@v3
with:
github_token: ${{ secrets.KIRARI_TOKEN }}
reporter: github-pr-review
textlint_flags: "docs/**"
25 changes: 25 additions & 0 deletions .github/workflows/linters/reviewdog/lint-yaml.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: "✒ Lint yaml files with yamllint using reviewdog"

on:
pull_request_target:
types:
- opened
- synchronize
branches:
- develop
paths:
- "**.yml"
- "**.yaml"

jobs:
yamllint:
name: "✒ lint yaml"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: yamllint
uses: reviewdog/action-yamllint@v1
with:
github_token: ${{ secrets.KIRARI_TOKEN }}
reporter: github-pr-review
yamllint_flags: '/'
24 changes: 24 additions & 0 deletions .github/workflows/linters/reviewdog/python/lint-black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: "✑ Lint python file with black using reviewdog"

on:
pull_request_target:
types:
- opened
- synchronize
branches:
- develop
paths:
- '**/*.py'

jobs:
lint_black:
name: "✒ lint py with black"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: reviewdog/action-black@v2
with:
github_token: ${{ secrets.KIRARI_TOKEN }}
black_args: "--line-length=88"
reporter: github-pr-review
level: error
31 changes: 31 additions & 0 deletions .github/workflows/linters/reviewdog/python/lint-flake8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "✑ Lint python file with flake8 using reviewdog"

on:
pull_request_target:
types:
- opened
- synchronize
branches:
- develop
paths:
- '**/*.py'

jobs:
lint_flake8:
name: "✒ lint py with flake8"
runs-on: ubuntu-latest
name: Lint
steps:
- name: Check out source repository
uses: actions/checkout@v2
- name: Set up Python environment
uses: actions/setup-python@v2
with:
python-version: "3.8"
- name: flake8 Lint
uses: reviewdog/action-flake8@v3
with:
github_token: ${{ secrets.KIRARI_TOKEN }}
flake8_args: "--max-line-length=88"
reporter: github-pr-review
level: error
24 changes: 24 additions & 0 deletions .github/workflows/linters/reviewdog/python/lint-mypy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: "✑ Lint python file with mypy using reviewdog"

on:
pull_request_target:
types:
- opened
- synchronize
branches:
- develop
paths:
- '**/*.py'

jobs:
lint_mypy:
name: "✒ lint py with mypy"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: tsuyoshicho/action-mypy@v3
with:
github_token: ${{ secrets.KIRARI_TOKEN }}
reporter: github-pr-review
level: error
workdir: src
Loading