feat: add check-for-ignored script
All checks were successful
/ test (map[name:nightly]) (push) Successful in 4s
/ test (map[name:stable]) (push) Successful in 5s
/ test (map[name:1.74.1]) (push) Successful in 5s

Checks for ignored files that have been tracked by git.
This commit is contained in:
Paul Campbell 2025-01-13 09:04:18 +00:00
parent 5d372a60de
commit b853a6acec
3 changed files with 47 additions and 0 deletions

View file

@ -39,4 +39,6 @@ RUN rustup install nightly && rustup component add --toolchain nightly rustfmt c
RUN git config --global user.email "action@git.kemitix.net" && \ RUN git config --global user.email "action@git.kemitix.net" && \
git config --global user.name "ForgeJo Action. See: https://git.kemitix.net/kemitix/rust" git config --global user.name "ForgeJo Action. See: https://git.kemitix.net/kemitix/rust"
COPY scripts/ /usr/local/bin/
WORKDIR /app WORKDIR /app

View file

@ -42,3 +42,18 @@ The available toolchain in the image are:
- cargo-chef - cargo-chef
- cargo-hack - cargo-hack
- release-plz - release-plz
### Scripts
- `check-for-ignored`
Checks for files that are being tracked by Git but should be ignored according
to the `.gitignore` file.
#### Usage
```yaml
steps:
- name: Check for Ignored Files
run: check-for-ignored
```

30
scripts/check-for-ignored Executable file
View file

@ -0,0 +1,30 @@
#!/usr/bin/env bash
# Exit on error
set -e
# Check if git is installed
if ! command -v git &> /dev/null; then
echo "Error: git is not installed"
exit 1
fi
# Check if we're in a git repository
if ! git rev-parse --is-inside-work-tree &> /dev/null; then
echo "Error: not in a git repository"
exit 1
fi
echo "Checking for tracked files that should be ignored..."
# Find files that are both tracked and ignored
ignored_files=$(git ls-files --cached -i --exclude-standard)
if [[ -z "$ignored_files" ]]; then
echo "No tracked files are marked as ignored"
exit 0
else
echo "The following tracked files are marked as ignored:"
echo "$ignored_files"
exit 1
fi