170 lines
4.9 KiB
YAML
170 lines
4.9 KiB
YAML
name: Backend Tests
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
paths:
|
|
- "apps/backend/**"
|
|
- ".github/workflows/backend-tests.yml"
|
|
- "!**/*.md"
|
|
- "!**/*.mdx"
|
|
- "!**/*.markdown"
|
|
pull_request:
|
|
branches: [main]
|
|
paths:
|
|
- "apps/backend/**"
|
|
- ".github/workflows/backend-tests.yml"
|
|
- "!**/*.md"
|
|
- "!**/*.mdx"
|
|
- "!**/*.markdown"
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
test:
|
|
name: Run Backend Tests
|
|
runs-on: ubuntu-latest
|
|
defaults:
|
|
run:
|
|
working-directory: apps/backend
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v6
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set up Go
|
|
if: ${{ !contains(runner.name, 'homelab') }}
|
|
uses: actions/setup-go@v6
|
|
with:
|
|
go-version-file: apps/backend/go.mod
|
|
cache-dependency-path: apps/backend/go.sum
|
|
|
|
- name: Cache Go modules
|
|
if: ${{ contains(runner.name, 'homelab') }}
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
~/go/pkg/mod
|
|
~/.cache/go-build
|
|
~/.cache/golangci-lint
|
|
key: go-${{ runner.os }}-${{ hashFiles('apps/backend/go.sum') }}
|
|
restore-keys: go-${{ runner.os }}-
|
|
|
|
- name: Build
|
|
run: go build -v ./cmd/kandev
|
|
|
|
- name: Resolve base SHA
|
|
shell: bash
|
|
working-directory: ${{ github.workspace }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
|
|
BASE_SHA="${{ github.event.pull_request.base.sha }}"
|
|
else
|
|
BASE_SHA="${{ github.event.before }}"
|
|
fi
|
|
|
|
if [[ -z "${BASE_SHA}" || "${BASE_SHA}" == "0000000000000000000000000000000000000000" ]]; then
|
|
BASE_SHA="$(git rev-list --max-parents=0 HEAD)"
|
|
fi
|
|
|
|
echo "BASE_SHA=${BASE_SHA}" >> "$GITHUB_ENV"
|
|
echo "Base SHA: ${BASE_SHA}"
|
|
|
|
- name: Check gofmt
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
CHANGED_GO_FILES="$(
|
|
git diff --name-only --diff-filter=ACMRT "${BASE_SHA}"..."${{ github.sha }}" -- apps/backend \
|
|
| grep -E '^apps/backend/.*\.go$' \
|
|
|| true
|
|
)"
|
|
|
|
if [[ -z "${CHANGED_GO_FILES}" ]]; then
|
|
echo "No backend Go files changed."
|
|
exit 0
|
|
fi
|
|
|
|
UNFORMATTED="$(echo "${CHANGED_GO_FILES}" | sed 's#^apps/backend/##' | xargs gofmt -l)"
|
|
if [[ -n "${UNFORMATTED}" ]]; then
|
|
echo "The following changed Go files are not formatted with gofmt:"
|
|
echo "${UNFORMATTED}"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Run golangci-lint
|
|
uses: golangci/golangci-lint-action@v9
|
|
with:
|
|
version: v2.9
|
|
args: ./... --new-from-rev=${{ env.BASE_SHA }}
|
|
working-directory: apps/backend
|
|
|
|
- name: Run tests
|
|
run: |
|
|
set -o pipefail
|
|
go test -v -race -coverprofile=coverage.out -covermode=atomic -json ./... 2>&1 | tee test-results.json
|
|
|
|
- name: Generate test report
|
|
uses: robherley/go-test-action@v0
|
|
if: always()
|
|
with:
|
|
fromJSONFile: apps/backend/test-results.json
|
|
|
|
- name: Upload test artifacts
|
|
uses: actions/upload-artifact@v5
|
|
if: always()
|
|
with:
|
|
name: test-results
|
|
path: |
|
|
apps/backend/coverage.out
|
|
apps/backend/test-results.json
|
|
retention-days: 30
|
|
|
|
test-windows:
|
|
name: Backend (windows)
|
|
runs-on: windows-latest
|
|
timeout-minutes: 15
|
|
# Least-privilege: this job only reads source and runs tests, no PR/issue
|
|
# writes or release operations. Flagged by CodeQL workflow audit + matching
|
|
# CodeRabbit nitpick.
|
|
permissions:
|
|
contents: read
|
|
defaults:
|
|
run:
|
|
working-directory: apps/backend
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v6
|
|
with:
|
|
go-version-file: apps/backend/go.mod
|
|
cache-dependency-path: apps/backend/go.sum
|
|
|
|
# Compile-checks every `*_windows.go` file (pty/conpty wrapper, job-object
|
|
# launcher, shell, signals, sysprocattr, vscode cleanup, …). The rest of
|
|
# the suite is build-tag-gated out automatically.
|
|
- name: Build
|
|
run: go build ./...
|
|
|
|
- name: Vet
|
|
run: go vet ./...
|
|
|
|
# Scope to packages with non-trivial Windows-specific code paths.
|
|
# Tests that genuinely cannot run on Windows (Unix sockets, POSIX
|
|
# symlinks under default Windows ACLs, delete-while-open) call t.Skip
|
|
# in source with a documented reason. The shell-fixture tests now use
|
|
# a self-hosting Go helper (see testmain_test.go) so they run on
|
|
# every platform.
|
|
- name: Test windows-sensitive packages
|
|
run: go test -race -v ./internal/agentctl/server/process/... ./internal/agent/runtime/agentctl/launcher/...
|