Add conditional unit tests workflow for pull requests #55
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This workflow runs unit tests on pull requests, executing frontend and backend tests conditionally based on which files have changed. It provides fast feedback to developers by only running relevant tests, while ensuring comprehensive test coverage when needed.
Key Features:
Trigger Conditions
Pull Request Events
pull_requestopened,synchronize,reopenedConcurrency Control
${{ github.workflow }}-${{ github.head_ref || github.run_id }}truePermissions
read(read-only access to repository)pull_requesttrigger (safe for fork PRs)Workflow Steps
Job 1:
files-changedType: Reusable workflow call
Purpose: Detects which types of files have changed in the PR
Workflow:
./.github/workflows/files-changed.ymlOutputs Used:
frontend- True if frontend files changedbackend- True if backend files changedFile Patterns:
*.js,*.ts,web_src/**,package.json,pnpm-lock.yaml, etc.**/*.go,go.mod,go.sum,models/**,modules/**,services/**, etc.Job 2:
test-frontendRuns on:
ubuntu-latestCondition:
needs.files-changed.outputs.frontend == 'true'Purpose: Runs frontend unit tests using Vitest
Steps:
Checkout Repository (
actions/checkout@v4)Setup pnpm (
pnpm/action-setup@v4)package.json(packageManagerfield)Setup Node.js (
actions/setup-node@v5)pnpm(automatically caches pnpm store)Install Frontend Dependencies
make deps-frontendpnpm installto install dependenciesRun Frontend Tests
make test-frontendpnpm exec vitestJob 3:
test-backendRuns on:
ubuntu-latestCondition:
needs.files-changed.outputs.backend == 'true'Purpose: Runs backend unit tests using Go's testing framework
Steps:
Checkout Repository (
actions/checkout@v4)Setup Go (
actions/setup-go@v5)go.modfiletrue(uses latest patch version)true(automatically caches Go modules and build cache)Install Backend Dependencies
make deps-backendgo mod downloadto download Go modulesRun Backend Tests
make test-backendbindata sqlite sqlite_unlock_notifygo test -tags='bindata sqlite sqlite_unlock_notify' ./...Conditional Execution Logic
Scenario 1: Only Frontend Files Changed
test-frontendrunstest-backendskippedweb_src/js/components/Button.vueScenario 2: Only Backend Files Changed
test-frontendskippedtest-backendrunsmodels/user.goScenario 3: Both Frontend and Backend Files Changed
test-frontendrunstest-backendruns (in parallel)web_src/js/api.jsandrouters/api/v1/user.goScenario 4: Only Documentation Files Changed
test-frontendskippedtest-backendskippedREADME.mdordocs/content/doc/usage/api.mdfiles-changedjob still runs (minimal overhead)Scenario 5: Makefile or Workflow Files Changed
Makefileor.github/workflows/pull-tests.ymlComparison:
pull_requestvspull_request_target