mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-25 19:15:18 +02:00
chore: refactor GitHub Actions workflow to improve backend change detection and job dependencies
This commit is contained in:
parent
a786574484
commit
844b8ba609
1 changed files with 45 additions and 37 deletions
82
.github/workflows/backend-tests.yml
vendored
82
.github/workflows/backend-tests.yml
vendored
|
|
@ -10,10 +10,30 @@ concurrency:
|
|||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
changes:
|
||||
name: Changes
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
backend: ${{ steps.filter.outputs.backend }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Check changed files
|
||||
id: filter
|
||||
uses: dorny/paths-filter@v4
|
||||
with:
|
||||
filters: |
|
||||
backend:
|
||||
- 'surfsense_backend/**'
|
||||
- '.github/workflows/backend-tests.yml'
|
||||
|
||||
unit-tests:
|
||||
name: Unit Tests
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event.pull_request.draft == false
|
||||
needs: changes
|
||||
if: ${{ github.event.pull_request.draft == false && needs.changes.outputs.backend == 'true' }}
|
||||
env:
|
||||
EMBEDDING_MODEL: sentence-transformers/all-MiniLM-L6-v2
|
||||
|
||||
|
|
@ -21,26 +41,15 @@ jobs:
|
|||
- name: Checkout code
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Check if backend files changed
|
||||
id: backend-changes
|
||||
uses: dorny/paths-filter@v3
|
||||
with:
|
||||
filters: |
|
||||
backend:
|
||||
- 'surfsense_backend/**'
|
||||
|
||||
- name: Set up Python
|
||||
if: steps.backend-changes.outputs.backend == 'true'
|
||||
uses: actions/setup-python@v5
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: '3.12'
|
||||
|
||||
- name: Install UV
|
||||
if: steps.backend-changes.outputs.backend == 'true'
|
||||
uses: astral-sh/setup-uv@v7
|
||||
uses: astral-sh/setup-uv@v8.1.0
|
||||
|
||||
- name: Cache dependencies
|
||||
if: steps.backend-changes.outputs.backend == 'true'
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
|
|
@ -51,26 +60,24 @@ jobs:
|
|||
python-deps-
|
||||
|
||||
- name: Cache HuggingFace models
|
||||
if: steps.backend-changes.outputs.backend == 'true'
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: ~/.cache/huggingface
|
||||
key: hf-models-${{ env.EMBEDDING_MODEL }}
|
||||
|
||||
- name: Install dependencies
|
||||
if: steps.backend-changes.outputs.backend == 'true'
|
||||
working-directory: surfsense_backend
|
||||
run: uv sync
|
||||
|
||||
- name: Run unit tests
|
||||
if: steps.backend-changes.outputs.backend == 'true'
|
||||
working-directory: surfsense_backend
|
||||
run: uv run pytest -m unit
|
||||
|
||||
integration-tests:
|
||||
name: Integration Tests
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event.pull_request.draft == false
|
||||
needs: changes
|
||||
if: ${{ github.event.pull_request.draft == false && needs.changes.outputs.backend == 'true' }}
|
||||
env:
|
||||
EMBEDDING_MODEL: sentence-transformers/all-MiniLM-L6-v2
|
||||
|
||||
|
|
@ -93,26 +100,15 @@ jobs:
|
|||
- name: Checkout code
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Check if backend files changed
|
||||
id: backend-changes
|
||||
uses: dorny/paths-filter@v3
|
||||
with:
|
||||
filters: |
|
||||
backend:
|
||||
- 'surfsense_backend/**'
|
||||
|
||||
- name: Set up Python
|
||||
if: steps.backend-changes.outputs.backend == 'true'
|
||||
uses: actions/setup-python@v5
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: '3.12'
|
||||
|
||||
- name: Install UV
|
||||
if: steps.backend-changes.outputs.backend == 'true'
|
||||
uses: astral-sh/setup-uv@v7
|
||||
uses: astral-sh/setup-uv@v8.1.0
|
||||
|
||||
- name: Cache dependencies
|
||||
if: steps.backend-changes.outputs.backend == 'true'
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
|
|
@ -123,19 +119,16 @@ jobs:
|
|||
python-deps-
|
||||
|
||||
- name: Cache HuggingFace models
|
||||
if: steps.backend-changes.outputs.backend == 'true'
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: ~/.cache/huggingface
|
||||
key: hf-models-${{ env.EMBEDDING_MODEL }}
|
||||
|
||||
- name: Install dependencies
|
||||
if: steps.backend-changes.outputs.backend == 'true'
|
||||
working-directory: surfsense_backend
|
||||
run: uv sync
|
||||
|
||||
- name: Run integration tests
|
||||
if: steps.backend-changes.outputs.backend == 'true'
|
||||
working-directory: surfsense_backend
|
||||
env:
|
||||
TEST_DATABASE_URL: postgresql+asyncpg://postgres:postgres@localhost:5432/surfsense_test
|
||||
|
|
@ -146,14 +139,29 @@ jobs:
|
|||
test-gate:
|
||||
name: Test Gate
|
||||
runs-on: ubuntu-latest
|
||||
needs: [unit-tests, integration-tests]
|
||||
needs: [changes, unit-tests, integration-tests]
|
||||
if: always()
|
||||
|
||||
steps:
|
||||
- name: Check all test jobs
|
||||
run: |
|
||||
if [[ "${{ needs.unit-tests.result }}" == "failure" ||
|
||||
"${{ needs.integration-tests.result }}" == "failure" ]]; then
|
||||
if [[ "${{ needs.changes.result }}" == "failure" || "${{ needs.changes.result }}" == "cancelled" ]]; then
|
||||
echo "Backend change detection failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "${{ github.event.pull_request.draft }}" == "true" ]]; then
|
||||
echo "Draft PR; backend tests skipped"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "${{ needs.changes.outputs.backend }}" != "true" ]]; then
|
||||
echo "No backend changes detected; backend tests skipped"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "${{ needs.unit-tests.result }}" != "success" ||
|
||||
"${{ needs.integration-tests.result }}" != "success" ]]; then
|
||||
echo "Backend tests failed"
|
||||
exit 1
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue