Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 89 additions & 19 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,85 @@
# This runs on every commit/PR to test that we are properly building binaries that work
# we test this on each commit/PR to catch build problems early
# This runs on every PR to test that we are properly building binaries that work.
# Branch protection should require the "build-and-test-gate" job.
name: Build and test HolmesGPT

on:
push:
branches:
- master
paths:
- '**'
- '!docs/**'
- '!**/*.md'
- '!mkdocs.yml'
- 'docs/reference/http-api.md'
pull_request:
paths:
- '**'
- '!docs/**'
- '!**/*.md'
- '!mkdocs.yml'
- 'docs/reference/http-api.md'
workflow_dispatch:

jobs:
check-changes:
runs-on: ubuntu-latest
outputs:
should_test: ${{ steps.changes.outputs.should_test }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check for source changes
id: changes
run: |
# Paths that do NOT require tests (docs-only changes)
SKIP_PATTERNS=(
"docs/*"
"*.md"
"mkdocs.yml"
)

# Exceptions: paths matching skip patterns that STILL require tests
ALWAYS_TEST=(
"docs/reference/http-api.md" # contains curl tests validated by tests/test_http_docs.py
)

if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "should_test=true" >> $GITHUB_OUTPUT
exit 0
fi

CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }}...${{ github.sha }})

SHOULD_TEST=false
while IFS= read -r file; do
[ -z "$file" ] && continue

# Check always-test exceptions first
for pattern in "${ALWAYS_TEST[@]}"; do
if [ "$file" = "$pattern" ]; then
SHOULD_TEST=true
break 2
fi
done

# Check if file matches any skip pattern
SKIP=false
for pattern in "${SKIP_PATTERNS[@]}"; do
case "$file" in
$pattern) SKIP=true; break ;;
esac
done

if [ "$SKIP" = false ]; then
SHOULD_TEST=true
break
fi
done <<< "$CHANGED_FILES"

echo "should_test=$SHOULD_TEST" >> $GITHUB_OUTPUT

build:
needs: check-changes
if: needs.check-changes.outputs.should_test == 'true'
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -111,3 +157,27 @@ jobs:
exit 1
fi
echo "Binary test passed"

# Gate job for branch protection — always runs and reports the correct status.
# Require this check ("Build and test HolmesGPT / build-and-test-gate") in
# branch protection instead of the individual build matrix jobs.
build-and-test-gate:
needs: [check-changes, build]
if: always()
runs-on: ubuntu-latest
steps:
- name: Check results
run: |
if [ "${{ needs.check-changes.result }}" != "success" ]; then
echo "check-changes job failed!"
exit 1
fi
if [ "${{ needs.check-changes.outputs.should_test }}" != "true" ]; then
echo "No source changes detected (docs-only) - skipping tests"
exit 0
fi
if [ "${{ needs.build.result }}" != "success" ]; then
echo "Build and test failed!"
exit 1
fi
Comment thread
coderabbitai[bot] marked this conversation as resolved.
echo "Build and test passed!"
Loading