mirror of
https://github.com/tldr-pages/tldr.git
synced 2024-10-28 11:19:46 +01:00
test: use shellcheck for Bash files (#13974)
This commit is contained in:
parent
c9f4806a57
commit
70d2c92ac0
2 changed files with 19 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: MIT
|
||||
# shellcheck disable=SC2016,SC2059
|
||||
|
||||
# This script is executed by GitHub Actions for every pull request opened.
|
||||
# It currently accomplishes the following objectives:
|
||||
|
@ -22,7 +23,6 @@
|
|||
function check_duplicates {
|
||||
local page=$1 # page path in the format 'pages<.language_code>/platform/pagename.md'
|
||||
local parts
|
||||
local other
|
||||
|
||||
readarray -td'/' parts < <(echo -n "$page")
|
||||
|
||||
|
@ -114,9 +114,7 @@ function check_outdated_page() {
|
|||
function check_more_info_link() {
|
||||
local page=$1
|
||||
|
||||
grep "$page" "more-info-links.txt" > /dev/null
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
if grep "$page" "more-info-links.txt" > /dev/null; then
|
||||
printf "\x2d $MSG_MORE_INFO" "$page"
|
||||
fi
|
||||
}
|
||||
|
@ -124,9 +122,7 @@ function check_more_info_link() {
|
|||
function check_page_title() {
|
||||
local page=$1
|
||||
|
||||
grep "$page" "page-titles.txt" > /dev/null
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
if grep "$page" "page-titles.txt" > /dev/null; then
|
||||
printf "\x2d $MSG_PAGE_TITLE" "$page"
|
||||
fi
|
||||
}
|
||||
|
@ -149,7 +145,7 @@ function check_diff {
|
|||
python3 scripts/set-more-info-link.py -Sn > more-info-links.txt
|
||||
python3 scripts/set-page-title.py -Sn > page-titles.txt
|
||||
|
||||
while read line; do
|
||||
while read -r line; do
|
||||
readarray -td$'\t' entry < <(echo -n "$line")
|
||||
|
||||
local change="${entry[0]}"
|
||||
|
@ -180,6 +176,8 @@ function check_diff {
|
|||
;;
|
||||
esac
|
||||
done <<< "$git_diff"
|
||||
|
||||
rm more-info-links.txt page-titles.txt
|
||||
}
|
||||
|
||||
# Recursively check the pages/ folder for anomalies.
|
||||
|
|
|
@ -21,7 +21,7 @@ function run_black {
|
|||
target_black_version=$(awk -F '==' '$1 == "black" { print $2 }' < requirements.txt)
|
||||
|
||||
if grep -qw black <<< "$(pip3 --disable-pip-version-check list)"; then
|
||||
errs=$(python3 -m black scripts --check --required-version ${target_black_version} 2>&1 || true)
|
||||
errs=$(python3 -m black scripts --check --required-version "${target_black_version}" 2>&1 || true)
|
||||
fi
|
||||
|
||||
if [[ -z $errs ]]; then
|
||||
|
@ -31,7 +31,7 @@ function run_black {
|
|||
return 0
|
||||
fi
|
||||
|
||||
errs=$(black scripts --check --required-version ${target_black_version} 2>&1 || true)
|
||||
errs=$(black scripts --check --required-version "${target_black_version}" 2>&1 || true)
|
||||
fi
|
||||
|
||||
if [[ ${errs} == *"does not match the running version"* ]]; then
|
||||
|
@ -71,6 +71,16 @@ function run_pytest {
|
|||
fi
|
||||
}
|
||||
|
||||
function run_shellcheck {
|
||||
# skip shellcheck check if the command is not available in the system.
|
||||
if [[ $CI != true ]] && ! exists shellcheck; then
|
||||
echo "Skipping shellcheck check, command not available."
|
||||
return 0
|
||||
fi
|
||||
|
||||
shellcheck scripts/*.sh
|
||||
}
|
||||
|
||||
# Default test function, run by `npm test`.
|
||||
function run_tests {
|
||||
find pages* -name '*.md' -exec markdownlint {} +
|
||||
|
@ -89,6 +99,7 @@ function run_tests {
|
|||
run_black
|
||||
run_flake8
|
||||
run_pytest
|
||||
run_shellcheck
|
||||
}
|
||||
|
||||
# Special test function for GitHub Actions pull request builds.
|
||||
|
|
Loading…
Reference in a new issue