From 889d8b67e07de339e1816e16dfcacbde8e6fabba Mon Sep 17 00:00:00 2001 From: tk-woven <61102060+tk-woven@users.noreply.github.com> Date: Tue, 23 Aug 2022 13:59:45 +0900 Subject: [PATCH] feat: move last SuperLinter check `yamllint` to pre-commit (#124) This also removes SuperLinter from DGP since all utilized checks have been migrated to pre-commit. --- .commitlintrc.yml | 2 +- .github/workflows/build-docker.yml | 2 +- .github/workflows/coverage.yml | 116 ++++++++++++++--------------- .github/workflows/doc-gen.yml | 44 +++++------ .github/workflows/pre-merge.yml | 23 ------ .pre-commit-config.yaml | 4 + .yamllint.yaml | 8 ++ 7 files changed, 94 insertions(+), 105 deletions(-) create mode 100644 .yamllint.yaml diff --git a/.commitlintrc.yml b/.commitlintrc.yml index 36228d3f..feb9e75d 100644 --- a/.commitlintrc.yml +++ b/.commitlintrc.yml @@ -3,4 +3,4 @@ extends: - '@commitlint/config-conventional' rules: - type-enum: [2, 'always', ['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'refactor', 'revert', 'perf', 'schema', 'style', 'test']] + type-enum: [2, 'always', ['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'refactor', 'revert', 'perf', 'schema', 'style', 'test']] diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index ffb10567..ce99d443 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -41,4 +41,4 @@ jobs: context: . push: true tags: ${{ steps.meta.outputs.tags }}-${{ github.sha }},${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 96e43392..f1e66963 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -15,61 +15,61 @@ jobs: PYTHON: '3.9' COVERAGE_TOTAL: 49 # Coverage threshold percentage steps: - - name: Checkout (admin token) - if: ${{github.event_name != 'pull_request'}} # We don't want to use the admin token for PR flows - uses: actions/checkout@master - with: - token: '${{ secrets.GIT_ADMIN_WORKFLOW_TOKEN }}' - fetch-depth: "2" # Original commit + code cov badge commit - - name: Checkout (normal flow) - if: ${{github.event_name == 'pull_request'}} - uses: actions/checkout@master - with: - fetch-depth: "2" # Original commit + code cov badge commit - - name: Setup Python - uses: actions/setup-python@master - with: - python-version: 3.9 - - name: Install dependencies - id: coverage-installer - run: | - python -m pip install --upgrade pip - pip install cython==0.29.21 numpy==1.23.2 - sudo apt-get install jq - pip install -r requirements.txt - pip install -r requirements-dev.txt - pip install coverage-badge - - name: Run tests and calculate coverage - id: test-runner - run: | - coverage run -m pytest - coverage-badge -f -o docs/coverage.svg - COVERAGE_SCORE=$(coverage json -o /dev/stdout | jq .totals.percent_covered) - echo "::set-output name=coverageScore::$COVERAGE_SCORE" - - name: Verify Changed files - uses: tj-actions/verify-changed-files@v6 - id: changed_files - with: - files: docs/coverage.svg - - name: Commit code coverage badge - if: ${{ steps.changed_files.outputs.files_changed == 'true' && github.event_name != 'pull_request'}} - run: | - git config --local user.name "$(git log -1 --pretty=format:'%an' | xargs)" - git config --local user.email "$(git log -1 --pretty=format:'%ae' | xargs)" - git add docs/coverage.svg - git commit -m "test: update coverage.svg" - git reset --soft HEAD~2 - # shellcheck disable=SC1083 # code is irrelevant because git needs this literal - git commit -m "$(git log --format=%B --reverse HEAD..HEAD@{1})" - - name: Push code coverage badge - if: ${{ steps.changed_files.outputs.files_changed == 'true' && github.event_name != 'pull_request'}} - uses: ad-m/github-push-action@master - with: - force: true - github_token: ${{ secrets.GIT_ADMIN_WORKFLOW_TOKEN }} - branch: ${{ github.event.pull_request.head.repo.full_name }} - - name: Coverage total fail - exit - if: ${{github.event_name == 'pull_request' && steps.test-runner.outputs.coverageScore < env.COVERAGE_TOTAL}} - run: | - echo "cov total fail ${{ steps.test-runner.outputs.coverageScore }}" - exit 1 + - name: Checkout (admin token) + if: ${{github.event_name != 'pull_request'}} # We don't want to use the admin token for PR flows + uses: actions/checkout@master + with: + token: '${{ secrets.GIT_ADMIN_WORKFLOW_TOKEN }}' + fetch-depth: "2" # Original commit + code cov badge commit + - name: Checkout (normal flow) + if: ${{github.event_name == 'pull_request'}} + uses: actions/checkout@master + with: + fetch-depth: "2" # Original commit + code cov badge commit + - name: Setup Python + uses: actions/setup-python@master + with: + python-version: 3.9 + - name: Install dependencies + id: coverage-installer + run: | + python -m pip install --upgrade pip + pip install cython==0.29.21 numpy==1.23.2 + sudo apt-get install jq + pip install -r requirements.txt + pip install -r requirements-dev.txt + pip install coverage-badge + - name: Run tests and calculate coverage + id: test-runner + run: | + coverage run -m pytest + coverage-badge -f -o docs/coverage.svg + COVERAGE_SCORE=$(coverage json -o /dev/stdout | jq .totals.percent_covered) + echo "::set-output name=coverageScore::$COVERAGE_SCORE" + - name: Verify Changed files + uses: tj-actions/verify-changed-files@v6 + id: changed_files + with: + files: docs/coverage.svg + - name: Commit code coverage badge + if: ${{ steps.changed_files.outputs.files_changed == 'true' && github.event_name != 'pull_request'}} + run: | + git config --local user.name "$(git log -1 --pretty=format:'%an' | xargs)" + git config --local user.email "$(git log -1 --pretty=format:'%ae' | xargs)" + git add docs/coverage.svg + git commit -m "test: update coverage.svg" + git reset --soft HEAD~2 + # shellcheck disable=SC1083 # code is irrelevant because git needs this literal + git commit -m "$(git log --format=%B --reverse HEAD..HEAD@{1})" + - name: Push code coverage badge + if: ${{ steps.changed_files.outputs.files_changed == 'true' && github.event_name != 'pull_request'}} + uses: ad-m/github-push-action@master + with: + force: true + github_token: ${{ secrets.GIT_ADMIN_WORKFLOW_TOKEN }} + branch: ${{ github.event.pull_request.head.repo.full_name }} + - name: Coverage total fail - exit + if: ${{github.event_name == 'pull_request' && steps.test-runner.outputs.coverageScore < env.COVERAGE_TOTAL}} + run: | + echo "cov total fail ${{ steps.test-runner.outputs.coverageScore }}" + exit 1 diff --git a/.github/workflows/doc-gen.yml b/.github/workflows/doc-gen.yml index 8fd1e76f..5a08df47 100644 --- a/.github/workflows/doc-gen.yml +++ b/.github/workflows/doc-gen.yml @@ -10,25 +10,25 @@ jobs: OS: ubuntu-20.04 PYTHON: '3.9' steps: - - uses: actions/checkout@master - with: - fetch-depth: "1" - - name: Setup Python - uses: actions/setup-python@master - with: - python-version: 3.9 - - name: Setup requirements and run sphinx - run: | - python -m pip install --upgrade pip - pip install cython==0.29.21 numpy==1.23.2 - pip install -r requirements.txt - pip install -r requirements-dev.txt - pip install -r docs/requirements-doc.txt - cd docs - make html - - name: Push Sphinx Pages to Webserver - uses: JamesIves/github-pages-deploy-action@4.1.5 - with: - branch: gh-pages - folder: ./docs/build/html - commit-message: 'docs: update build documentation' + - uses: actions/checkout@master + with: + fetch-depth: "1" + - name: Setup Python + uses: actions/setup-python@master + with: + python-version: 3.9 + - name: Setup requirements and run sphinx + run: | + python -m pip install --upgrade pip + pip install cython==0.29.21 numpy==1.23.2 + pip install -r requirements.txt + pip install -r requirements-dev.txt + pip install -r docs/requirements-doc.txt + cd docs + make html + - name: Push Sphinx Pages to Webserver + uses: JamesIves/github-pages-deploy-action@4.1.5 + with: + branch: gh-pages + folder: ./docs/build/html + commit-message: 'docs: update build documentation' diff --git a/.github/workflows/pre-merge.yml b/.github/workflows/pre-merge.yml index 0e188280..ec86054c 100644 --- a/.github/workflows/pre-merge.yml +++ b/.github/workflows/pre-merge.yml @@ -35,26 +35,3 @@ jobs: run: | pre-commit install pre-commit run --all-files - - name: Lint code base with SuperLinter - # Documentation: https://github.com/github/super-linter#how-to-use - uses: github/super-linter@v4 - env: - DEFAULT_BRANCH: master - FILTER_REGEX_EXCLUDE: .*pb2*py - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - LINTER_RULES_PATH: . - VALIDATE_ALL_CODEBASE: false # Only new or edited files will be parsed for validation. - VALIDATE_DOCKERFILE_HADOLINT: false - VALIDATE_GITLEAKS: false # Handled by pre-commit. - VALIDATE_HTML: false # Handled by pre-commit. - VALIDATE_JSCPD: false - VALIDATE_JSON: false # Handled by pre-commit. - VALIDATE_MARKDOWN: false # Handled by pre-commit. - VALIDATE_NATURAL_LANGUAGE: false # No corresponding pre-commit hook but not critical. - VALIDATE_PROTOBUF: false - VALIDATE_PYTHON_BLACK: false - VALIDATE_PYTHON_FLAKE8: false # Formatted by YAPF. - VALIDATE_PYTHON_ISORT: false # Formatted by YAPF. - VALIDATE_PYTHON_MYPY: false - VALIDATE_PYTHON_PYLINT: false # Handled by pre-commit. - VALIDATE_SHELL_SHFMT: false # Handled by pre-commit. diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ee08cf45..4e140361 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -49,6 +49,10 @@ repos: hooks: - id: shellcheck - id: shfmt + - repo: https://github.com/adrienverge/yamllint + rev: v1.27.1 + hooks: + - id: yamllint - repo: https://github.com/pre-commit/mirrors-yapf rev: v0.32.0 hooks: diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 00000000..aa438ab0 --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,8 @@ +extends: default + +rules: + line-length: disable + document-start: disable # Allow missing "---" file prelude. + truthy: + check-keys: false # Allow keys that look like truthy literals, such as `on`. + comments: disable # Allow single space between non-comment and comment.