Fix pre-push check to check commited files, not staged.
This commit is contained in:
parent
7471b48794
commit
6a810475df
1 changed files with 63 additions and 53 deletions
|
|
@ -1,19 +1,22 @@
|
|||
#!/usr/bin/env bash
|
||||
# PRE-PUSH
|
||||
# Check the repo for dependency, language, vulnerability, and build issues
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Colors
|
||||
# Setting log colours
|
||||
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
|
||||
|
||||
echo -e "${GREEN}Running pre-push checks...${NC}"
|
||||
|
||||
# Paths
|
||||
# Setting paths
|
||||
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
|
||||
CONTENT_DIR="$REPO_ROOT/content"
|
||||
ZENSICAL_CFG_PATH="$REPO_ROOT/zensical.toml"
|
||||
SITE_DIR="$REPO_ROOT/deploy"
|
||||
LOG_DIR="$REPO_ROOT/logs"
|
||||
|
||||
# Clean logs
|
||||
# Removing the old logs and recreating logs folder
|
||||
rm -rf "$LOG_DIR"; mkdir -p "$LOG_DIR"
|
||||
|
||||
SERVER_PID=""
|
||||
|
|
@ -50,7 +53,7 @@ else
|
|||
echo -e "${YELLOW}TruffleHog or jq not installed. Skipping secrets scan.${NC}"
|
||||
fi
|
||||
|
||||
# Dependabot-like dependency vulnerability check
|
||||
# Dependabot dependency vulnerability check
|
||||
if command -v npm &>/dev/null && [[ -f package.json ]]; then
|
||||
echo -e "${GREEN}Running npm audit...${NC}"
|
||||
npm audit --audit-level=high >"$LOG_DIR/npm-audit.log" 2>&1 || {
|
||||
|
|
@ -70,11 +73,14 @@ fi
|
|||
# Lint all the markdown files using markdownlint-cli2
|
||||
if command -v markdownlint-cli2 &>/dev/null; then
|
||||
echo -e "${GREEN}Running markdownlint...${NC}"
|
||||
MD_FILES="$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.md$' || true)"
|
||||
# Check committed Markdown files instead of staged ones
|
||||
MD_FILES="$(git diff HEAD~1 HEAD --name-only --diff-filter=ACM | grep -E '\.md$' || true)"
|
||||
if [[ -n "$MD_FILES" ]]; then
|
||||
# shellcheck disable=SC2086
|
||||
echo $MD_FILES | xargs markdownlint-cli2 >"$LOG_DIR/markdownlint.log" 2>&1 || {
|
||||
echo -e "${RED}markdownlint-cli2 failed. See $LOG_DIR/markdownlint.log${NC}"; exit 1; }
|
||||
else
|
||||
echo -e "${YELLOW}No committed Markdown files found. Skipping markdown check.${NC}"
|
||||
fi
|
||||
else
|
||||
echo -e "${YELLOW}markdownlint-cli2 not installed. Skipping markdown check.${NC}"
|
||||
|
|
@ -83,11 +89,14 @@ fi
|
|||
# Lint language using Vale
|
||||
if command -v vale &>/dev/null && [[ -f "$REPO_ROOT/.vale.ini" ]]; then
|
||||
echo -e "${GREEN}Running Vale...${NC}"
|
||||
VALE_FILES="$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.md$' || true)"
|
||||
# Check committed Markdown files instead of staged ones
|
||||
VALE_FILES="$(git diff HEAD~1 HEAD --name-only --diff-filter=ACM | grep -E '\.md$' || true)"
|
||||
if [[ -n "$VALE_FILES" ]]; then
|
||||
# shellcheck disable=SC2086
|
||||
echo $VALE_FILES | xargs vale >"$LOG_DIR/vale.log" 2>&1 || {
|
||||
echo -e "${RED}Vale issues. See $LOG_DIR/vale.log${NC}"; exit 1; }
|
||||
else
|
||||
echo -e "${YELLOW}No committed Markdown files found. Skipping Vale check.${NC}"
|
||||
fi
|
||||
else
|
||||
echo -e "${YELLOW}Vale not installed or .vale.ini missing. Skipping Vale.${NC}"
|
||||
|
|
@ -98,5 +107,6 @@ if ! command -v zensical >/dev/null 2>&1; then
|
|||
echo -e "${RED}Zensical not installed; cannot build docs.${NC}"; exit 1
|
||||
fi
|
||||
echo -e "${GREEN}Building documentation (strict)…${NC}"
|
||||
zensical build -f "$ZENSICAL_CFG_PATH" -d "$SITE_DIR" --strict >"$LOG_DIR/zensical-build.log" 2>&1 || {
|
||||
echo -e "${RED}Zensical build failed. See $LOG_DIR/zensical-build.log${NC}"; exit 1; }
|
||||
zensical build --clean >"$LOG_DIR/zensical-build.log" 2>&1 || {
|
||||
echo -e "${RED}Zensical build failed. See $LOG_DIR/zensical-build.log${NC}"; exit 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue