From 1a23f98667a03c5a610537e07b101074248cdc92 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sat, 15 Feb 2025 17:45:43 -0500 Subject: [PATCH] ci(lint): add linting workflow --- .flake8 | 7 ++ .github/scripts/requirements-lint.txt | 1 + .github/workflows/lint.yml | 143 ++++++++++++++++++++++++++ .gitpod.dockerfile | 9 +- 4 files changed, 157 insertions(+), 3 deletions(-) create mode 100644 .flake8 create mode 100644 .github/scripts/requirements-lint.txt create mode 100644 .github/workflows/lint.yml diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000..a8948ef1e --- /dev/null +++ b/.flake8 @@ -0,0 +1,7 @@ +[flake8] +filename = + *.py +max-line-length = 120 +extend-exclude = + .venv/ + venv/ diff --git a/.github/scripts/requirements-lint.txt b/.github/scripts/requirements-lint.txt new file mode 100644 index 000000000..91fa1282f --- /dev/null +++ b/.github/scripts/requirements-lint.txt @@ -0,0 +1 @@ +flake8==7.1.1 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..56293f25a --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,143 @@ +--- +name: Lint + +on: + pull_request: + branches: + - develop + types: + - opened + - synchronize + - reopened + +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install dependencies + run: | + python -m pip install --upgrade \ + pip \ + setuptools \ + wheel + python -m pip install -r ./.github/scripts/requirements-lint.txt + + - name: Docker - find files + id: dokcer_files + if: always() + run: | + found_files=$(find . -type f -iname "Dockerfile" -o -iname "*.dockerfile") + + echo "found_files: ${found_files}" + + # do not quote to keep this as a single line + echo found_files=${found_files} >> $GITHUB_OUTPUT + + - name: Docker - hadolint + if: always() && steps.dokcer_files.outputs.found_files + run: | + docker pull hadolint/hadolint + + # create hadolint config file + cat < .hadolint.yaml + --- + ignored: + - DL3008 + - DL3013 + - DL3016 + - DL3018 + - DL3028 + - DL3059 + EOF + + failed=0 + failed_files="" + + for file in ${{ steps.dokcer_files.outputs.found_files }}; do + echo "::group::${file}" + docker run --rm -i \ + -e "NO_COLOR=0" \ + -e "HADOLINT_VERBOSE=1" \ + -v $(pwd)/.hadolint.yaml:/.config/hadolint.yaml \ + hadolint/hadolint < $file || { + failed=1 + failed_files="$failed_files $file" + } + echo "::endgroup::" + done + + if [ $failed -ne 0 ]; then + echo "::error:: hadolint failed for the following files: $failed_files" + exit 1 + fi + + - name: Python - flake8 + if: always() + run: | + python -m flake8 \ + --color=always \ + --verbose + + - name: YAML - find files + id: yaml_files + if: always() + run: | + # space separated list of files + FILES=.clang-format + + # empty placeholder + found_files="" + + for FILE in ${FILES}; do + if [ -f "$FILE" ] + then + found_files="$found_files $FILE" + fi + done + + echo "found_files=${found_files}" >> $GITHUB_OUTPUT + + - name: YAML - yamllint + id: yamllint + if: always() + uses: ibiqlik/action-yamllint@v3 + with: + # https://yamllint.readthedocs.io/en/stable/configuration.html#default-configuration + config_data: | + extends: default + rules: + comments: + level: error + document-start: + level: error + line-length: + max: 120 + new-line-at-end-of-file: + level: error + new-lines: + type: unix + truthy: + # GitHub uses "on" for workflow event triggers + # .clang-format file has options of "Yes" "No" that will be caught by this, so changed to "warning" + allowed-values: ['true', 'false', 'on'] + check-keys: true + level: warning + file_or_dir: . ${{ steps.yaml_files.outputs.found_files }} + + - name: YAML - log + if: always() && steps.yamllint.outcome == 'failure' + run: | + cat "${{ steps.yamllint.outputs.logfile }}" >> $GITHUB_STEP_SUMMARY diff --git a/.gitpod.dockerfile b/.gitpod.dockerfile index 7e356ce00..14ad616f7 100644 --- a/.gitpod.dockerfile +++ b/.gitpod.dockerfile @@ -1,8 +1,11 @@ -FROM gitpod/workspace-full-vnc +FROM gitpod/workspace-full-vnc:2025-02-12-08-12-04 +# Hadolint complains about sudo; however gitpod recommends using sudo to install packages +# hadolint ignore=DL3004 RUN sudo apt-get update \ && sudo apt-get install -y \ firefox \ gulp \ - && python -m pip install --upgrade pip \ - && pip install selenium==4.1.0 requests==2.25.1 + && sudo apt-get clean \ + && python -m pip install --no-cache-dir --upgrade pip \ + && python -m pip install --no-cache-dir selenium==4.1.0 'requests<3'