tldr/scripts/test.sh

55 lines
1.6 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2020-06-09 15:03:35 +01:00
# This script is executed by GitHub Actions for every successful push (on any branch, PR or not).
# It runs some basic tests on pages. If the build is also a PR, additional
# checks are run through the check-pr script, and any message or error is sent
# to tldr-bot to be commented on the PR.
#
# NOTE: must be run from the repository root directory to correctly work!
# NOTE: `set -e` is applied conditionally only if needed.
2019-11-27 17:22:38 +00:00
# Default test function, ran by `npm test`.
function run_tests {
markdownlint pages*/**/*.md
tldr-lint ./pages
}
2020-06-09 15:03:35 +01:00
# Special test function for GitHub Actions pull request builds.
2019-11-27 17:22:38 +00:00
# Runs run_tests collecting errors for tldr-bot.
function run_tests_pr {
errs=$(run_tests 2>&1)
if [ -n "$errs" ]; then
echo -e "Test failed!\n$errs\n" >&2
echo 'Sending errors to tldr-bot.' >&2
2019-11-18 21:58:03 +00:00
echo -n "$errs" | python3 scripts/send-to-bot.py report-errors
exit 1
fi
}
2020-06-09 15:03:35 +01:00
# Additional checks for GitHub Actions pull request builds.
# Only taken as suggestions, does not make the build fail.
2019-11-27 17:22:38 +00:00
function run_checks_pr {
msgs=$(bash scripts/check-pr.sh)
if [ -n "$msgs" ]; then
echo -e "\nCheck PR reported the following message(s):\n$msgs\n" >&2
echo 'Sending check results to tldr-bot.' >&2
2019-11-18 21:58:03 +00:00
echo -n "$msgs" | python3 scripts/send-to-bot.py report-check-results
fi
}
###################################
# MAIN
###################################
2020-06-24 13:11:33 +01:00
if [ "$CI" = "true" ] && [ "$GITHUB_REPOSITORY" = "tldr-pages/tldr" ] && [ "$PULL_REQUEST_ID" != "false" ]; then
2019-11-27 17:22:38 +00:00
run_checks_pr
run_tests_pr
else
set -e
2019-11-27 17:22:38 +00:00
run_tests
fi
echo 'Test ran succesfully!'