Skip to content

Commit

Permalink
#110 unregister
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Oct 12, 2023
1 parent 3bc654f commit 878323c
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 6 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ define step
endef

# The main goal
all: $(TARGET)/start.txt $(TARGET)/repositories.csv polish clone jpeek filter measure aggregate zip
all: $(TARGET)/start.txt $(TARGET)/repositories.csv polish clone unregister jpeek filter measure aggregate zip
echo -e "\n\nSUCCESS (made by yegor256/cam $(VERSION)$$("$${LOCAL}/help/tdiff.sh" "$$(cat "$(TARGET)/start.txt")"))!"

install:
Expand Down Expand Up @@ -124,6 +124,10 @@ $(TARGET)/repositories.csv: $(TARGET)/temp
polish: $(TARGET)/repositories.csv $(TARGET)/github
$(call step,polish)

# Delete directories from the CSV register if their clones are absent.
unregister: $(TARGET)/repositories.csv $(TARGET)/github
$(call step,unregister)

# Clone all necessary repositories.
# Don't touch those that already have any files in the dirs.
clone: $(TARGET)/repositories.csv $(TARGET)/github
Expand Down
4 changes: 2 additions & 2 deletions steps/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ find "${LOCAL}/tests" -name '*.sh' | sort | while IFS= read -r test; do
rm -rf "${tgt}"
fi
mkdir -p "${tgt}"
stdout=${temp}/${name}.log
stdout=${t}/stdout.log
mkdir -p "$(dirname "${stdout}")"
touch "${stdout}"
if ! TARGET="${tgt}" "${test}" "${t}" "${stdout}"; then
cat "${stdout}"
echo "❌ Non-zero exit code"
echo "❌ Non-zero exit code (TARGET=${tgt})"
exit 1
fi
done
54 changes: 54 additions & 0 deletions steps/unregister.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
# The MIT License (MIT)
#
# Copyright (c) 2021-2023 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
set -e
set -o pipefail

csv=${TARGET}/repositories.csv

if [ ! -e "${csv}" ]; then
echo "Nothing to unregister, the CSV is absent: ${csv}"
exit
fi

before="${TARGET}/temp/repositories-before-unregister.txt"
mkdir -p "$(dirname "${before}")"
tail -n +2 "${csv}" > "${before}"

head=$(head -1 "${csv}")
rm -f "${csv}"
echo ${head} > "${csv}"

declare -i total=0
declare -i good=0
while IFS=',' read -r r tag tail; do
if [ -z "${r}" ]; then continue; fi
total=$((total+1))
if [ ! -e "${TARGET}/github/${r}" ]; then
echo "The clone of ${r} is absent, unregistered"
else
printf "%s,%s,%s\n" "${r}" "${tag}" "${tail}" >> "${csv}"
good=$((good+1))
fi
done < "${before}"
echo "All ${total} repositories checked, ${good} are good"

2 changes: 1 addition & 1 deletion tests/steps/test-jpeek.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mkdir -p "${TARGET}/github/${repo}"
cp -r "${LOCAL}/fixtures/jaxec"/* "${TARGET}/github/${repo}"
msg=$("${LOCAL}/steps/jpeek.sh")
echo "${msg}" > "${stdout}"
echo "${msg}" | grep -v "Analyzed ${repo} through jPeek" > "${stdout}" 2>&1
echo "${msg}" | grep "Analyzed ${repo} through jPeek" > "${stdout}" 2>&1
mfile=${TARGET}/measurements/${repo}/src/main/java/com/yegor256/Jaxec.java.m.NHD
value=$(cat "${mfile}")
test ! "${value}" = '0'
Expand Down
4 changes: 2 additions & 2 deletions tests/steps/test-polish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ rm -rf "${TARGET}/github"
mkdir -p "${TARGET}/github/foo/bar"
msg=$("${LOCAL}/steps/polish.sh")
test -e "${TARGET}/github/foo/bar"
echo "${msg}" | grep -v "foo/bar is already here" > "${stdout}" 2>&1
echo "${msg}" | grep "foo/bar is already here" > "${stdout}" 2>&1
echo "👍🏻 A correct directory was not deleted"

touch "${TARGET}/repositories.csv"
rm -rf "${TARGET}/github"
mkdir -p "${TARGET}/github/foo/bar"
msg=$("${LOCAL}/steps/polish.sh")
echo "${msg}" | grep -v "foo/bar is obsolete and was deleted" > "${stdout}" 2>&1
echo "${msg}" | grep -v "All 1 repo directories" > "${stdout}" 2>&1
echo "${msg}" | grep "All 1 repo directories" > "${stdout}" 2>&1
echo "👍🏻 An obsolete directory was deleted"

TARGET=${TARGET}/dir-is-absent
Expand Down
39 changes: 39 additions & 0 deletions tests/steps/test-unregister.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# The MIT License (MIT)
#
# Copyright (c) 2021-2023 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
set -e
set -o pipefail

stdout=$2

echo -e 'repo,branch\nfoo/bar,master,44,99\nboom/boom,master\n' > "${TARGET}/repositories.csv"
rm -rf "${TARGET}/github"
mkdir -p "${TARGET}/github/boom/boom"
msg=$("${LOCAL}/steps/unregister.sh")
echo "${msg}" >> "${stdout}"
cat "${TARGET}/temp/repositories-before-unregister.txt" >> "${stdout}"
cat "${TARGET}/repositories.csv" >> "${stdout}"
test "$(wc -l < "${TARGET}/repositories.csv" | xargs)" = '2'
cat "${TARGET}/repositories.csv" | grep "boom/boom" >> "${stdout}" 2>&1
echo "${msg}" | grep "All 2 repositories checked" >> "${stdout}" 2>&1
echo "${msg}" | grep "The clone of foo/bar is absent, unregistered" >> "${stdout}" 2>&1
echo "👍🏻 A broken repo clone was unregistered"

0 comments on commit 878323c

Please sign in to comment.