Merge pull request #37 from BerryBytes/feat/rajivbb/workflow #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Pre-Commit Checks | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - develop | |
| - 'feat/**' | |
| - 'feature/**' | |
| - 'test/**' | |
| - 'chore/**' | |
| - 'fix/**' | |
| - 'hotfix/**' | |
| - 'docs/**' | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| jobs: | |
| precommit: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: '1.22.0' | |
| - name: Install goimports | |
| run: | | |
| go install golang.org/x/tools/cmd/goimports@latest | |
| echo "$HOME/go/bin" >> $GITHUB_PATH | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install pre-commit | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install pre-commit | |
| - name: Load Pre-commit Config | |
| run: | | |
| if [ ! -f ".pre-commit-config.yaml" ]; then | |
| echo " No .pre-commit-config.yaml found — downloading BerryBytes global config..." | |
| curl -sSL \ | |
| https://raw.githubusercontent.com/BerryBytes/precommit-util/main/global/precommitFile/.pre-commit-config.yaml \ | |
| -o .pre-commit-config.yaml | |
| else | |
| echo "✔ Using project's existing .pre-commit-config.yaml" | |
| fi | |
| - name: Inject temporary Stylelint config for CI | |
| run: | | |
| if [ ! -f ".stylelintrc.json" ]; then | |
| echo " Creating temporary .stylelintrc.json for CI..." | |
| cat <<EOF > .stylelintrc.json | |
| { | |
| "extends": "stylelint-config-standard", | |
| "rules": { | |
| "no-duplicate-selectors": true, | |
| "color-hex-length": "short", | |
| "selector-no-qualifying-type": true, | |
| "selector-max-id": 0 | |
| } | |
| } | |
| EOF | |
| else | |
| echo "✔ .stylelintrc.json already exists — skipping" | |
| fi | |
| # -------------------------------------------------------------------- | |
| # STEP 1: Run pre-commit (capture full logs and exit code safely) | |
| # -------------------------------------------------------------------- | |
| - name: Run pre-commit (full logs) | |
| id: runprecommit | |
| run: | | |
| echo "🔍 Running full pre-commit checks..." | |
| set +e # allow failure | |
| pre-commit run --all-files --verbose --show-diff-on-failure --color never \ | |
| | tee full_precommit.log | |
| exit_code=${PIPESTATUS[0]} | |
| echo "Pre-commit exit code: $exit_code" | |
| echo "$exit_code" > precommit_exit_code.txt | |
| # -------------------------------------------------------------------- | |
| # STEP 2: Summary of FAILED hooks | |
| # -------------------------------------------------------------------- | |
| - name: Pre-commit summary of failed hooks | |
| run: | | |
| echo "=====================================================" | |
| echo " PRE-COMMIT SUMMARY" | |
| echo "=====================================================" | |
| exit_code=$(cat precommit_exit_code.txt) | |
| if [ "$exit_code" = "0" ]; then | |
| echo " All hooks passed!" | |
| exit 0 | |
| fi | |
| echo " Hooks failed — showing summary:" | |
| echo "" | |
| echo " FAILED HOOKS:" | |
| grep -E "^\w.*\.{3,}Failed" full_precommit.log || echo " None" | |
| echo "-----------------------------------------------------" | |
| echo " FILES WITH ISSUES:" | |
| grep -E "files were modified by this hook" -A3 full_precommit.log \ | |
| | sed 's/^/ - /' || echo " None" | |
| echo "-----------------------------------------------------" | |
| echo " ERROR DETAILS:" | |
| grep -Ei "(error|failed|violation|missing|line too long|could not|warning)" full_precommit.log \ | |
| | grep -Ev "^(---|\+\+\+|@@|diff --git|index )" \ | |
| | sed 's/^/ • /' || echo " None" | |
| echo "-----------------------------------------------------" | |
| exit $exit_code |