test.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env bash
  2. # This script is executed by GitHub Actions for every successful push (on any branch, PR or not).
  3. # It runs some basic tests on pages. If the build is also a PR, additional
  4. # checks are run through the check-pr script, and any message or error is sent
  5. # to tldr-bot to be commented on the PR.
  6. #
  7. # NOTE: must be run from the repository root directory to correctly work!
  8. # NOTE: `set -e` is applied conditionally only if needed.
  9. # Default test function, ran by `npm test`.
  10. function run_tests {
  11. markdownlint pages*/**/*.md
  12. tldr-lint ./pages
  13. for f in ./pages.*; do
  14. tldr-lint --ignore "TLDR003,TLDR004,TLDR005,TLDR015,TLDR104" ${f}
  15. done
  16. }
  17. # Special test function for GitHub Actions pull request builds.
  18. # Runs run_tests collecting errors for tldr-bot.
  19. function run_tests_pr {
  20. errs=$(run_tests 2>&1)
  21. if [ -n "$errs" ]; then
  22. echo -e "Test failed!\n$errs\n" >&2
  23. echo 'Sending errors to tldr-bot.' >&2
  24. echo -n "$errs" | python3 scripts/send-to-bot.py report-errors
  25. exit 1
  26. fi
  27. }
  28. # Additional checks for GitHub Actions pull request builds.
  29. # Only taken as suggestions, does not make the build fail.
  30. function run_checks_pr {
  31. msgs=$(bash scripts/check-pr.sh)
  32. if [ -n "$msgs" ]; then
  33. echo -e "\nCheck PR reported the following message(s):\n$msgs\n" >&2
  34. echo 'Sending check results to tldr-bot.' >&2
  35. echo -n "$msgs" | python3 scripts/send-to-bot.py report-check-results
  36. fi
  37. }
  38. ###################################
  39. # MAIN
  40. ###################################
  41. if [ "$CI" = "true" ] && [ "$GITHUB_REPOSITORY" = "tldr-pages/tldr" ] && [ "$PULL_REQUEST_ID" != "" ]; then
  42. run_checks_pr
  43. run_tests_pr
  44. else
  45. set -e
  46. run_tests
  47. fi
  48. echo 'Test ran succesfully!'