Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions .github/workflows/general_file_formatting_check.yml
Original file line number Diff line number Diff line change
@@ -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<<EOF" >> $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<<EOF" >> $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
75 changes: 0 additions & 75 deletions .github/workflows/prettier.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
env.*
vars.*
.env*
*.debug
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down