Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

7.5 KB
Raw Blame
version: "3"

# NOTE: UNSAFE_DISABLE_PASSWORD_PROJECTION is deliberately NOT set here. It
# turns password hashing into a plaintext no-op, which is a local dev-server
# convenience only. As a global it also applied to `go:test`/`go:coverage`,
# so the Go suite exercised the plaintext branch instead of argon2id — and
# TestTimingEqualizationHashIsValidArgon2 failed in CI as a result. Set it
# per-task on the tasks that actually run a dev server.
env:
  HBOX_LOG_LEVEL: debug
  HBOX_DATABASE_DRIVER: sqlite3
  HBOX_DATABASE_SQLITE_PATH: .data/homebox.db?_pragma=busy_timeout=1000&_pragma=journal_mode=WAL&_fk=1&_time_format=sqlite
  HBOX_OPTIONS_ALLOW_REGISTRATION: true
  HBOX_AUTH_API_KEY_PEPPER: "dev-only-pepper-not-for-production-use-32b+"
tasks:
  setup:
    desc: Install development dependencies
    cmds:
      - go install github.com/swaggo/swag/cmd/swag@latest
      - go install github.com/pressly/goose/v3/cmd/[email protected]
      - cd backend && go mod tidy
      - cd frontend && pnpm install

  swag:
    desc: Generate swagger docs
    dir: backend/app/api/static/
    vars:
      API: "../"
      INTERNAL: "../../../internal"
      PKGS: "../../../pkgs"
    cmds:
      - swag init --dir={{ .API }},{{ .INTERNAL }}/core/services,{{ .INTERNAL }}/data/repo --parseDependency
      - npx -y -p swagger2openapi swagger2openapi --outfile ./docs/openapi-3.json ./docs/swagger.json
      - npx -y -p swagger2openapi swagger2openapi --yaml --outfile ./docs/openapi-3.yaml ./docs/swagger.json
      - cp -r ./docs/swagger.json ../../../../docs/public/api/swagger-2.0.json
      - cp -r ./docs/swagger.yaml ../../../../docs/public/api/swagger-2.0.yaml
      - cp -r ./docs/openapi-3.json ../../../../docs/public/api/openapi-3.0.json
      - cp -r ./docs/openapi-3.yaml ../../../../docs/public/api/openapi-3.0.yaml
    sources:
      - "./backend/app/api/**/*"
      - "./backend/internal/data/**"
      - "./backend/internal/core/services/**/*"
      - "./backend/app/tools/typegen/main.go"
  typescript-types:
    desc: Generates typescript types from swagger definition
    cmds:
      - |
        pnpm dlx swagger-typescript-api generate \
          --no-client \
          --modular \
          --path ./backend/app/api/static/docs/swagger.json \
          --output ./frontend/lib/api/types
      - go run ./backend/app/tools/typegen/main.go ./frontend/lib/api/types/data-contracts.ts
    sources:
      - ./backend/app/tools/typegen/main.go
      - ./backend/app/api/static/docs/swagger.json

  generate:
    deps:
      - db:generate
    cmds:
      - task: swag
      - task: typescript-types

  go:run:
    env:
      HBOX_DEMO: true
      UNSAFE_DISABLE_PASSWORD_PROJECTION: "yes_i_am_sure"
    desc: Starts the backend api server (depends on generate task)
    dir: backend
    deps:
      - generate
    cmds:
      - go run ./app/api/ {{ .CLI_ARGS }}
    silent: false

  go:run:postgresql:
    env:
      HBOX_DEMO: true
      UNSAFE_DISABLE_PASSWORD_PROJECTION: "yes_i_am_sure"
      HBOX_DATABASE_DRIVER: postgres
      HBOX_DATABASE_USERNAME: homebox
      HBOX_DATABASE_PASSWORD: homebox
      HBOX_DATABASE_DATABASE: homebox
      HBOX_DATABASE_HOST: localhost
      HBOX_DATABASE_PORT: 5432
      HBOX_DATABASE_SSL_MODE: disable
    desc: Starts the backend api server with postgresql (depends on generate task)
    dir: backend
    deps:
      - generate
    cmds:
      - go run ./app/api/ {{ .CLI_ARGS }}
    silent: false

  go:ci:
    env:
      HBOX_DEMO: true
      UNSAFE_DISABLE_PASSWORD_PROJECTION: "yes_i_am_sure"
    desc: Runs all go test and lint related tasks
    dir: backend
    cmds:
      - go run ./app/api/ {{ .CLI_ARGS }} &
    silent: true

  go:ci:with-frontend:
      desc: Run backend with frontend in CI mode
      dir: frontend
      cmds:
        - pnpm install
        - pnpm run build
        - cp -r ./.output/public ../backend/app/api/static/
        - task: go:ci
      silent: true

  go:test:
    desc: Runs all go tests using gotestsum - supports passing gotestsum args
    dir: backend
    cmds:
      - go test {{ .CLI_ARGS }} ./...

  go:test:meilisearch:
    desc: Runs the Meilisearch search engine integration tests against a dockerized instance
    dir: backend
    cmds:
      - docker run -d --rm --name homebox-meili-test -p 7711:7700 -e MEILI_MASTER_KEY=test-master-key -e MEILI_NO_ANALYTICS=true getmeili/meilisearch:v1.22
      - defer: docker stop homebox-meili-test
      - |
        i=0
        while [ "$i" -lt 60 ]; do
          if curl -sf http://localhost:7711/health > /dev/null; then exit 0; fi
          i=$((i + 1))
          sleep 0.5
        done
        echo "Meilisearch did not become healthy within 30s" >&2
        exit 1
      - TEST_MEILISEARCH_URL=http://localhost:7711 TEST_MEILISEARCH_KEY=test-master-key go test ./internal/data/search/ -v -count=1

  go:coverage:
    desc: Runs all go tests with -race flag and generates a coverage report
    dir: backend
    cmds:
      - go test -race -coverprofile=coverage.out -covermode=atomic ./app/... ./internal/... ./pkgs/... -v -cover
    silent: true

  go:tidy:
    desc: Runs go mod tidy on the backend
    dir: backend
    cmds:
      - go mod tidy

  go:lint:
    desc: Runs golangci-lint
    dir: backend
    cmds:
      - golangci-lint run ./...

  go:all:
    desc: Runs all go test and lint related tasks
    cmds:
      - task: go:tidy
      - task: go:lint
      - task: go:test

  go:build:
    desc: Builds the backend binary
    dir: backend
    cmds:
      - go build -o ../build/backend ./app/api

  db:generate:
    desc: Run Entgo.io Code Generation
    dir: backend/internal/
    cmds:
      - CGO_ENABLED=0 go generate ./...
    sources:
      - "./backend/internal/data/ent/schema/**/*"

  ui:watch:
    desc: Starts the vitest test runner in watch mode
    dir: frontend
    cmds:
      - pnpm run test:watch

  ui:dev:
    desc: Run frontend development server
    dir: frontend
    cmds:
      - pnpm dev --no-fork

  ui:ci:
    desc: Run frontend build in CI mode
    dir: frontend
    cmds:
      - pnpm dev &
    silent: true

  ui:fix:
    desc: Runs prettier and eslint on the frontend
    dir: frontend
    cmds:
      - pnpm run lint:fix

  ui:check:
    desc: Runs type checking
    dir: frontend
    cmds:
      - pnpm run typecheck

  test:ci:
    env:
      UNSAFE_DISABLE_PASSWORD_PROJECTION: "yes_i_am_sure"
    desc: Runs end-to-end test on a live server (only for use in CI)
    cmds:
      - cd backend && go build ./app/api
      - backend/api &
      - sleep 15
      - cd frontend && pnpm run test:ci
    silent: true

  test:ci:postgresql:
    env:
      UNSAFE_DISABLE_PASSWORD_PROJECTION: "yes_i_am_sure"
      HBOX_DATABASE_DRIVER: postgres
      HBOX_DATABASE_USERNAME: homebox
      HBOX_DATABASE_PASSWORD: homebox
      HBOX_DATABASE_DATABASE: homebox
      HBOX_DATABASE_HOST: 127.0.0.1
      HBOX_DATABASE_PORT: 5432
      HBOX_DATABASE_SSL_MODE: disable
    desc: Runs end-to-end test on a live server with postgresql (only for use in CI)
    cmds:
      - cd backend && go build ./app/api
      - backend/api &
      - sleep 15
      - cd frontend && pnpm run test:ci
    silent: true

  test:e2e:
    desc: Runs end-to-end test on a live server
    dir: frontend
    cmds:
      - task: go:ci:with-frontend
      - pnpm exec playwright install-deps
      - pnpm exec playwright install
      - sleep 30
      - TEST_SHUTDOWN_API_SERVER=true E2E_BASE_URL=http://localhost:7745 pnpm exec playwright test -c ./test/playwright.config.ts {{ .CLI_ARGS }}

  pr:
    desc: Runs all tasks required for a PR
    cmds:
      - task: generate
      - task: go:all
      - task: ui:check
      - task: ui:fix
      - task: test:ci