Skip to content

Conversation

@pedrogaudencio
Copy link
Collaborator

@pedrogaudencio pedrogaudencio commented Nov 11, 2025

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:

  • Conditional test execution based on file changes
  • Separate frontend and backend test jobs that run in parallel
  • Automatic dependency caching for faster execution
  • Minimal permissions (read-only access)

Trigger Conditions

Pull Request Events

  • Event: pull_request
  • Types: opened, synchronize, reopened
  • Behavior: Runs when a PR is opened, updated with new commits, or reopened

Concurrency Control

  • Group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  • Cancel in Progress: true
  • Behavior: Cancels previous test runs when new commits are pushed to the same PR
  • Benefit: Saves CI resources and provides faster feedback

Permissions

  • Contents: read (read-only access to repository)
  • Security: Uses pull_request trigger (safe for fork PRs)

Workflow Steps

Job 1: files-changed

Type: Reusable workflow call

Purpose: Detects which types of files have changed in the PR

Workflow: ./.github/workflows/files-changed.yml

Outputs Used:

  • frontend - True if frontend files changed
  • backend - True if backend files changed

File Patterns:

  • Frontend: *.js, *.ts, web_src/**, package.json, pnpm-lock.yaml, etc.
  • Backend: **/*.go, go.mod, go.sum, models/**, modules/**, services/**, etc.

Job 2: test-frontend

Runs on: ubuntu-latest

Condition: needs.files-changed.outputs.frontend == 'true'

Purpose: Runs frontend unit tests using Vitest

Steps:

  1. Checkout Repository (actions/checkout@v4)

    • Checks out the PR code
  2. Setup pnpm (pnpm/action-setup@v4)

    • Installs pnpm package manager
    • Version specified in package.json (packageManager field)
  3. Setup Node.js (actions/setup-node@v5)

    • Node Version: 24
    • Cache: pnpm (automatically caches pnpm store)
    • Benefit: Faster dependency installation on subsequent runs
  4. Install Frontend Dependencies

    • Command: make deps-frontend
    • Action: Runs pnpm install to install dependencies
  5. Run Frontend Tests

    • Command: make test-frontend
    • Test Runner: Vitest
    • Actual Command: pnpm exec vitest
    • Tests: All frontend unit tests

Job 3: test-backend

Runs on: ubuntu-latest

Condition: needs.files-changed.outputs.backend == 'true'

Purpose: Runs backend unit tests using Go's testing framework

Steps:

  1. Checkout Repository (actions/checkout@v4)

    • Checks out the PR code
  2. Setup Go (actions/setup-go@v5)

    • Go Version: From go.mod file
    • Check Latest: true (uses latest patch version)
    • Cache: true (automatically caches Go modules and build cache)
    • Benefit: Faster builds on subsequent runs
  3. Install Backend Dependencies

    • Command: make deps-backend
    • Action: Runs go mod download to download Go modules
  4. Run Backend Tests

    • Command: make test-backend
    • Test Runner: Go test
    • Tags: bindata sqlite sqlite_unlock_notify
    • Actual Command: go test -tags='bindata sqlite sqlite_unlock_notify' ./...
    • Tests: All backend unit tests

Conditional Execution Logic

Scenario 1: Only Frontend Files Changed

  • test-frontend runs
  • ⏭️ test-backend skipped
  • Example: Changes to web_src/js/components/Button.vue

Scenario 2: Only Backend Files Changed

  • ⏭️ test-frontend skipped
  • test-backend runs
  • Example: Changes to models/user.go

Scenario 3: Both Frontend and Backend Files Changed

  • test-frontend runs
  • test-backend runs (in parallel)
  • Example: Changes to both web_src/js/api.js and routers/api/v1/user.go

Scenario 4: Only Documentation Files Changed

  • ⏭️ test-frontend skipped
  • ⏭️ test-backend skipped
  • Example: Changes to README.md or docs/content/doc/usage/api.md
  • Note: The files-changed job still runs (minimal overhead)

Scenario 5: Makefile or Workflow Files Changed

  • ✅ Both jobs run (because these files affect both frontend and backend)
  • Example: Changes to Makefile or .github/workflows/pull-tests.yml

Comparison: pull_request vs pull_request_target

Aspect pull_request (This Workflow) pull_request_target
Code Context PR branch Base branch
Permissions Read-only (forks) Write access
Secrets Access No (forks) Yes
Security Risk LOW HIGH (if misused)
Use Case Testing, linting Labeling, commenting

* Runs frontend tests (Vitest) only when frontend files change
* Runs backend tests (Go) only when backend files change
* Skips tests when only documentation changes
* Automatic dependency caching (Go modules, pnpm)
* Concurrency control to cancel outdated runs
* Secure design using pull_request trigger with read-only permissions

Fixes /issues/51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants