From 1afb0a751282344c3f3f460de9eff4083abfc09c Mon Sep 17 00:00:00 2001 From: Scotte Zinn Date: Sun, 26 Jan 2025 01:59:00 -0500 Subject: [PATCH] fix: Linting refactor --- .ci/flake8/.flake8 | 2 - .ci/jscpd/jscpd.json | 22 --- .ci/prettier/.prettierrc.yaml | 8 - .ci/secretlint/.secretlintrc.json | 7 - .../actionlint.yml => .github/actionlint.yaml | 2 +- .github/workflows/lint.yaml | 153 ++++++++++++------ .../.markdownlint.yaml => .markdownlint.yaml | 0 .pre-commit-config.yaml | 4 +- .../.prettierignore => .prettierignore | 0 .ci/yamllint/.yamllint.yaml => .yamllint.yaml | 6 +- {.ci/ansible-lint => ansible}/.ansible-lint | 1 + ansible/files/ragnar/minio.yaml | 1 + ansible/files/ragnar/node-exporter.yaml | 1 + ansible/files/ragnar/smartctl-exporter.yaml | 3 +- .../playbooks/update-pikvm-certificate.yaml | 1 + .../playbooks/update-pikvm-configuration.yaml | 1 + .../playbooks/update-proxmox-certificate.yaml | 1 + .../playbooks/update-ragnar-certificate.yaml | 1 + .../update-ragnar-configuration.yaml | 1 + .../playbooks/update-titan-certificate.yaml | 1 + .../playbooks/update-udmse-configuration.yaml | 1 + .../playbooks/update-unifi-certificate.yaml | 1 + 22 files changed, 129 insertions(+), 89 deletions(-) delete mode 100644 .ci/flake8/.flake8 delete mode 100644 .ci/jscpd/jscpd.json delete mode 100644 .ci/prettier/.prettierrc.yaml delete mode 100644 .ci/secretlint/.secretlintrc.json rename .ci/actionlint/actionlint.yml => .github/actionlint.yaml (57%) rename .ci/markdownlint/.markdownlint.yaml => .markdownlint.yaml (100%) rename .ci/prettier/.prettierignore => .prettierignore (100%) rename .ci/yamllint/.yamllint.yaml => .yamllint.yaml (82%) rename {.ci/ansible-lint => ansible}/.ansible-lint (86%) diff --git a/.ci/flake8/.flake8 b/.ci/flake8/.flake8 deleted file mode 100644 index 6deafc2617..0000000000 --- a/.ci/flake8/.flake8 +++ /dev/null @@ -1,2 +0,0 @@ -[flake8] -max-line-length = 120 diff --git a/.ci/jscpd/jscpd.json b/.ci/jscpd/jscpd.json deleted file mode 100644 index 510120d18b..0000000000 --- a/.ci/jscpd/jscpd.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "threshold": 0, - "reporters": ["html", "markdown", "console"], - "ignore": [ - "**/node_modules/**", - "**/.git/**", - "**/.direnv/**", - "**/.rbenv/**", - "**/.terraform/**", - "**/.venv/**", - "**/report/**", - "**/*cache*/**", - "**/*.json", - "**/*.yaml", - "**/*.yml", - "**/*.md", - "**/*.html", - "**/*.xml", - "kubernetes/**/scripts/pushover-notify.sh", - "infrastructure/**" - ] -} diff --git a/.ci/prettier/.prettierrc.yaml b/.ci/prettier/.prettierrc.yaml deleted file mode 100644 index f3957ee556..0000000000 --- a/.ci/prettier/.prettierrc.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -trailingComma: "none" -tabWidth: 2 -semi: false -singleQuote: false -bracketSpacing: false -useTabs: false -quoteProps: "preserve" diff --git a/.ci/secretlint/.secretlintrc.json b/.ci/secretlint/.secretlintrc.json deleted file mode 100644 index 7a1a5df3c2..0000000000 --- a/.ci/secretlint/.secretlintrc.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "rules": [ - { - "id": "@secretlint/secretlint-rule-preset-recommend" - } - ] -} diff --git a/.ci/actionlint/actionlint.yml b/.github/actionlint.yaml similarity index 57% rename from .ci/actionlint/actionlint.yml rename to .github/actionlint.yaml index c34e9f49d3..470c48192a 100644 --- a/.ci/actionlint/actionlint.yml +++ b/.github/actionlint.yaml @@ -1,4 +1,4 @@ --- self-hosted-runner: labels: - - k8s-homelab + - k8s-homelab-runner diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 7d349e8c46..dadcb3f4cc 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -13,56 +13,119 @@ concurrency: cancel-in-progress: true jobs: - build: - name: Lint + actionlint: + name: actionlint runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Generate Token - uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 # v1 - if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} - id: app-token + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v45 with: - app-id: ${{ secrets.BOT_APP_ID }} - private-key: ${{ secrets.BOT_APP_PRIVATE_KEY }} - - - name: MegaLinter - uses: oxsecurity/megalinter/flavors/terraform@1fc052d03c7a43c78fe0fee19c9d648b749e0c01 # v8.3.0 - env: - GITHUB_TOKEN: "${{ steps.app-token.outputs.token }}" - PRINT_ALPACA: false - VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'workflow_dispatch' }} - ENABLE_LINTERS: |- - ${{ - join( - fromJSON(' - [ - "ACTION_ACTIONLINT", - "ANSIBLE_ANSIBLE_LINT", - "COPYPASTE_JSCPD", - "MARKDOWN_MARKDOWNLINT", - "PYTHON_FLAKE8", - "PYTHON_PYLINT", - "REPOSITORY_GIT_DIFF", - "REPOSITORY_SECRETLINT", - "TERRAFORM_TERRAFORM_FMT", - "YAML_PRETTIER", - "YAML_YAMLLINT" - ] - '), - ',' + files: | + .github/workflows/**/*.yml + .github/workflows/**/*.yaml + + - name: Run actionlint + if: steps.changed-files.outputs.any_changed == 'true' + uses: bjw-s/action-actionlint@v0.1 + with: + actionlint_config: .github/actionlint.yaml + file_pattern: ${{ steps.changed-files.outputs.all_changed_files }} + + yamllint: + name: yamllint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v45 + with: + files: | + **.yml + **.yaml + + - name: Install yamllint + if: steps.changed-files.outputs.any_changed == 'true' + shell: bash + run: | + pip install --user yamllint + + - name: Run yamllint + if: steps.changed-files.outputs.any_changed == 'true' + shell: bash + run: | + yamllint --config-file .yamllint.yaml --format github ${{ steps.changed-files.outputs.all_changed_files }} + + markdownlint: + name: markdownlint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v45 + with: + files: | + **.md + + - name: Run markdownlint-cli2 + if: steps.changed-files.outputs.any_changed == 'true' + uses: bjw-s/action-markdownlint-cli2@v0.1 + with: + markdownlint_config: .markdownlint.yaml + file_pattern: ${{ steps.changed-files.outputs.all_changed_files }} + + prettier: + name: prettier + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v45 + + - name: Run prettier + if: steps.changed-files.outputs.any_changed == 'true' + uses: bjw-s/action-prettier-lint@v0.1 + with: + prettier_ignore: .prettierignore + prettier_config: .prettierrc.yaml + file_pattern: ${{ steps.changed-files.outputs.all_changed_files }} + + lint_success: + needs: + - actionlint + - prettier + - yamllint + - markdownlint + if: | + always() + name: Lint successful + runs-on: ubuntu-latest + steps: + - name: Check job status + if: >- + ${{ + ( + contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') ) - }} - ACTION_ACTIONLINT_CONFIG_FILE: .ci/actionlint/actionlint.yml - ANSIBLE_ANSIBLE_LINT_ARGUMENTS: "-c .ci/ansible-lint/.ansible-lint ansible" - COPYPASTE_JSCPD_CONFIG_FILE: .ci/jscpd/jscpd.json - MARKDOWN_MARKDOWNLINT_CONFIG_FILE: .ci/markdownlint/markdownlint.yaml - MARKDOWN_MARKDOWNLINT_RULES_PATH: .ci/markdownlint/ - PYTHON_FLAKE8_CONFIG_FILE: .ci/flake8/.flake8 - YAML_YAMLLINT_CONFIG_FILE: .ci/yamllint/.yamllint.yaml - YAML_PRETTIER_CONFIG_FILE: .ci/prettier/.prettierrc.yaml - YAML_PRETTIER_ARGUMENTS: --ignore-path .ci/prettier/.prettierignore + }} + run: exit 1 diff --git a/.ci/markdownlint/.markdownlint.yaml b/.markdownlint.yaml similarity index 100% rename from .ci/markdownlint/.markdownlint.yaml rename to .markdownlint.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d2ac3c6dc8..5b4b624b34 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: - id: yamllint args: - --config-file - - .ci/yamllint/.yamllint.yaml + - .yamllint.yaml - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 @@ -57,7 +57,7 @@ repos: - id: markdownlint args: - --config - - ".ci/markdownlint/.markdownlint.yaml" + - .markdownlint.yaml - repo: https://github.com/jumanjihouse/pre-commit-hooks rev: 3.0.0 diff --git a/.ci/prettier/.prettierignore b/.prettierignore similarity index 100% rename from .ci/prettier/.prettierignore rename to .prettierignore diff --git a/.ci/yamllint/.yamllint.yaml b/.yamllint.yaml similarity index 82% rename from .ci/yamllint/.yamllint.yaml rename to .yamllint.yaml index 893ecc014c..28d994af14 100644 --- a/.ci/yamllint/.yamllint.yaml +++ b/.yamllint.yaml @@ -3,9 +3,13 @@ ignore: | hack/ .private/ .terraform/ + .venv/ .vscode/ *.sops.* - gotk-components.yaml + *.zinn.tech.yaml + tech-wildcard-tls.yaml + wildcard-tls.yaml + extends: default rules: truthy: diff --git a/.ci/ansible-lint/.ansible-lint b/ansible/.ansible-lint similarity index 86% rename from .ci/ansible-lint/.ansible-lint rename to ansible/.ansible-lint index a77e5d3e00..7c17aa1fb0 100644 --- a/.ci/ansible-lint/.ansible-lint +++ b/ansible/.ansible-lint @@ -1,2 +1,3 @@ +--- exclude_paths: - files/ diff --git a/ansible/files/ragnar/minio.yaml b/ansible/files/ragnar/minio.yaml index 4e9f80063b..c96d53db5d 100644 --- a/ansible/files/ragnar/minio.yaml +++ b/ansible/files/ragnar/minio.yaml @@ -1,3 +1,4 @@ +--- services: minio: command: server /data --console-address ":9001" diff --git a/ansible/files/ragnar/node-exporter.yaml b/ansible/files/ragnar/node-exporter.yaml index a7bc27636a..7884044426 100644 --- a/ansible/files/ragnar/node-exporter.yaml +++ b/ansible/files/ragnar/node-exporter.yaml @@ -1,3 +1,4 @@ +--- services: node-exporter: command: diff --git a/ansible/files/ragnar/smartctl-exporter.yaml b/ansible/files/ragnar/smartctl-exporter.yaml index f1491579fe..137153e201 100644 --- a/ansible/files/ragnar/smartctl-exporter.yaml +++ b/ansible/files/ragnar/smartctl-exporter.yaml @@ -1,3 +1,4 @@ +--- services: smartctl-exporter: command: @@ -6,6 +7,6 @@ services: image: quay.io/prometheuscommunity/smartctl-exporter:v0.13.0 ports: - "9633:9633" - privileged: True + privileged: true restart: always user: root diff --git a/ansible/playbooks/update-pikvm-certificate.yaml b/ansible/playbooks/update-pikvm-certificate.yaml index df4329c7b0..89323f7ca4 100644 --- a/ansible/playbooks/update-pikvm-certificate.yaml +++ b/ansible/playbooks/update-pikvm-certificate.yaml @@ -1,3 +1,4 @@ +--- - name: Update PiKVM Certificate hosts: pikvm remote_user: root diff --git a/ansible/playbooks/update-pikvm-configuration.yaml b/ansible/playbooks/update-pikvm-configuration.yaml index a181e4944c..65fce75259 100644 --- a/ansible/playbooks/update-pikvm-configuration.yaml +++ b/ansible/playbooks/update-pikvm-configuration.yaml @@ -1,3 +1,4 @@ +--- - name: Update PiKVM Configuration hosts: pikvm remote_user: root diff --git a/ansible/playbooks/update-proxmox-certificate.yaml b/ansible/playbooks/update-proxmox-certificate.yaml index b248882d14..7eff69911b 100644 --- a/ansible/playbooks/update-proxmox-certificate.yaml +++ b/ansible/playbooks/update-proxmox-certificate.yaml @@ -1,3 +1,4 @@ +--- - name: Update Proxmox Certificate hosts: "ares" remote_user: root diff --git a/ansible/playbooks/update-ragnar-certificate.yaml b/ansible/playbooks/update-ragnar-certificate.yaml index c83a61045f..4328f4c332 100644 --- a/ansible/playbooks/update-ragnar-certificate.yaml +++ b/ansible/playbooks/update-ragnar-certificate.yaml @@ -1,3 +1,4 @@ +--- - name: Update TrueNAS Certificate hosts: ragnar become: true diff --git a/ansible/playbooks/update-ragnar-configuration.yaml b/ansible/playbooks/update-ragnar-configuration.yaml index f3a7593300..23d57c6ca9 100644 --- a/ansible/playbooks/update-ragnar-configuration.yaml +++ b/ansible/playbooks/update-ragnar-configuration.yaml @@ -1,3 +1,4 @@ +--- - name: Update Ragnar Configuration hosts: ragnar tasks: diff --git a/ansible/playbooks/update-titan-certificate.yaml b/ansible/playbooks/update-titan-certificate.yaml index a4dd802ec0..c4e714dfa9 100644 --- a/ansible/playbooks/update-titan-certificate.yaml +++ b/ansible/playbooks/update-titan-certificate.yaml @@ -1,3 +1,4 @@ +--- - name: Update Gatus Certificate hosts: titan remote_user: root diff --git a/ansible/playbooks/update-udmse-configuration.yaml b/ansible/playbooks/update-udmse-configuration.yaml index ad09b93725..c783741002 100644 --- a/ansible/playbooks/update-udmse-configuration.yaml +++ b/ansible/playbooks/update-udmse-configuration.yaml @@ -1,3 +1,4 @@ +--- - name: Update Styx Configuration hosts: styx tasks: diff --git a/ansible/playbooks/update-unifi-certificate.yaml b/ansible/playbooks/update-unifi-certificate.yaml index 194021d10b..7906ee3507 100644 --- a/ansible/playbooks/update-unifi-certificate.yaml +++ b/ansible/playbooks/update-unifi-certificate.yaml @@ -1,3 +1,4 @@ +--- - name: Update UniFi Certificate hosts: styx zeus tasks: