Skip to content

Commit

Permalink
Merge pull request #1708 from EliahKagan/run-ci/mode
Browse files Browse the repository at this point in the history
Check for executable bits that disagree with shebangs
  • Loading branch information
Byron authored Nov 28, 2024
2 parents 1d73d00 + 82cbc0a commit 34efe03
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,14 @@ jobs:
- name: gix-pack with all features (including wasm)
run: cd gix-pack && cargo build --all-features --target "$TARGET"

check-mode:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Find scripts with mode/shebang mismatch
run: etc/check-mode.sh

check-packetline:
strategy:
fail-fast: false
Expand Down Expand Up @@ -441,6 +449,7 @@ jobs:
- test-32bit-cross
- lint
- cargo-deny
- check-mode
- check-packetline
- check-blocking

Expand Down
40 changes: 40 additions & 0 deletions etc/check-mode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

set -eu -o pipefail

# Go to the worktree's root. (Even if the dir name ends in a newline.)
root_padded="$(git rev-parse --show-toplevel && echo -n .)"
root="${root_padded%$'\n.'}"
cd -- "$root"

symbolic_shebang="$(printf '#!' | od -An -ta)"
status=0

function check () {
local mode="$1" oid="$2" path="$3" symbolic_magic

# Extract the first two bytes (or less if shorter) and put in symbolic form.
symbolic_magic="$(git cat-file blob "$oid" | od -N2 -An -ta)"

# Check for inconsistency between the mode and whether `#!` is present.
if [ "$mode" = 100644 ] && [ "$symbolic_magic" = "$symbolic_shebang" ]; then
printf 'mode -x but has shebang: %q\n' "$path"
elif [ "$mode" = 100755 ] && [ "$symbolic_magic" != "$symbolic_shebang" ]; then
printf 'mode +x but no shebang: %q\n' "$path"
else
return 0
fi

status=1
}

# Check regular files named with a `.sh` suffix.
while read -rd '' mode oid _stage_number path; do
case "$mode" in
100644 | 100755)
check "$mode" "$oid" "$path"
;;
esac
done < <(git ls-files -sz -- '*.sh')

exit "$status"
Empty file modified gix-diff/tests/fixtures/make_diff_for_rewrites_repo.sh
100644 → 100755
Empty file.
Empty file modified gix-merge/tests/fixtures/make_blob_repo.sh
100644 → 100755
Empty file.
Empty file modified gix-merge/tests/fixtures/text-baseline.sh
100644 → 100755
Empty file.
Empty file modified gix-merge/tests/fixtures/tree-baseline.sh
100644 → 100755
Empty file.
Empty file modified gix-revision/tests/fixtures/merge_base_octopus_repos.sh
100644 → 100755
Empty file.
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ fmt:
find-yanked:
cargo install --debug --locked --no-default-features --features max-pure --path .

# Find shell scripts whose +x/-x bits and magic bytes (e.g. `#!`) disagree
check-mode:
./etc/check-mode.sh

# Delete gix-packetline-blocking/src and regenerate from gix-packetline/src
copy-packetline:
./etc/copy-packetline.sh

0 comments on commit 34efe03

Please sign in to comment.