From b92bade11d982a5e98c0132fe653426a03203571 Mon Sep 17 00:00:00 2001 From: Daniel Falk Date: Fri, 15 Aug 2025 14:12:45 +0200 Subject: [PATCH] Add check for trailing whitespace --- .../general_file_formatting_check.yml | 134 ++++++++++++++++++ .github/workflows/prettier.yml | 75 ---------- .gitignore | 4 + .../helper_scripts/generate-env.sh | 2 +- 4 files changed, 139 insertions(+), 76 deletions(-) create mode 100644 .github/workflows/general_file_formatting_check.yml delete mode 100644 .github/workflows/prettier.yml create mode 100644 .gitignore diff --git a/.github/workflows/general_file_formatting_check.yml b/.github/workflows/general_file_formatting_check.yml new file mode 100644 index 0000000..155a7e9 --- /dev/null +++ b/.github/workflows/general_file_formatting_check.yml @@ -0,0 +1,134 @@ +name: File formatting check + +on: + push: + pull_request: + +permissions: + contents: read + pull-requests: write + +jobs: + formatting: + runs-on: ubuntu-latest + env: + # List of files patterns that should be formatted by prettier. This should normally include: + # workflow files (yml) and any other json/yml/markdown files, including hidden config files for tools. + PRETTIER_FILES: '"**/*.{json,yml,yaml,md}" ".github/**/*.{json,yml,yaml,md}" ".*.{yml,yaml,json,md}"' + # Pin Prettier version to ensure deterministic CI runs and avoid unpredictable failures + PRETTIER_VERSION: "3.6.0" + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20" + + - name: Check for files with spaces in names + # If we find files with spaces, etc., we exit directly with an error. That way, + # the rest of the workflow does not need to be compatible with spaces in the + # file names which makes things easier. + run: | + echo "🔍 Checking for files with spaces or newlines in names..." + BAD_FILENAMES=$(find . -name "* *" -o -name $'*\n*' -o -name $'*\t*' 2>/dev/null || true) + + if [ -n "$BAD_FILENAMES" ]; then + echo "❌ Found files with spaces/tabs/newlines in names:" + echo "$BAD_FILENAMES" + echo "Please rename these files to use underscores or hyphens instead of spaces." + exit 1 + else + echo "✅ No files with problematic names found" + fi + + - name: Check for trailing whitespace + id: whitespace_check + run: | + # Check for trailing whitespace in all text files + echo "🔍 Checking for trailing whitespace..." + WHITESPACE_FILES=$(grep -rI \ + --exclude-dir=".git" --exclude-dir="node_modules" --exclude-dir="dist" --exclude-dir="build" \ + --exclude-dir=".mypy_cache" --exclude-dir="__pycache__" --exclude-dir=".pytest_cache" \ + --include="*.py" --include="*.yml" --include="*.yaml" --include="*.json" --include="*.md" --include="*.txt" --include="*.sh" --include="*.conf" \ + -l '[[:space:]]$' . 2>/dev/null || true) + + if [ -n "$WHITESPACE_FILES" ]; then + echo "whitespace_files<> $GITHUB_OUTPUT + echo "$WHITESPACE_FILES" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + echo "❌ Found trailing whitespace in files:" + echo "$WHITESPACE_FILES" + echo "whitespace_found=true" >> $GITHUB_OUTPUT + else + echo "✅ No trailing whitespace found" + echo "whitespace_found=false" >> $GITHUB_OUTPUT + fi + + - name: Run prettier check + id: prettier_check + run: | + # Format JSON, YAML (including workflow files), and Markdown files + if npx prettier@${{ env.PRETTIER_VERSION }} --check ${{ env.PRETTIER_FILES }} --ignore-unknown; then + echo "prettier_passed=true" >> $GITHUB_OUTPUT + echo "prettier_files=" >> $GITHUB_OUTPUT + else + echo "prettier_passed=false" >> $GITHUB_OUTPUT + # Get list of files that need formatting + FILES_NEEDING_FORMAT=$(npx prettier@${{ env.PRETTIER_VERSION }} --list-different ${{ env.PRETTIER_FILES }} --ignore-unknown 2>/dev/null || true) + echo "prettier_files<> $GITHUB_OUTPUT + echo "$FILES_NEEDING_FORMAT" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + fi + + - name: Comment on PR (on failure) + continue-on-error: true # to be resilient against forks... + if: github.event_name == 'pull_request' && (steps.prettier_check.outputs.prettier_passed == 'false' || steps.whitespace_check.outputs.whitespace_found == 'true') + uses: actions/github-script@v7 + with: + script: | + const prettierFiles = `${{ steps.prettier_check.outputs.prettier_files }}`.trim(); + const whitespaceFiles = `${{ steps.whitespace_check.outputs.whitespace_files }}`.trim(); + + let comment = `## 🎨 Code Formatting Required\n\n`; + + if (prettierFiles) { + const files = prettierFiles.split('\n').filter(f => f.trim()); + comment += `### Prettier Formatting Issues\n\n`; + comment += `Some files need to be formatted with Prettier (JSON, YAML, Markdown).\n\n`; + comment += `**Files that need prettier formatting:**\n`; + comment += `${files.map(file => `- \`${file}\``).join('\n')}\n\n`; + comment += `**To fix prettier issues:**\n`; + comment += `\`\`\`bash\n`; + comment += `npx prettier@${{ env.PRETTIER_VERSION }} --write ${{ env.PRETTIER_FILES }} --ignore-unknown\n`; + comment += `\`\`\`\n\n`; + } + + if (whitespaceFiles) { + const files = whitespaceFiles.split('\n').filter(f => f.trim()); + comment += `### Trailing Whitespace Issues\n\n`; + comment += `Some files have trailing whitespace (spaces/tabs at end of lines).\n\n`; + comment += `**Files with trailing whitespace:**\n`; + comment += `${files.map(file => `- \`${file}\``).join('\n')}\n\n`; + comment += `**To fix:** Remove the trailing spaces/tabs at the end of lines in your favorite editor.\n\n`; + } + + comment += `**After fixing:**\n`; + comment += `1. Commit and push the changes\n`; + comment += `2. The formatting check will automatically pass\n`; + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: comment + }); + + - name: Fail if formatting issues found + if: steps.prettier_check.outputs.prettier_passed == 'false' || steps.whitespace_check.outputs.whitespace_found == 'true' + run: | + echo "❌ Formatting issues found" + exit 1 diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml deleted file mode 100644 index 3ae2ca1..0000000 --- a/.github/workflows/prettier.yml +++ /dev/null @@ -1,75 +0,0 @@ -name: Prettier Format Check - -on: - push: - pull_request: - -permissions: - contents: read - pull-requests: write - -jobs: - prettier: - runs-on: ubuntu-latest - env: - # List of files patterns that should be formatted by prettier. This should normally include: - # workflow files (yml) and any other json/yml/markdown files, including hidden config files for tools. - PRETTIER_FILES: '"**/*.{json,yml,yaml,md}" ".github/**/*.{json,yml,yaml,md}" ".*.{yml,yaml,json,md}"' - # Pin Prettier version to ensure deterministic CI runs and avoid unpredictable failures - PRETTIER_VERSION: "3.6.0" - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: "20" - - - name: Run prettier check - run: | - # Format JSON, YAML (including workflow files), and Markdown files - npx prettier@${{ env.PRETTIER_VERSION }} --check ${{ env.PRETTIER_FILES }} --ignore-unknown - - - name: Get files that need formatting (on failure) - if: failure() && github.event_name == 'pull_request' - id: format_files - run: | - # Get list of files that need formatting - FILES_NEEDING_FORMAT=$(npx prettier@${{ env.PRETTIER_VERSION }} --check ${{ env.PRETTIER_FILES }} --ignore-unknown --list-different 2>/dev/null || true) - echo "files_list<> $GITHUB_OUTPUT - echo "$FILES_NEEDING_FORMAT" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT - - - name: Comment on PR (on failure) - if: failure() && github.event_name == 'pull_request' && steps.format_files.outputs.files_list != '' - uses: actions/github-script@v7 - with: - script: | - const filesList = `${{ steps.format_files.outputs.files_list }}`.trim(); - - if (filesList) { - const files = filesList.split('\n').filter(f => f.trim()); - const comment = `## 🎨 Code Formatting Required - - Some files in this PR need to be formatted with Prettier. - - This includes JSON, YAML (workflow files), and Markdown files. - - **Files that need formatting:** - ${files.map(file => `- \`${file}\``).join('\n')} - - **To fix this:** - 1. Format the files: \`npx prettier@${{ env.PRETTIER_VERSION }} --write ${{ env.PRETTIER_FILES }} --ignore-unknown\` - 2. Commit and push the changes - - The formatting check will automatically pass once these files are properly formatted.`; - - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: comment - }); - } diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ca153d5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +env.* +vars.* +.env* +*.debug \ No newline at end of file diff --git a/dashboard-deployments/system-monitoring-influxdb2-flux-grafana/helper_scripts/generate-env.sh b/dashboard-deployments/system-monitoring-influxdb2-flux-grafana/helper_scripts/generate-env.sh index c2f2988..d93c4c2 100755 --- a/dashboard-deployments/system-monitoring-influxdb2-flux-grafana/helper_scripts/generate-env.sh +++ b/dashboard-deployments/system-monitoring-influxdb2-flux-grafana/helper_scripts/generate-env.sh @@ -49,7 +49,7 @@ cat > "$ENV_FILE" << EOF #!/bin/bash # Generated environment variables for production docker-compose setup # Generated on: $(date) -# +# # To use these variables, source this file: # source env.sh #