From 84aaa3fa3d2fde954c5886398f802b43aeed5d61 Mon Sep 17 00:00:00 2001 From: Marian Steinbach Date: Thu, 23 Oct 2025 17:44:38 +0200 Subject: [PATCH 1/8] Add workflow to validate file names --- .github/workflows/validate-file-names.yaml | 121 +++++++++++++++++++++ .github/workflows/validate-workflows.yaml | 3 + 2 files changed, 124 insertions(+) create mode 100644 .github/workflows/validate-file-names.yaml diff --git a/.github/workflows/validate-file-names.yaml b/.github/workflows/validate-file-names.yaml new file mode 100644 index 0000000..06fc9f4 --- /dev/null +++ b/.github/workflows/validate-file-names.yaml @@ -0,0 +1,121 @@ +name: Validate file names + +on: + workflow_call: + workflow_dispatch: + +permissions: + contents: read + +jobs: + validate-file-names: + name: Validate file names contain only ASCII characters + runs-on: ubuntu-24.04 + + steps: + - name: Checkout code + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + fetch-depth: 0 + + - name: Get list of added or renamed files + id: changed-files + run: | + # Determine base and head refs based on trigger type + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + # For manual triggers, compare current branch against main/master + # First try to find main, then master + if git rev-parse origin/main >/dev/null 2>&1; then + base_ref="origin/main" + elif git rev-parse origin/master >/dev/null 2>&1; then + base_ref="origin/master" + else + echo "::error::Could not find origin/main or origin/master branch" + exit 1 + fi + head_ref="${{ github.sha }}" + echo "Manual trigger detected - comparing against $base_ref" + else + # For PR or workflow_call triggers + base_ref="${{ github.event.pull_request.base.sha || github.event.before }}" + head_ref="${{ github.event.pull_request.head.sha || github.sha }}" + fi + + echo "Base ref: $base_ref" + echo "Head ref: $head_ref" + + # Get added and renamed files + files=$(git diff --name-only --diff-filter=AR "$base_ref" "$head_ref" || true) + + if [ -z "$files" ]; then + echo "No added or renamed files found" + echo "has_files=false" >> $GITHUB_OUTPUT + else + echo "Files to validate:" + echo "$files" + echo "has_files=true" >> $GITHUB_OUTPUT + # Save files to a temporary file for the next step + echo "$files" > /tmp/files_to_check.txt + fi + + - name: Validate file and directory names are ASCII only + if: steps.changed-files.outputs.has_files == 'true' + id: validate + run: | + invalid_files="" + exit_code=0 + + while IFS= read -r file; do + # Check if the path (including all directory names and file name) contains only ASCII characters + # ASCII characters range from 0x00 to 0x7F + if echo "$file" | LC_ALL=C grep -q '[^\x00-\x7F]'; then + echo "::error file=$file::Path contains non-ASCII characters: $file" + invalid_files="${invalid_files}${file}"$'\n' + exit_code=1 + fi + done < /tmp/files_to_check.txt + + if [ $exit_code -eq 1 ]; then + echo "invalid_files<> $GITHUB_OUTPUT + echo "$invalid_files" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + echo "validation_failed=true" >> $GITHUB_OUTPUT + else + echo "All file and directory names contain only ASCII characters" + echo "validation_failed=false" >> $GITHUB_OUTPUT + fi + + - name: Generate job summary + if: always() && steps.changed-files.outputs.has_files == 'true' + run: | + if [ "${{ steps.validate.outputs.validation_failed }}" == "true" ]; then + echo "## :x: File Name Validation Failed" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "The following files or directories contain non-ASCII characters in their paths:" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "${{ steps.validate.outputs.invalid_files }}" | while IFS= read -r file; do + if [ -n "$file" ]; then + echo "- \`$file\`" >> $GITHUB_STEP_SUMMARY + fi + done + echo "" >> $GITHUB_STEP_SUMMARY + echo "### Why this matters" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "- Non-ASCII characters can cause issues with some tools and systems" >> $GITHUB_STEP_SUMMARY + echo "- ASCII-only paths ensure better compatibility across different platforms" >> $GITHUB_STEP_SUMMARY + echo "- They prevent encoding-related problems in version control systems" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "### How to fix" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "Please rename these files/directories to use only ASCII characters (letters, numbers, and common symbols like \`-\`, \`_\`, \`.\`)." >> $GITHUB_STEP_SUMMARY + else + echo "## :white_check_mark: File Name Validation Passed" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "All file and directory names contain only ASCII characters." >> $GITHUB_STEP_SUMMARY + fi + + - name: Fail if validation found issues + if: steps.validate.outputs.validation_failed == 'true' + run: | + echo "Validation failed - found files or directories with non-ASCII characters" + exit 1 diff --git a/.github/workflows/validate-workflows.yaml b/.github/workflows/validate-workflows.yaml index 47c9c35..5180c3e 100644 --- a/.github/workflows/validate-workflows.yaml +++ b/.github/workflows/validate-workflows.yaml @@ -15,6 +15,9 @@ jobs: - name: Checkout code uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + - name: Validate file names + uses: ./.github/workflows/validate-file-names.yaml + - name: Validate YAML uses: docker://gsoci.azurecr.io/giantswarm/yamllint:1.37.1 with: From ddb20d47d0545cbd5ab7d671bfa1ee2abdf7aa60 Mon Sep 17 00:00:00 2001 From: Marian Steinbach Date: Thu, 23 Oct 2025 17:46:32 +0200 Subject: [PATCH 2/8] Use branch --- .github/workflows/validate-workflows.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/validate-workflows.yaml b/.github/workflows/validate-workflows.yaml index 5180c3e..d3117ff 100644 --- a/.github/workflows/validate-workflows.yaml +++ b/.github/workflows/validate-workflows.yaml @@ -16,7 +16,7 @@ jobs: uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Validate file names - uses: ./.github/workflows/validate-file-names.yaml + uses: ./.github/workflows/validate-file-names.yaml@add-filename-check - name: Validate YAML uses: docker://gsoci.azurecr.io/giantswarm/yamllint:1.37.1 From 1486ad016483192a88c9a01416bc1fd070f08d35 Mon Sep 17 00:00:00 2001 From: Marian Steinbach Date: Thu, 23 Oct 2025 17:48:17 +0200 Subject: [PATCH 3/8] Change workflow ref --- .github/workflows/validate-workflows.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/validate-workflows.yaml b/.github/workflows/validate-workflows.yaml index d3117ff..e591188 100644 --- a/.github/workflows/validate-workflows.yaml +++ b/.github/workflows/validate-workflows.yaml @@ -16,7 +16,7 @@ jobs: uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Validate file names - uses: ./.github/workflows/validate-file-names.yaml@add-filename-check + uses: giantswarm/github-workflows/.github/workflows/validate-file-names.yaml@add-filename-check - name: Validate YAML uses: docker://gsoci.azurecr.io/giantswarm/yamllint:1.37.1 From 9f5c0869d3231f87e74e5511747484f1d2716379 Mon Sep 17 00:00:00 2001 From: Marian Steinbach Date: Thu, 23 Oct 2025 17:49:32 +0200 Subject: [PATCH 4/8] Update validate-workflows.yaml --- .github/workflows/validate-workflows.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/validate-workflows.yaml b/.github/workflows/validate-workflows.yaml index e591188..47c9c35 100644 --- a/.github/workflows/validate-workflows.yaml +++ b/.github/workflows/validate-workflows.yaml @@ -15,9 +15,6 @@ jobs: - name: Checkout code uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - - name: Validate file names - uses: giantswarm/github-workflows/.github/workflows/validate-file-names.yaml@add-filename-check - - name: Validate YAML uses: docker://gsoci.azurecr.io/giantswarm/yamllint:1.37.1 with: From 8e9204079dede4cf03112366ebd4a8ebff095b70 Mon Sep 17 00:00:00 2001 From: Marian Steinbach Date: Thu, 23 Oct 2025 17:59:53 +0200 Subject: [PATCH 5/8] Update character detection --- .github/workflows/validate-file-names.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/validate-file-names.yaml b/.github/workflows/validate-file-names.yaml index 06fc9f4..dc0f225 100644 --- a/.github/workflows/validate-file-names.yaml +++ b/.github/workflows/validate-file-names.yaml @@ -67,8 +67,7 @@ jobs: while IFS= read -r file; do # Check if the path (including all directory names and file name) contains only ASCII characters - # ASCII characters range from 0x00 to 0x7F - if echo "$file" | LC_ALL=C grep -q '[^\x00-\x7F]'; then + if [[ "$file" = *[![:ascii:]]* ]]; then echo "::error file=$file::Path contains non-ASCII characters: $file" invalid_files="${invalid_files}${file}"$'\n' exit_code=1 From 7135939f4760e36ce4f403ef72c8488de888edd3 Mon Sep 17 00:00:00 2001 From: Marian Steinbach Date: Fri, 24 Oct 2025 07:43:55 +0200 Subject: [PATCH 6/8] Fix: Configure git to not escape non-ASCII filenames --- .github/workflows/validate-file-names.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/validate-file-names.yaml b/.github/workflows/validate-file-names.yaml index dc0f225..5a7fa89 100644 --- a/.github/workflows/validate-file-names.yaml +++ b/.github/workflows/validate-file-names.yaml @@ -44,6 +44,9 @@ jobs: echo "Base ref: $base_ref" echo "Head ref: $head_ref" + # Configure git to not escape non-ASCII characters in filenames + git config core.quotepath false + # Get added and renamed files files=$(git diff --name-only --diff-filter=AR "$base_ref" "$head_ref" || true) From 197e0ec670288f0bdbeac8b8ec2c8228ed97507d Mon Sep 17 00:00:00 2001 From: Marian Steinbach Date: Fri, 24 Oct 2025 07:47:08 +0200 Subject: [PATCH 7/8] Simplify summary --- .github/workflows/validate-file-names.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/validate-file-names.yaml b/.github/workflows/validate-file-names.yaml index 5a7fa89..ddb1e63 100644 --- a/.github/workflows/validate-file-names.yaml +++ b/.github/workflows/validate-file-names.yaml @@ -101,12 +101,6 @@ jobs: fi done echo "" >> $GITHUB_STEP_SUMMARY - echo "### Why this matters" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "- Non-ASCII characters can cause issues with some tools and systems" >> $GITHUB_STEP_SUMMARY - echo "- ASCII-only paths ensure better compatibility across different platforms" >> $GITHUB_STEP_SUMMARY - echo "- They prevent encoding-related problems in version control systems" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY echo "### How to fix" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "Please rename these files/directories to use only ASCII characters (letters, numbers, and common symbols like \`-\`, \`_\`, \`.\`)." >> $GITHUB_STEP_SUMMARY From 17223759b1cd217af51317c8e1923250f409f589 Mon Sep 17 00:00:00 2001 From: Marian Steinbach Date: Fri, 24 Oct 2025 10:12:15 +0200 Subject: [PATCH 8/8] Change manual trigger to validate all files in repository --- .github/workflows/validate-file-names.yaml | 44 +++++++++------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/.github/workflows/validate-file-names.yaml b/.github/workflows/validate-file-names.yaml index ddb1e63..de1a8f4 100644 --- a/.github/workflows/validate-file-names.yaml +++ b/.github/workflows/validate-file-names.yaml @@ -1,3 +1,4 @@ +# Use this workflow in repositories to enforcee ASCII-only file names. name: Validate file names on: @@ -8,8 +9,8 @@ permissions: contents: read jobs: - validate-file-names: - name: Validate file names contain only ASCII characters + validate: + name: Validate file names runs-on: ubuntu-24.04 steps: @@ -18,40 +19,31 @@ jobs: with: fetch-depth: 0 - - name: Get list of added or renamed files + - name: Get list of files to validate id: changed-files run: | - # Determine base and head refs based on trigger type + # Configure git to not escape non-ASCII characters in filenames + git config core.quotepath false + + # Determine which files to validate based on trigger type if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then - # For manual triggers, compare current branch against main/master - # First try to find main, then master - if git rev-parse origin/main >/dev/null 2>&1; then - base_ref="origin/main" - elif git rev-parse origin/master >/dev/null 2>&1; then - base_ref="origin/master" - else - echo "::error::Could not find origin/main or origin/master branch" - exit 1 - fi - head_ref="${{ github.sha }}" - echo "Manual trigger detected - comparing against $base_ref" + # For manual triggers, validate ALL files in the repository + echo "Manual trigger detected - validating all files in repository" + files=$(git ls-files) else - # For PR or workflow_call triggers + # For PR or workflow_call triggers, only validate added/renamed files base_ref="${{ github.event.pull_request.base.sha || github.event.before }}" head_ref="${{ github.event.pull_request.head.sha || github.sha }}" - fi - echo "Base ref: $base_ref" - echo "Head ref: $head_ref" + echo "Base ref: $base_ref" + echo "Head ref: $head_ref" - # Configure git to not escape non-ASCII characters in filenames - git config core.quotepath false - - # Get added and renamed files - files=$(git diff --name-only --diff-filter=AR "$base_ref" "$head_ref" || true) + # Get added and renamed files + files=$(git diff --name-only --diff-filter=AR "$base_ref" "$head_ref" || true) + fi if [ -z "$files" ]; then - echo "No added or renamed files found" + echo "No files found to validate" echo "has_files=false" >> $GITHUB_OUTPUT else echo "Files to validate:"