From 5f48ef87bc5bf361f05b37853bd4f1ddc0153b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20Mart=C3=ADnez?= Date: Wed, 23 Oct 2024 21:02:26 -0700 Subject: [PATCH 1/2] actions: adding a workflow to check for stale hints --- .github/workflows/stale_hints.yml | 19 +++++++++++++++++++ .scripts/remove_stale_hints.sh | 13 +++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/stale_hints.yml diff --git a/.github/workflows/stale_hints.yml b/.github/workflows/stale_hints.yml new file mode 100644 index 00000000000..f7388d7001a --- /dev/null +++ b/.github/workflows/stale_hints.yml @@ -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 diff --git a/.scripts/remove_stale_hints.sh b/.scripts/remove_stale_hints.sh index e8e8f20570c..db029f17465 100755 --- a/.scripts/remove_stale_hints.sh +++ b/.scripts/remove_stale_hints.sh @@ -2,6 +2,11 @@ set -eu +list=false +if [ $# -gt 0 ] && [ $1 == "list" ]; then + list=true +fi + declare -A files # Store all basenames in repo declare -A hints # Store all paths of hints in repo @@ -27,7 +32,11 @@ for h0 in "${!hints[@]}"; do # 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 From 23f2b1fb2d882dee83836aca4bc6fff50ed28a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20Mart=C3=ADnez?= Date: Wed, 23 Oct 2024 21:31:05 -0700 Subject: [PATCH 2/2] scripts: remove_stale_hints: make it faster --- .scripts/remove_stale_hints.sh | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.scripts/remove_stale_hints.sh b/.scripts/remove_stale_hints.sh index db029f17465..720f5b34382 100755 --- a/.scripts/remove_stale_hints.sh +++ b/.scripts/remove_stale_hints.sh @@ -7,8 +7,8 @@ if [ $# -gt 0 ] && [ $1 == "list" ]; then list=true fi -declare -A files # Store all basenames in repo -declare -A hints # Store all paths of hints in repo +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 @@ -16,18 +16,21 @@ trap 'RC=$?; rm -f .filelist; exit $RC' EXIT INT # 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.