64 lines
1.6 KiB
Bash
Executable File
64 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
usage() {
|
|
echo "usage: $0 <coverage-publication-root>" >&2
|
|
exit 2
|
|
}
|
|
|
|
[ "$#" -eq 1 ] || usage
|
|
publication_root=$1
|
|
|
|
case "$publication_root" in
|
|
/*) ;;
|
|
*)
|
|
echo "coverage publication root must be an absolute path: $publication_root" >&2
|
|
exit 2
|
|
;;
|
|
esac
|
|
|
|
if [ ! -d "$publication_root" ] || [ ! -w "$publication_root" ]; then
|
|
echo "coverage publication root is not a writable directory: $publication_root" >&2
|
|
exit 2
|
|
fi
|
|
|
|
for artifact in coverage/coverage.svg coverage/lcov.info coverage/summary.json coverage/html/index.html; do
|
|
if [ ! -f "$artifact" ]; then
|
|
echo "required coverage artifact is missing: $artifact" >&2
|
|
exit 2
|
|
fi
|
|
done
|
|
|
|
commit=$(git rev-parse --verify HEAD)
|
|
case "$commit" in
|
|
*[!0-9a-f]*|'')
|
|
echo "Git returned an invalid commit identifier: $commit" >&2
|
|
exit 2
|
|
;;
|
|
esac
|
|
|
|
project_root="$publication_root/MadGobblins/vsg-bridge-ls"
|
|
destination="$project_root/$commit"
|
|
mkdir -p -- "$project_root"
|
|
|
|
if [ -e "$destination" ]; then
|
|
if cmp -s coverage/summary.json "$destination/summary.json"; then
|
|
echo "coverage for $commit is already published"
|
|
else
|
|
echo "refusing to overwrite different coverage for immutable commit $commit" >&2
|
|
exit 1
|
|
fi
|
|
else
|
|
staging=$(mktemp -d "$project_root/.publish.XXXXXX")
|
|
trap 'rm -rf -- "$staging"' EXIT HUP INT TERM
|
|
cp -R -- coverage/. "$staging/"
|
|
mv -- "$staging" "$destination"
|
|
trap - EXIT HUP INT TERM
|
|
fi
|
|
|
|
latest_link="$project_root/.main.$$"
|
|
ln -s -- "$commit" "$latest_link"
|
|
mv -f -- "$latest_link" "$project_root/main"
|
|
|
|
echo "published coverage for $commit to $destination"
|