Files

81 lines
3.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# npm-groovy-lint-docker-action
Gitea Action (Github Action) для проверки Groovy кода(Groovy Liter).
В качестве линтера используется 'NPM GROOVY LINT' - Groovy & Jenkinsfile Linter. NPM GROOVY LINT основан на базе CodeNarc - анализатора Groovy кода.
[Ссылка на проект](https://github.com/nvuillam/npm-groovy-lint)
Пример использования:
1- Данный код в виде yaml файла размещаем в репозиторий для которого необходим линтинг groovy кода. Путь для размещения
файла: repo_with_groovy_files/.gitea/workflows/groovy-linter.yml
```yaml
---
name: Groovy linter
run-name: ${{ gitea.actor }} is start check sources
on: [pull_request]
jobs:
linter:
name: Groovy linter
runs-on: docker
container:
image: harbor.avroid.tech/devops/npm-groovy-lint:14.4.1-0
steps:
- run: echo "Start job on ${{ runner.name }} with OS ${{ runner.os }}"
- run: echo "Work with branch ${{ gitea.ref }} in repository ${{ gitea.repository }}"
- name: Check out repository code
uses: https://${{ secrets.CI_USER }}:${{ secrets.CI_TOKEN }}@git.avroid.tech/Mirrors/github-actions-checkout.git@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Get all groovy files that have changed
id: changed-files-specific
uses: https://${{ secrets.CI_USER }}:${{ secrets.CI_TOKEN }}@git.avroid.tech/Mirrors/github-actions-tj-actions-changed-files.git@v44
with:
files: |
**/*.groovy
**/Jenkinsfile
- name: Run step if there is no changed files
id: no_files_to_check
if: steps.changed-files-specific.outputs.any_changed != 'true'
run: echo "*** No changed groovy files, nothing to check. ***"
- name: Run linter for changed files
id: groovy_linter
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: https://${{ secrets.CI_USER }}:${{ secrets.CI_TOKEN }}@git.avroid.tech/Actions/npm-groovy-lint-docker-action.git@v17
with:
input_flags: "--failon error"
input_files: ${{ steps.changed-files-specific.outputs.all_changed_files }}
```
2 - Размещаем в корне проверяемого репозитория конфиг для линтера. Путь и имя для размещения
repo_with_groovy_files/.groovylintrc.json
```json
{
"extends": "recommended",
"rules": {
"convention.CompileStatic": "off",
"convention.NoDef": "off",
"groovyism.ExplicitCallToEqualsMethod": "off",
"groovyism.GStringExpressionWithinString": "off",
"naming.VariableName": {
"ignoreVariableNames": "_"
},
"naming.FactoryMethodName": "off",
"unnecessary.UnnecessaryGetter": "off",
"size.NestedBlockDepth": {
"maxNestedBlockDepth": 10
},
"unused.UnusedVariable": {
"ignoreVariableNames": "_"
}
}
}
```
Директория example содержит примеры файлов .groovylintrc.json и .gitea/workflows/groovy-linter.yml
Описание правил конфига линтера https://codenarc.org/codenarc-rule-index-by-name.html