Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Build and Test

permissions:
contents: write
packages: write
pages: write

on:
push:
branches:
- master
pull_request:
paths-ignore: ['docs/**', 'mkdocs.yml']
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build and Lint
runs-on: ubuntu-latest
steps:

- name: Check out code
uses: actions/checkout@v6

- name: Set up Golang
uses: actions/setup-go@v6
with:
go-version: '1.25'
cache-dependency-path: 'go.sum'

- name: Build
run: |
go build ./cmd/pgcov

- name: GolangCI-Lint
uses: golangci/golangci-lint-action@v9
with:
version: latest

test:
if: true # false to skip job during debug
needs: build
runs-on: ubuntu-latest
name: Test
steps:

- name: Check out code
uses: actions/checkout@v6

- name: Set up Golang
uses: actions/setup-go@v6
with:
go-version: '1.25'
cache-dependency-path: 'go.sum'

- name: Test
run: |
go test -failfast -v -timeout=300s -coverprofile=profile.cov ./cmd/... ./internal/...

- name: Coveralls
uses: coverallsapp/github-action@v2
with:
file: profile.cov
39 changes: 39 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: "2"
linters:
enable:
- misspell
- revive
disable:
- gocyclo
settings:
gocyclo:
min-complexity: 20
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- path: (.+)\.go$
text: SA1019 # CPUTimesStat.Total is deprecated
- path: (.+)\.go$
text: SA5008 # duplicate struct tag "choice" (staticcheck)
- path: (.+)\.go$
text: QF1001 # could apply De Morgan's law
- path: pkg/
text: "var-naming: avoid meaningless package names"
linters:
- revive
paths:
- third_party$
- builtin$
- examples$
formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
33 changes: 7 additions & 26 deletions cmd/pgcov/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,9 @@ func main() {
Action: runCommand,
Flags: []urfavecli.Flag{
&urfavecli.StringFlag{
Name: "host",
Usage: "PostgreSQL host",
},
&urfavecli.IntFlag{
Name: "port",
Usage: "PostgreSQL port",
},
&urfavecli.StringFlag{
Name: "user",
Usage: "PostgreSQL user",
},
&urfavecli.StringFlag{
Name: "password",
Usage: "PostgreSQL password",
},
&urfavecli.StringFlag{
Name: "database",
Usage: "Template database for test databases",
Name: "connection",
Aliases: []string{"c"},
Usage: "PostgreSQL connection string (URI or key=value format). Supports standard PG* environment variables.",
},
&urfavecli.DurationFlag{
Name: "timeout",
Expand Down Expand Up @@ -95,20 +80,16 @@ func main() {
// runCommand handles the 'pgcov run' command
func runCommand(ctx context.Context, cmd *urfavecli.Command) error {
// Load configuration
config := cli.LoadConfig()
config := &cli.DefaultConfig

// Apply flags
host := cmd.String("host")
port := cmd.Int("port")
user := cmd.String("user")
password := cmd.String("password")
database := cmd.String("database")
connection := cmd.String("connection")
timeout := cmd.Duration("timeout")
parallel := cmd.Int("parallel")
coverageFile := cmd.String("coverage-file")
verbose := cmd.Bool("verbose")

cli.ApplyFlagsToConfig(config, host, port, user, password, database, timeout, parallel, coverageFile, verbose)
cli.ApplyFlagsToConfig(config, connection, timeout, parallel, coverageFile, verbose)

// Validate configuration
if err := config.Validate(); err != nil {
Expand Down Expand Up @@ -142,5 +123,5 @@ func reportCommand(ctx context.Context, cmd *urfavecli.Command) error {
output := cmd.String("output")
coverageFile := cmd.String("coverage-file")

return cli.Report(coverageFile, format, output)
return cli.Report(ctx, coverageFile, format, output)
}
61 changes: 9 additions & 52 deletions internal/cli/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cli

import (
"os"
"strconv"
"time"

"github.com/cybertec-postgresql/pgcov/pkg/types"
Expand All @@ -16,60 +14,19 @@ type ConfigError = types.ConfigError

// DefaultConfig provides default configuration values
var DefaultConfig = Config{
PGHost: "localhost",
PGPort: 5432,
PGDatabase: "postgres",
Timeout: 30 * time.Second,
Parallelism: 1,
CoverageFile: ".pgcov/coverage.json",
Verbose: false,
}

// LoadConfig creates a configuration by layering flags → env vars → defaults
// Priority: flags override env vars override defaults
func LoadConfig() *Config {
cfg := DefaultConfig

// Load from environment variables
if host := os.Getenv("PGHOST"); host != "" {
cfg.PGHost = host
}
if portStr := os.Getenv("PGPORT"); portStr != "" {
if port, err := strconv.Atoi(portStr); err == nil {
cfg.PGPort = port
}
}
if user := os.Getenv("PGUSER"); user != "" {
cfg.PGUser = user
}
if password := os.Getenv("PGPASSWORD"); password != "" {
cfg.PGPassword = password
}
if database := os.Getenv("PGDATABASE"); database != "" {
cfg.PGDatabase = database
}

return &cfg
ConnectionString: "",
Timeout: 30 * time.Second,
Parallelism: 1,
CoverageFile: ".pgcov/coverage.json",
Verbose: false,
}

// ApplyFlagsToConfig applies command-line flag values to configuration
func ApplyFlagsToConfig(c *Config, host string, port int, user, password, database string,
timeout time.Duration, parallel int, coverageFile string, verbose bool) {
func ApplyFlagsToConfig(c *Config, connection string, timeout time.Duration,
parallel int, coverageFile string, verbose bool) {

if host != "" {
c.PGHost = host
}
if port != 0 {
c.PGPort = port
}
if user != "" {
c.PGUser = user
}
if password != "" {
c.PGPassword = password
}
if database != "" {
c.PGDatabase = database
if connection != "" {
c.ConnectionString = connection
}
if timeout != 0 {
c.Timeout = timeout
Expand Down
Loading
Loading