From 05824b40544b37906855ee7e844af02233fd53e8 Mon Sep 17 00:00:00 2001 From: lachlan-robinson Date: Mon, 25 Aug 2025 19:04:30 +1000 Subject: [PATCH 1/6] chore: add validation script --- .github/workflows/validate-filenames.yml | 52 ++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/validate-filenames.yml diff --git a/.github/workflows/validate-filenames.yml b/.github/workflows/validate-filenames.yml new file mode 100644 index 00000000..b876ca6a --- /dev/null +++ b/.github/workflows/validate-filenames.yml @@ -0,0 +1,52 @@ +# .github/workflows/check-colon-in-filenames.yml +name: Check filenames for colons + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + check-filenames: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Get list of changed files + id: files + run: | + files=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files --jq '.[].filename') + echo "files<> $GITHUB_OUTPUT + echo "$files" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check for colons + id: check + run: | + bad_files=$(echo "${{ steps.files.outputs.files }}" | grep ":" || true) + if [ -n "$bad_files" ]; then + echo "bad_files<> $GITHUB_OUTPUT + echo "$bad_files" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + exit 1 + else + echo "No bad filenames found." + fi + + - name: Comment on PR if bad files found + if: failure() && steps.check.outputs.bad_files != '' + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const badFiles = `\`\`\` +${{ steps.check.outputs.bad_files }} +\`\`\``; + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: `❌ Filenames with colons detected:\n${badFiles}\nPlease rename these files to remove ":" before merging.` + }) From 25656924c404fc253c6c9bc6ec21e3c58b67edac Mon Sep 17 00:00:00 2001 From: lachlan-robinson Date: Mon, 25 Aug 2025 19:12:33 +1000 Subject: [PATCH 2/6] fix: filenames script --- .github/workflows/validate-filenames.yml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/validate-filenames.yml b/.github/workflows/validate-filenames.yml index b876ca6a..46432fa4 100644 --- a/.github/workflows/validate-filenames.yml +++ b/.github/workflows/validate-filenames.yml @@ -1,4 +1,4 @@ -# .github/workflows/check-colon-in-filenames.yml +# .github/workflows/validate-filenames.yml name: Check filenames for colons on: @@ -15,7 +15,7 @@ jobs: - name: Get list of changed files id: files run: | - files=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files --jq '.[].filename') + files=$(gh pr view ${{ github.event.pull_request.number }} --json files --jq '.files[].path') echo "files<> $GITHUB_OUTPUT echo "$files" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT @@ -41,12 +41,9 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const badFiles = `\`\`\` -${{ steps.check.outputs.bad_files }} -\`\`\``; - github.rest.issues.createComment({ + const badFiles = process.env.BAD_FILES; + const body = `❌ Filenames with colons detected:\n\n\`\`\`\n${badFiles}\n\`\`\`\nPlease rename these files to remove ":" before merging.`; + await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, - issue_number: context.issue.number, - body: `❌ Filenames with colons detected:\n${badFiles}\nPlease rename these files to remove ":" before merging.` - }) + issue_number: context.issue.num_ From 1e055122f5ead5a688bee78c64b79a0c39ffd743 Mon Sep 17 00:00:00 2001 From: lachlan-robinson Date: Mon, 25 Aug 2025 19:19:29 +1000 Subject: [PATCH 3/6] chore: update script --- .github/workflows/validate-filenames.yml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/validate-filenames.yml b/.github/workflows/validate-filenames.yml index 46432fa4..d3be393d 100644 --- a/.github/workflows/validate-filenames.yml +++ b/.github/workflows/validate-filenames.yml @@ -32,6 +32,7 @@ jobs: echo "EOF" >> $GITHUB_OUTPUT exit 1 else + echo "bad_files=" >> $GITHUB_OUTPUT echo "No bad filenames found." fi @@ -41,9 +42,23 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const badFiles = process.env.BAD_FILES; - const body = `❌ Filenames with colons detected:\n\n\`\`\`\n${badFiles}\n\`\`\`\nPlease rename these files to remove ":" before merging.`; + const badFiles = process.env.BAD_FILES || ''; + if (badFiles.trim().length === 0) { + console.log("No bad files to report, skipping comment."); + return; + } + const body = [ + "❌ Filenames with colons detected:", + "```", + badFiles, + "```", + 'Please rename these files to remove ":" before merging.' + ].join("\n"); await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, - issue_number: context.issue.num_ + issue_number: context.issue.number, + body + }); + env: + BAD_FILES: ${{ steps.check.outputs.bad_files }} From a2192387d01593f8e330fe763865e86813105af4 Mon Sep 17 00:00:00 2001 From: lachlan-robinson Date: Mon, 25 Aug 2025 19:20:58 +1000 Subject: [PATCH 4/6] chore: Update Scripts --- .github/workflows/validate-filenames.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/validate-filenames.yml b/.github/workflows/validate-filenames.yml index d3be393d..c199aee9 100644 --- a/.github/workflows/validate-filenames.yml +++ b/.github/workflows/validate-filenames.yml @@ -1,5 +1,5 @@ # .github/workflows/validate-filenames.yml -name: Check filenames for colons +name: Check filenames on: pull_request: @@ -22,7 +22,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Check for colons + - name: Check if Valid Filename id: check run: | bad_files=$(echo "${{ steps.files.outputs.files }}" | grep ":" || true) @@ -36,7 +36,7 @@ jobs: echo "No bad filenames found." fi - - name: Comment on PR if bad files found + - name: Comment on PR if invalid filenames found if: failure() && steps.check.outputs.bad_files != '' uses: actions/github-script@v7 with: From a68e789607428c0530a591c80c20f7ce5b0b44c6 Mon Sep 17 00:00:00 2001 From: lachlan-robinson Date: Mon, 25 Aug 2025 19:24:57 +1000 Subject: [PATCH 5/6] chore: update language --- .github/workflows/validate-filenames.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/validate-filenames.yml b/.github/workflows/validate-filenames.yml index c199aee9..afd67269 100644 --- a/.github/workflows/validate-filenames.yml +++ b/.github/workflows/validate-filenames.yml @@ -1,5 +1,5 @@ # .github/workflows/validate-filenames.yml -name: Check filenames +name: Check Filenames on: pull_request: @@ -22,7 +22,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Check if Valid Filename + - name: Check For Valid Filenames id: check run: | bad_files=$(echo "${{ steps.files.outputs.files }}" | grep ":" || true) @@ -48,7 +48,7 @@ jobs: return; } const body = [ - "❌ Filenames with colons detected:", + "❌ Invalid Filenames Found:", "```", badFiles, "```", From 22d6f859c7e3b24af31e1f206660751b1f99b356 Mon Sep 17 00:00:00 2001 From: lachlan-robinson Date: Mon, 25 Aug 2025 19:28:47 +1000 Subject: [PATCH 6/6] chore: update to include more validations --- .github/workflows/validate-filenames.yml | 33 +++++++++++++++++++----- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/.github/workflows/validate-filenames.yml b/.github/workflows/validate-filenames.yml index afd67269..e31fd7a4 100644 --- a/.github/workflows/validate-filenames.yml +++ b/.github/workflows/validate-filenames.yml @@ -22,18 +22,37 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Check For Valid Filenames + - name: Validate Filenames (cross-platform) id: check run: | - bad_files=$(echo "${{ steps.files.outputs.files }}" | grep ":" || true) + bad_files="" + while IFS= read -r file; do + fname=$(basename "$file") + + # Check for illegal characters + if echo "$fname" | grep -qE '[:*?"<>|]'; then + bad_files="$bad_files\n$file (contains invalid characters)" + fi + + # Check for trailing space or dot + if echo "$fname" | grep -qE '(\.|\s)$'; then + bad_files="$bad_files\n$file (ends with space or dot)" + fi + + # Check for Windows reserved names (case-insensitive) + if echo "$fname" | grep -qiE '^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\..*)?$'; then + bad_files="$bad_files\n$file (reserved Windows filename)" + fi + done <<< "${{ steps.files.outputs.files }}" + if [ -n "$bad_files" ]; then echo "bad_files<> $GITHUB_OUTPUT - echo "$bad_files" >> $GITHUB_OUTPUT + echo -e "$bad_files" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT exit 1 else echo "bad_files=" >> $GITHUB_OUTPUT - echo "No bad filenames found." + echo "✅ All filenames are cross-platform safe." fi - name: Comment on PR if invalid filenames found @@ -48,11 +67,11 @@ jobs: return; } const body = [ - "❌ Invalid Filenames Found:", + "❌ Invalid Filenames Found (cross-platform check):", "```", - badFiles, + badFiles.trim(), "```", - 'Please rename these files to remove ":" before merging.' + "Please rename these files to remove reserved characters/names so they work across Windows, macOS, and Linux." ].join("\n"); await github.rest.issues.createComment({ owner: context.repo.owner,