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
83 changes: 83 additions & 0 deletions .github/workflows/wren-launcher-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Wren Launcher CI

on:
pull_request:
types: [synchronize, labeled]
paths:
- 'wren-launcher/**'
- '.github/workflows/wren-launcher-ci.yaml'

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.number || github.sha }}
cancel-in-progress: true

defaults:
run:
working-directory: wren-launcher

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.24'
cache-dependency-path: wren-launcher/go.sum
- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: v2.3.1
working-directory: wren-launcher

fmt-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
cache-dependency-path: wren-launcher/go.sum
- name: Install goimports
run: go install golang.org/x/tools/cmd/goimports@latest
- name: Download dependencies
run: go mod download
- name: Run format check
run: |
make fmt
# Check if there are any formatting changes
if [ -n "$(git diff --name-only)" ]; then
echo "Code is not formatted properly. Please run 'make fmt' and commit the changes."
git diff
exit 1
fi
- name: Run go vet
run: make vet
- name: Run tests
run: go test ./commands/dbt

security-scan:
runs-on: ubuntu-latest
needs: fmt-and-test
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
cache-dependency-path: wren-launcher/go.sum
- name: Run Gosec Security Scanner
run: |
go install github.com/securego/gosec/v2/cmd/gosec@latest
gosec ./...
- name: Run Go mod audit
run: |
go mod verify
go list -json -deps ./... | jq -r '.Module | select(.Version) | "\(.Path) \(.Version)"' | sort -u
25 changes: 25 additions & 0 deletions wren-launcher/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# golangci-lint configuration for WrenAI wren-launcher
version: "2"

run:
timeout: 5m

linters:
enable:
- errcheck
- govet
- ineffassign
- staticcheck
- unused
- misspell
- unconvert
- gosec
- dupl
- goconst
- gocyclo
- bodyclose
- whitespace

issues:
max-issues-per-linter: 0
max-same-issues: 0
48 changes: 48 additions & 0 deletions wren-launcher/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
BINARY_NAME=wren-launcher

# Build targets
build:
env GOARCH=amd64 GOOS=darwin CGO_ENABLED=1 go build -o dist/${BINARY_NAME}-darwin main.go
env GOARCH=arm64 GOOS=darwin CGO_ENABLED=1 go build -o dist/${BINARY_NAME}-darwin-arm64 main.go
Expand All @@ -18,3 +19,50 @@ clean:
rm -rf dist

rebuild: clean build

# Code quality targets
.PHONY: fmt
fmt:
go fmt ./...

.PHONY: imports
imports:
$(shell go env GOPATH)/bin/goimports -w .

.PHONY: vet
vet:
go vet ./...

.PHONY: lint
lint:
golangci-lint run

.PHONY: lint-fix
lint-fix:
golangci-lint run --fix

.PHONY: check
check: fmt vet lint

.PHONY: fix
fix: fmt imports lint-fix

.PHONY: test
test:
go test ./...

.PHONY: help
help:
@echo "Available targets:"
@echo " build - Build binaries for all platforms"
@echo " clean - Clean build artifacts"
@echo " rebuild - Clean and build"
@echo " fmt - Format Go code"
@echo " imports - Fix imports"
@echo " vet - Run go vet"
@echo " lint - Run golangci-lint"
@echo " lint-fix - Run golangci-lint with auto-fix"
@echo " check - Run fmt, vet, and lint"
@echo " fix - Run fmt, imports, and lint-fix"
@echo " test - Run tests"
@echo " help - Show this help"
30 changes: 30 additions & 0 deletions wren-launcher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@ go build main.go
env GOOS=windows GOARCH=amd64 go build main.go
```

## Code Quality
```bash
make check # Run all checks (fmt, vet, lint)
make test # Run tests
make fmt # Format code
make vet # Run go vet
make lint # Run golangci-lint
```

## Continuous Integration

This project uses GitHub Actions for CI/CD. The workflow runs automatically on:

- **Push to main branch**: Runs all checks and tests
- **Pull Request with label `launcher`**: Runs all checks and tests when PR is labeled
- **Manual trigger**: Can be triggered manually via GitHub Actions UI

### CI Jobs:

1. **Lint and Test**:
- Code formatting check
- Go vet analysis
- golangci-lint checks
- Unit tests
- All quality checks

2. **Security Scan**:
- Gosec security analysis
- Go module verification

## How to update dependencies

```bash
Expand Down
10 changes: 5 additions & 5 deletions wren-launcher/commands/dbt/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func ConvertDbtProjectCore(opts ConvertOptions) (*ConvertResult, error) {
}

