diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 25c4f48..6829f72 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -1,8 +1,9 @@ name: Benchmark on: push: - branches: [main] + branches: [ "main", "master" ] pull_request: + branches: [ "main", "master" ] workflow_dispatch: concurrency: @@ -15,31 +16,13 @@ env: TIMEOUT: 10m jobs: - sqlite: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: benchmark/go.mod - cache-dependency-path: benchmark/go.sum - - run: | - go build -o bin/valk - cd benchmark - node prepareSchema.js sqlite - rm -rf valk/migrations/*.sql - rm -f dev.db - DATABASE_URL="file:./dev.db" DATABASE_DIRECT_URL="file:./dev.db" ../bin/valk migrate init - ../bin/valk generate - go generate ./ent - go run ./cmd/benchsummary -count=${{ env.COUNT }} -benchtime=${{ env.BENCHTIME }} -timeout=${{ env.TIMEOUT }} | tee ../bench-sqlite.txt - - uses: actions/upload-artifact@v4 - with: - name: bench-sqlite-${{ github.sha }} - path: bench-sqlite.txt - - postgres: + benchmark: + name: Benchmark (${{ matrix.db }}) runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + db: [sqlite, postgres] services: postgres: image: postgres:16 @@ -62,19 +45,29 @@ jobs: with: go-version-file: benchmark/go.mod cache-dependency-path: benchmark/go.sum - - run: | - go build -o bin/valk + + - name: Build Valkyrie CLI + run: go build -o bin/valk + + - name: Run Benchmark (${{ matrix.db }}) + run: | cd benchmark - node prepareSchema.js postgres + node prepareSchema.js ${{ matrix.db }} rm -rf valk/migrations/*.sql - DATABASE_URL="postgres://postgres:postgres@localhost:5432/bench?sslmode=disable" DATABASE_DIRECT_URL="postgres://postgres:postgres@localhost:5432/bench?sslmode=disable" ../bin/valk migrate init + rm -f dev.db + if [ "${{ matrix.db }}" = "sqlite" ]; then + DATABASE_URL="file:./dev.db" DATABASE_DIRECT_URL="file:./dev.db" ../bin/valk migrate init + else + DATABASE_URL="postgres://postgres:postgres@localhost:5432/bench?sslmode=disable" DATABASE_DIRECT_URL="postgres://postgres:postgres@localhost:5432/bench?sslmode=disable" ../bin/valk migrate init + fi ../bin/valk generate go generate ./ent - go run ./cmd/benchsummary -count=${{ env.COUNT }} -benchtime=${{ env.BENCHTIME }} -timeout=${{ env.TIMEOUT }} | tee ../bench-postgres.txt + BENCH_DB=${{ matrix.db }} go run ./cmd/benchsummary -count=${{ env.COUNT }} -benchtime=${{ env.BENCHTIME }} -timeout=${{ env.TIMEOUT }} | tee ../bench-${{ matrix.db }}.txt env: - BENCH_DB: postgres + BENCH_DB: ${{ matrix.db }} PG_DATABASE_URL: postgres://postgres:postgres@localhost:5432/bench?sslmode=disable + - uses: actions/upload-artifact@v4 with: - name: bench-postgres-${{ github.sha }} - path: bench-postgres.txt + name: bench-${{ matrix.db }}-${{ github.sha }} + path: bench-${{ matrix.db }}.txt diff --git a/.github/workflows/lint-pr.yml b/.github/workflows/lint-pr.yml new file mode 100644 index 0000000..58eb942 --- /dev/null +++ b/.github/workflows/lint-pr.yml @@ -0,0 +1,29 @@ +name: "Lint PR" + +on: + pull_request: + types: + - opened + - edited + - synchronize + - reopened + +jobs: + main: + name: Validate PR Title + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + types: | + feat + fix + perf + refactor + docs + ci + test + build + chore diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 61be105..0a52158 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -4,6 +4,8 @@ on: push: branches: [ "main", "master" ] pull_request: + schedule: + - cron: '0 0 * * 1' jobs: govulncheck: diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml deleted file mode 100644 index a7fd251..0000000 --- a/.github/workflows/validate.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: validate - -on: - push: - branches-ignore: - - 'main' - - 'master' - pull_request: - branches-ignore: - - 'main' - - 'master' - -jobs: - check-and-test: - name: Check, Build, and Test - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version-file: 'go.mod' - cache: true - cache-dependency-path: '**/go.sum' - - - name: Run Formatter Check - run: make fmt-check - - - name: Run Tidy Check - run: make tidy-check - - - name: Vet packages - run: make vet - - - name: Run compiler unit tests - run: make test diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index aa07778..a0b6563 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -7,8 +7,52 @@ on: branches: [ "main", "master" ] jobs: + path-filter: + name: Check Changed Paths + runs-on: ubuntu-latest + outputs: + code: ${{ steps.filter.outputs.code }} + steps: + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + code: + - 'generator/**' + - 'cli/**' + - 'schema/**' + - 'integration/**' + - 'dbProviders/**' + - 'migration/**' + - 'benchmark/**' + - '*.go' + - 'go.mod' + - 'go.sum' + - '.github/workflows/**' + + compiler-unit-tests: + needs: path-filter + if: ${{ needs.path-filter.outputs.code == 'true' }} + name: Unit Tests (${{ matrix.os }}) + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + cache: true + - name: Run compiler unit tests + run: go test -race -v ./... + integration-tests: - name: Run Integration Tests + needs: path-filter + if: ${{ needs.path-filter.outputs.code == 'true' }} + name: Run Database Integration Tests runs-on: ubuntu-latest services: @@ -19,57 +63,53 @@ jobs: POSTGRES_PASSWORD: testpassword POSTGRES_DB: valk_test ports: - - 5432:5432 + - 5432:5432 options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version-file: 'go.mod' - cache: true - cache-dependency-path: '**/go.sum' + - name: Checkout code + uses: actions/checkout@v4 - - name: Run Formatter Check - run: make fmt-check + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + cache: true - - name: Run Tidy Check - run: make tidy-check + - name: Run Formatter Check + run: make fmt-check - - name: Vet packages - run: make vet + - name: Run Tidy Check + run: make tidy-check - - name: Run compiler unit tests - run: make test + - name: Vet packages + run: make vet - - name: Run SQLite Integration Tests - run: | - cp integration/schema.prisma integration/schema.prisma.bak - node integration/prepareSchema.js sqlite - rm -f integration/valk/migrations/*.sql - make integration-gen - cd integration - ../bin/valk migrate -u "file:dev.db" init_sqlite - go test -race -tags sqlite -v ./... - mv schema.prisma.bak schema.prisma + - name: Run SQLite Integration Tests + run: | + cp integration/schema.prisma integration/schema.prisma.bak + node integration/prepareSchema.js sqlite + rm -f integration/valk/migrations/*.sql + make integration-gen + cd integration + ../bin/valk migrate -u "file:dev.db" init_sqlite + go test -race -tags sqlite -v ./... + mv schema.prisma.bak schema.prisma - - name: Run Postgres Integration Tests - run: | - PG_URL="${{ secrets.PG_DATABASE_URL }}" - if [ -z "$PG_URL" ]; then - PG_URL="postgres://testuser:testpassword@localhost:5432/valk_test?sslmode=disable" - else - PG_URL="${PG_URL/valkyrie_test/valk_test}" - fi - cp integration/schema.prisma integration/schema.prisma.bak - node integration/prepareSchema.js postgres - rm -f integration/valk/migrations/*.sql - make integration-gen - cd integration - ../bin/valk migrate -u "$PG_URL" init_pg - PG_DATABASE_URL="$PG_URL" go test -race -v ./... - mv schema.prisma.bak schema.prisma + - name: Run Postgres Integration Tests + run: | + PG_URL="${{ secrets.PG_DATABASE_URL }}" + if [ -z "$PG_URL" ]; then + PG_URL="postgres://testuser:testpassword@localhost:5432/valk_test?sslmode=disable" + else + PG_URL="${PG_URL/valkyrie_test/valk_test}" + fi + cp integration/schema.prisma integration/schema.prisma.bak + node integration/prepareSchema.js postgres + rm -f integration/valk/migrations/*.sql + make integration-gen + cd integration + ../bin/valk migrate -u "$PG_URL" init_pg + PG_DATABASE_URL="$PG_URL" go test -race -v ./... + mv schema.prisma.bak schema.prisma diff --git a/.gitignore b/.gitignore index dd2ac16..003cec1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,8 @@ bin docker-compose.yml api-example.gotpl *.bak -schema.prisma.backup \ No newline at end of file +schema.prisma.backup + +coverage.out +coverage.html +*.out \ No newline at end of file diff --git a/makefile b/makefile index cabf24e..f61c402 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -.PHONY: build build-prod run test install db-up db-down db-clean bi fmt fmt-check tidy tidy-check vulncheck vet integration-gen integration-test bench bench-sqlite bench-pg bench-all race lint test-sqlite test-pg test-dbs ci-local +.PHONY: build build-prod run test coverage cover-html install db-up db-down db-clean bi fmt fmt-check tidy tidy-check vulncheck vet integration-gen integration-test bench bench-sqlite bench-pg bench-all race lint test-sqlite test-pg test-dbs ci-local bi: build install @@ -7,6 +7,13 @@ e2e: test integration-test race: go test -race ./... && cd integration && go test -race ./... +coverage: + go test -coverprofile=coverage.out ./... + go tool cover -func=coverage.out + +cover-html: coverage + go tool cover -html=coverage.out -o coverage.html + bench: cd benchmark && make bench && cd ..