Skip to content
Merged
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
57 changes: 57 additions & 0 deletions .github/workflows/check-shebangs-and-filemodes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# shebangとfilemodeが一貫しているかをチェックする。またbashファイルについてもこの両者についてチェックする。
name: Check shebangs and filemodes

on:
push:

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Check shebangs and filemodes
run: |
blobs=$(git ls-files -s | grep '^100')

while read -r blob; do
filemode=$(awk '{ print $1 }' <<< "$blob")
filename=$(awk '{ print $4 }' <<< "$blob")

first_line=$(head -n 1 "$filename")
shebang_line=$(grep '^#!/' <<< "$first_line" || true)

has_shebang() {
[ -n "$shebang_line" ]
}

is_shellscript() {
[[ "$filename" =~ \.(ba)?sh$ ]]
}

is_executable() {
[ "$filemode" = 100755 ]
}

echo -n "$filename ($filemode): "

if has_shebang && ! is_executable; then
# shellcheck disable=SC2016
echo 'A shebanged file must be executable (note: if you are using Windows, please change the filemode with `git update-index --chmod+x`)'
exit 1
fi

if is_shellscript && ! is_executable; then
# shellcheck disable=SC2016
echo 'A shell script file must be executable (note: if you are using Windows, please change the filemode with `git update-index --chmod+x`)'
exit 1
fi

if is_executable && ! has_shebang; then
echo 'An executable blob must have a shebang'
exit 1
fi

echo OK
done <<< "$blobs"