// Create output directory if it doesn't exist
if err := os.MkdirAll(opts.OutputDir, 0755); err != nil {
if err := os.MkdirAll(opts.OutputDir, 0750); err != nil {
return nil, fmt.Errorf("failed to create output directory: %w", err)
}

Expand Down Expand Up @@ -169,7 +169,7 @@ func ConvertDbtProjectCore(opts ConvertOptions) (*ConvertResult, error) {
return nil, fmt.Errorf("failed to marshal data source JSON: %w", err)
}

if err := os.WriteFile(dataSourcePath, dataSourceJSON, 0644); err != nil {
if err := os.WriteFile(dataSourcePath, dataSourceJSON, 0600); err != nil {
return nil, fmt.Errorf("failed to write data source file: %w", err)
}

Expand Down Expand Up @@ -198,7 +198,7 @@ func ConvertDbtProjectCore(opts ConvertOptions) (*ConvertResult, error) {
return nil, fmt.Errorf("failed to marshal MDL JSON: %w", err)
}

if err := os.WriteFile(mdlPath, mdlJSON, 0644); err != nil {
if err := os.WriteFile(mdlPath, mdlJSON, 0600); err != nil {
return nil, fmt.Errorf("failed to write MDL file: %w", err)
}

Expand Down Expand Up @@ -244,7 +244,7 @@ func handleLocalhostForContainer(host string) string {
// ConvertDbtCatalogToWrenMDL converts dbt catalog.json to Wren MDL format
func ConvertDbtCatalogToWrenMDL(catalogPath string, data_source DataSource, manifestPath string) (*WrenMDLManifest, error) {
// Read and parse the catalog.json file
data, err := os.ReadFile(catalogPath)
data, err := os.ReadFile(catalogPath) // #nosec G304 -- catalogPath is controlled by application
if err != nil {
return nil, fmt.Errorf("failed to read catalog file %s: %w", catalogPath, err)
}
Expand All @@ -258,7 +258,7 @@ func ConvertDbtCatalogToWrenMDL(catalogPath string, data_source DataSource, mani
var manifestData map[string]interface{}
if manifestPath != "" {
pterm.Info.Printf("Reading manifest.json for descriptions from: %s\n", manifestPath)
manifestBytes, err := os.ReadFile(manifestPath)
manifestBytes, err := os.ReadFile(manifestPath) // #nosec G304 -- manifestPath is controlled by application
if err != nil {
pterm.Warning.Printf("Warning: Failed to read manifest file %s: %v\n", manifestPath, err)
} else {
Expand Down
53 changes: 41 additions & 12 deletions wren-launcher/commands/dbt/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,35 @@ import (
"github.com/pterm/pterm"
)

// Constants for data types
const (
integerType = "integer"
varcharType = "varchar"
dateType = "date"
timestampType = "timestamp"
doubleType = "double"
booleanType = "boolean"
)

// Constants for SQL data types
const (
integerSQL = "INTEGER"
intSQL = "INT"
bigintSQL = "BIGINT"
varcharSQL = "VARCHAR"
textSQL = "TEXT"
stringSQL = "STRING"
dateSQL = "DATE"
timestampSQL = "TIMESTAMP"
datetimeSQL = "DATETIME"
doubleSQL = "DOUBLE"
floatSQL = "FLOAT"
numericSQL = "NUMERIC"
decimalSQL = "DECIMAL"
booleanSQL = "BOOLEAN"
boolSQL = "BOOL"
)

// DataSource is a common interface for all data source types
type DataSource interface {
GetType() string
Expand Down Expand Up @@ -140,18 +169,18 @@ func (ds *WrenLocalFileDataSource) MapType(sourceType string) string {
sourceType = strings.ToUpper(sourceType)

switch sourceType {
case "INTEGER", "INT", "BIGINT":
return "integer"
case "VARCHAR", "TEXT", "STRING":
return "varchar"
case "DATE":
return "date"
case "TIMESTAMP", "DATETIME":
return "timestamp"
case "DOUBLE", "FLOAT", "NUMERIC", "DECIMAL":
return "double"
case "BOOLEAN", "BOOL":
return "boolean"
case integerSQL, intSQL, bigintSQL:
return integerType
case varcharSQL, textSQL, stringSQL:
return varcharType
case dateSQL:
return dateType
case timestampSQL, datetimeSQL:
return timestampType
case doubleSQL, floatSQL, numericSQL, decimalSQL:
return doubleType
case booleanSQL, boolSQL:
return booleanType
default:
// Return the original type if no mapping is found
return strings.ToLower(sourceType)
Expand Down
Loading