GitHub action to check for non-binary, non-utf-8, and non-ascii
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 17
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
every time a push is made, it searches the entire repo for files that are non-binary, non-utf-8, and non-ascii, and fails with a list of files if it finds any (otherwise passes)
-- @cjyetman
I'll keep the thread history below because the development over time might be interesting/instructive, but this is the version I would advise to use...
name: check file encodings in PR
on: [pull_request]
jobs:
file-encoding:
name: file encooding check
runs-on: ubuntu-latest
steps:
- name: run the checkout action
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: list all changed files
run: |
files=$(git diff --name-only origin/$GITHUB_BASE_REF...${{ github.sha }})
IFS=$'\n'; files=($files); unset IFS; # split the string into an array
file --mime "${files[@]}"
- name: list all changed files with the wrong encoding
run: |
files=$(git diff --name-only origin/$GITHUB_BASE_REF...${{ github.sha }})
IFS=$'\n'; files=($files); unset IFS; # split the string into an array
! file --mime "${files[@]}" | grep -v "charset=utf-8\|charset=us-ascii\|charset=binary\| (No such file or directory)$"
This was the originally proposed version...
name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: run the checkout action
uses: actions/checkout@v1
- name: list the directory
run: echo '! find $GITHUB_WORKSPACE -type f -exec file --mime {} \; | grep -v "charset=binary$" | grep -v "charset=us-ascii$" | grep -v "charset=utf-8$"' | bash
--
Thanks @cjyetman
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the GitHub Actions YAML shown in the issue and review its checkout, git diff, and file --mime steps. The work is done when the workflow checks the intended files, fails with non-UTF-8, non-ASCII, or non-binary matches, and passes otherwise.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- github-actions, shell
- Domain
- ci-cd, devops
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100