From 087c7679dc3221aed60a08cd9c2e80325cece415 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 13 Jan 2025 09:04:18 +0000 Subject: [PATCH] feat: add `check-for-ignored` script Checks for ignored files that have been tracked by git. --- .forgejo/workflows/push-next.yml | 15 ++++++++------- Dockerfile | 2 ++ README.md | 15 +++++++++++++++ scripts/check-for-ignored | 30 ++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 7 deletions(-) create mode 100755 scripts/check-for-ignored diff --git a/.forgejo/workflows/push-next.yml b/.forgejo/workflows/push-next.yml index f17055e..e1a445d 100644 --- a/.forgejo/workflows/push-next.yml +++ b/.forgejo/workflows/push-next.yml @@ -19,13 +19,14 @@ jobs: - uses: actions/checkout@v4 - name: Ignored Files - run: | - IGNORED=$(git ls-files --cached -i --exclude-standard) - if [ -n "$IGNORED" ] - then - echo "Ignored files present:\n$IGNORED" - exit 1 - fi + run: check-for-ignored + # run: | + # IGNORED=$(git ls-files --cached -i --exclude-standard) + # if [ -n "$IGNORED" ] + # then + # echo "Ignored files present:\n$IGNORED" + # exit 1 + # fi - name: Machete run: cargo machete diff --git a/Dockerfile b/Dockerfile index 23b5fdd..4c4011c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" && \ git config --global user.name "ForgeJo Action. See: https://git.kemitix.net/kemitix/rust" +COPY scripts/ /usr/local/bin/ + WORKDIR /app diff --git a/README.md b/README.md index f3637c6..9e42799 100644 --- a/README.md +++ b/README.md @@ -42,3 +42,18 @@ The available toolchain in the image are: - cargo-chef - cargo-hack - 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 +``` diff --git a/scripts/check-for-ignored b/scripts/check-for-ignored new file mode 100755 index 0000000..90f8626 --- /dev/null +++ b/scripts/check-for-ignored @@ -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