Skip to content

Commit

Permalink
Merge pull request #3595 from mtzguido/stale
Browse files Browse the repository at this point in the history
actions: adding a workflow to check for stale hints
  • Loading branch information
mtzguido authored Oct 25, 2024
2 parents a6a8ba7 + 23f2b1f commit 8b6fce6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/stale_hints.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Check for stale hints
on:
pull_request:
workflow_dispatch:
jobs:
check_stale_hints:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- run: |
L=$(.scripts/remove_stale_hints.sh list)
if [ "$L" != "" ]; then
echo "There are stale hints:"
echo "$L"
false
fi
32 changes: 22 additions & 10 deletions .scripts/remove_stale_hints.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,44 @@

set -eu

declare -A files # Store all basenames in repo
declare -A hints # Store all paths of hints in repo
list=false
if [ $# -gt 0 ] && [ $1 == "list" ]; then
list=true
fi

declare -A files # Store all basenames for non-hint files in repo (value = 1, this is just a set)
declare -A hints # Store a map from hint paths into basenames (turns out basename computation was a bottleneck)

trap 'RC=$?; rm -f .filelist; exit $RC' EXIT INT

# Find all (normal) files, not descending into .git, and store in
# the array. Using a pipe here would be better, but a pipe creates a
# subshell, so changes to the variables won't have any effect in the
# parent.
find . -name '.git' -prune -o \( -type f \) > .filelist
find . -name '.git' -prune -false -o \( -type f -name '*.hints' \) > .filelist
while read f0; do
f="$(basename "${f0}")"
files[$f]=1;
if [[ "$f0" == *.hints ]]; then
hints[$f0]=1
fi
hints[$f0]=$f
done < .filelist

find . -name '.git' -prune -false -o \( -type f -not -name '*.hints' \) -printf '%f\n' > .filelist
while read f; do
files[$f]=1
done < .filelist

rm -f .filelist

for h0 in "${!hints[@]}"; do
h="$(basename "${h0}")"
h=${hints[$h0]}
h="${h%.hints}"
# Given a/b/c/Foo.Bar.fst.hints, if there is no Foo.Bar.fst
# anywhere, then delete the hint file.
if ! [ -v "files[$h]" ]; then
echo "DELETING HINT $h0"
rm -f "${h0}"
if $list; then
echo "$h0"
else
echo "DELETING HINT $h0"
rm -f "${h0}"
fi
fi
done

0 comments on commit 8b6fce6

Please sign in to comment.