Skip to content
Snippets Groups Projects
Verified Commit 71cc58ba authored by anarcat's avatar anarcat
Browse files

handle file renames in linter

When the `bullseye.mdwn` page was renamed (to `bullseye.md`) in this
commit:

commit 6fe448dc
Author: Antoine Beaupré <anarcat@debian.org>
Date:   Wed Sep 1 11:33:12 2021 -0400

    rename bullseye upgrade procedure file

    This is the only .mdwn file out there, strangely. Let's hope this is
    going to fix the garbled display issues, where code blocks show up
    with <pre><code> blobs.

diff --git a/howto/upgrades/bullseye.mdwn b/howto/upgrades/bullseye.md
similarity index 100%
rename from howto/upgrades/bullseye.mdwn
rename to howto/upgrades/bullseye.md

... the CI failed, because the hook couldn't find the `.mdwn` file to check:

https://gitlab.torproject.org/tpo/tpa/wiki-replica/-/jobs/35296

The actual error was:

$ ./bin/mdl-wrapper $(cat changed-files.txt)
checking file howto/upgrades/bullseye.md...
checking howto/upgrades/bullseye.mdwn...
/usr/lib/ruby/gems/2.6.0/gems/mdl-0.11.0/lib/mdl/doc.rb:50:in `read': No such file or directory @ rb_sysopen - howto/upgrades/bullseye.mdwn (Errno::ENOENT)
	from /usr/lib/ruby/gems/2.6.0/gems/mdl-0.11.0/lib/mdl/doc.rb:50:in `new_from_file'
	from /usr/lib/ruby/gems/2.6.0/gems/mdl-0.11.0/lib/mdl.rb:82:in `block in run'
	from /usr/lib/ruby/gems/2.6.0/gems/mdl-0.11.0/lib/mdl.rb:80:in `each'
	from /usr/lib/ruby/gems/2.6.0/gems/mdl-0.11.0/lib/mdl.rb:80:in `run'
	from /usr/lib/ruby/gems/2.6.0/gems/mdl-0.11.0/bin/mdl:10:in `<top (required)>'
	from /usr/bin/mdl:23:in `load'
	from /usr/bin/mdl:23:in `<main>'
Cleaning up file based variables 00:03
ERROR: Job failed: exit code 1

In our code, we assume that if a path is not a file, it's a directory,
but that's not quite right: it could also be just missing!

So handle that other case more elegantly.
parent 28e4335f
No related branches found
No related tags found
No related merge requests found
......@@ -6,15 +6,18 @@
# files, if provided a directory, it will just throw the entire thing
# at mdl.
for path in "$@"; do
if [ -f "$path" ]; then
if [ -d "$path" ]; then
echo "checking directory $path..."
mdl "$path"
elif ! [ -e "$path" ]; then
echo "file $path does not exist, maybe it was removed or renamed? skipping."
else
# this could be a symlink, a normal file, or whatever, but it exists
case "$path" in
*.md|*.mdwn|*.markdown)
echo "checking file $path..."
# this also removes [x] style checklists which kramdown doesn't like
sed 's/^\[\[_TOC_\]\]/TOC_PLACEHOLDER/;s/^ *\([*-]\|[0-9][0-9]*\.\) *\[[x ]\] /\* /' "$path" | mdl - ;;
esac
else
echo "checking $path..."
mdl "$path"
fi
done
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment