pre-push
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash

# Check for direct push to main
while read local_ref local_sha remote_ref remote_sha; do
    if [[ "$remote_ref" == "refs/heads/main" ]]; then
        echo -e "\e[31mERR:\e[0m Direct push to main is not allowed."
        echo -e "Please raise a PR and get it reviewed before merging into main.\n"
        exit 1
    fi
done

# Check branch name convention
BRANCH=$(git symbolic-ref --short HEAD)
PATTERN="^(feat|fix|chore|docs|refactor|revert)/.+"

if [[ ! "$BRANCH" =~ $PATTERN ]]; then
    echo -e "\e[31mERR:\e[0m Branch name '$BRANCH' does not follow naming convention."
    echo -e "Expected: <type>/<description>"
    echo -e "Example:  feat/add-vpc-module\n"
    exit 1
fi

# Check for pwsh
if ! command -v pwsh &>/dev/null; then
    echo -e "\e[31mERR:\e[0m PowerShell (pwsh) is not installed or not in PATH.\n"
    exit 1
fi

# Run workspace validation
if [ ! -f scripts/workspace-validate.ps1 ]; then
    echo -e "\e[31mERR:\e[0m scripts/workspace-validate.ps1 not found.\n"
    exit 1
fi

pwsh -NonInteractive -NoProfile -File scripts/workspace-validate.ps1
if [ $? -ne 0 ]; then
    echo -e "\e[31mERR:\e[0m Workspace validation failed. Fix the issues above before pushing.\n"
    exit 1
fi

exit 0