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: 75 additions & 8 deletions .github/workflows/gofmt.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,96 @@
on: [pull_request]

name: Go Fmt

on:
pull_request:
types: [opened, synchronize, reopened, labeled]
push:
branches:
- main

permissions:
contents: write
pull-requests: write

jobs:
test:
gofmt:
strategy:
matrix:
go-version: [1.24.x]
go-version: [1.24.5]
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
fetch-depth: 0

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4

- name: Run Formatter
run: gofmt -w -s .

- name: Commit Changes
uses: stefanzweifel/git-auto-commit-action@v4.0.0
- name: Check for formatting changes (dry run)
if: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'testing') }}
run: |
git diff --exit-code || echo "::warning::Formatting changes would be applied in normal mode"
continue-on-error: true

- name: Commit Changes to PR
if: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'testing') }}
uses: stefanzweifel/git-auto-commit-action@v6.0.1
with:
commit_message: apply coding style fixes
commit_options: '--no-verify'
file_pattern: .
repository: .
commit_user_name: GitHub Actions
commit_user_email: ${{ secrets.GUS_GH_EMAIL }}
commit_author: gocanto <gocanto@users.noreply.github.com>
branch: ${{ github.head_ref }}

- name: Create branch for formatting changes
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: |
# Check if there are any changes after formatting
if ! git diff --quiet; then
# Create a new branch with timestamp
BRANCH_NAME="gofmt-fixes-$(date +%Y%m%d-%H%M%S)"
git checkout -b $BRANCH_NAME

# Configure git
git config user.name "GitHub Actions"
git config user.email "${{ secrets.GUS_GH_EMAIL }}"

# Commit changes
git add .
git commit -m "Apply Go formatting fixes"

# Push the branch
git push origin $BRANCH_NAME

# Set output for next step
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
echo "HAS_CHANGES=true" >> $GITHUB_ENV
else
echo "No formatting changes needed"
echo "HAS_CHANGES=false" >> $GITHUB_ENV
fi

- name: Create Pull Request
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && env.HAS_CHANGES == 'true' }}
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Apply Go formatting fixes
title: "Auto: Apply Go formatting fixes"
body: |
This PR was automatically created by the Go Fmt GitHub Action.
It applies Go formatting standards to the codebase.
branch: ${{ env.BRANCH_NAME }}
base: main
19 changes: 11 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ name: Tests

on:
pull_request:
types: [ready_for_review, synchronize, labeled]
types: [opened, reopened, ready_for_review, synchronize, labeled]
push:
branches: [main, master]

jobs:
test:
if: github.event.pull_request.draft == false ||
(github.event.action == 'labeled' && github.event.label.name == 'testing')
if: (github.event_name == 'push') ||
(github.event_name == 'pull_request' && (github.event.pull_request.draft == false ||
(github.event.action == 'labeled' && github.event.label.name == 'testing')))
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.24.5', '1.24.4']
go-version: ['1.24.6', '1.24.5']

steps:
- uses: actions/setup-go@v5
Expand All @@ -38,10 +41,10 @@ jobs:
go test -coverpkg=./... ./pkg/... -coverprofile=coverage-pkg-${{ matrix.go-version }}.out
go tool cover -func=coverage-pkg-${{ matrix.go-version }}.out | tail -n 1

- name: Run boost & env tests
- name: Run kernel & env tests
run: |
go test -coverpkg=./... ./boost ./env -coverprofile=coverage-boost-env-${{ matrix.go-version }}.out
go tool cover -func=coverage-boost-env-${{ matrix.go-version }}.out | tail -n 1
go test -coverpkg=./... ./metal/kernel ./metal/env -coverprofile=coverage-metal-env-${{ matrix.go-version }}.out
go tool cover -func=coverage-metal-env-${{ matrix.go-version }}.out | tail -n 1

- name: Run handlers tests
run: |
Expand All @@ -55,7 +58,7 @@ jobs:

- name: Run CLI tests
run: |
go test -coverpkg=./... ./cli/... -coverprofile=coverage-cli-${{ matrix.go-version }}.out
go test -coverpkg=./... ./metal/cli/... -coverprofile=coverage-cli-${{ matrix.go-version }}.out
go tool cover -func=coverage-cli-${{ matrix.go-version }}.out | tail -n 1

- name: Merge coverage reports
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ tmp

database/infra/data

# --- [API]: Bin
bin/*
!bin/.gitkeep

# --- [API]: Storage
storage/logs/*.*
storage/media/*.*
Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ VERSION := $(shell git describe --tags 2>/dev/null | cut -c 2-)
# -------------------------------------------------------------------------------------------------------------------- #
# -------------------------------------------------------------------------------------------------------------------- #

include ./config/makefile/helpers.mk
include ./config/makefile/env.mk
include ./config/makefile/db.mk
include ./config/makefile/app.mk
include ./config/makefile/logs.mk
include ./config/makefile/build.mk
include ./config/makefile/infra.mk
include ./metal/makefile/helpers.mk
include ./metal/makefile/env.mk
include ./metal/makefile/db.mk
include ./metal/makefile/app.mk
include ./metal/makefile/logs.mk
include ./metal/makefile/build.mk
include ./metal/makefile/infra.mk

# -------------------------------------------------------------------------------------------------------------------- #
# -------------------------------------------------------------------------------------------------------------------- #
Expand All @@ -53,7 +53,7 @@ help:
@printf " $(BOLD)$(GREEN)audit$(NC) : Run code audits and checks.\n"
@printf " $(BOLD)$(GREEN)watch$(NC) : Start a file watcher process.\n"
@printf " $(BOLD)$(GREEN)format$(NC) : Automatically format code.\n"
@printf " $(BOLD)$(GREEN)run-cli$(NC) : Run the API's cli interface.\n\n"
@printf " $(BOLD)$(GREEN)test-all$(NC) : Run all the application tests.\n\n"

@printf "$(BOLD)$(BLUE)Build Commands:$(NC)\n"
@printf " $(BOLD)$(GREEN)build-local$(NC) : Build the main application for development.\n"
Expand Down
Empty file added bin/.gitkeep
Empty file.
14 changes: 7 additions & 7 deletions database/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package database
import (
"database/sql"
"fmt"
"github.com/oullin/env"
"github.com/oullin/metal/env"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"log/slog"
Expand Down Expand Up @@ -49,24 +49,24 @@ func (c *Connection) Close() bool {
func (c *Connection) Ping() {
var driver *sql.DB

fmt.Println("\n---------")
slog.Info("Database ping started", "separator", "---------")

if conn, err := c.driver.DB(); err != nil {
fmt.Println(fmt.Sprintf("error retrieving the db driver: %v", err.Error()))
slog.Error("Error retrieving the db driver", "error", err.Error())

return
} else {
driver = conn
fmt.Println(fmt.Sprintf("db driver adquired: %T", driver))
slog.Info("Database driver acquired", "type", fmt.Sprintf("%T", driver))
}

if err := driver.Ping(); err != nil {
slog.Error("error pinging the db driver: " + err.Error())
slog.Error("Error pinging the db driver", "error", err.Error())
}

fmt.Println(fmt.Sprintf("db driver is healthy: %+v", driver.Stats()))
slog.Info("Database driver is healthy", "stats", driver.Stats())

fmt.Println("---------")
slog.Info("Database ping completed", "separator", "---------")
}

func (c *Connection) Sql() *gorm.DB {
Expand Down
2 changes: 1 addition & 1 deletion database/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/oullin/database"
"github.com/oullin/database/repository"
"github.com/oullin/env"
"github.com/oullin/metal/env"
)

func TestApiKeysWithTestContainer(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion database/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/oullin/database"
"github.com/oullin/database/repository"
"github.com/oullin/env"
"github.com/oullin/metal/env"
)

func setupDB(t *testing.T) *database.Connection {
Expand Down
2 changes: 1 addition & 1 deletion database/repository/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package repository

import (
"github.com/oullin/database"
"github.com/oullin/env"
"github.com/oullin/metal/env"
"github.com/oullin/pkg/gorm"
"strings"
)
Expand Down
17 changes: 9 additions & 8 deletions database/seeder/main.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
package main

import (
"github.com/oullin/boost"
"sync"
"time"

"github.com/oullin/database"
"github.com/oullin/database/seeder/seeds"
"github.com/oullin/env"
"github.com/oullin/metal/env"
"github.com/oullin/metal/kernel"
"github.com/oullin/pkg"
"github.com/oullin/pkg/cli"
"sync"
"time"
)

var environment *env.Environment

func init() {
secrets := boost.Ignite("./.env", pkg.GetDefaultValidator())
secrets := kernel.Ignite("./.env", pkg.GetDefaultValidator())

environment = secrets
}

func main() {
cli.ClearScreen()

dbConnection := boost.MakeDbConnection(environment)
logs := boost.MakeLogs(environment)
dbConnection := kernel.MakeDbConnection(environment)
logs := kernel.MakeLogs(environment)

defer (*logs).Close()
defer logs.Close()
defer (*dbConnection).Close()

// [1] --- Create the Seeder Runner.
Expand Down
2 changes: 1 addition & 1 deletion database/seeder/seeds/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"github.com/google/uuid"
"github.com/oullin/database"
"github.com/oullin/env"
"github.com/oullin/metal/env"
"math/rand"
"time"
)
Expand Down
2 changes: 1 addition & 1 deletion database/seeder/seeds/seeder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/testcontainers/testcontainers-go/modules/postgres"

"github.com/oullin/database"
"github.com/oullin/env"
"github.com/oullin/metal/env"
)

func testConnection(t *testing.T, e *env.Environment) *database.Connection {
Expand Down
2 changes: 1 addition & 1 deletion database/truncate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package database
import (
"errors"
"fmt"
"github.com/oullin/env"
"github.com/oullin/metal/env"
)

type Truncate struct {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/oullin

go 1.24
go 1.24.5

require (
github.com/getsentry/sentry-go v0.35.0
Expand Down
2 changes: 1 addition & 1 deletion handler/tests/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/google/uuid"
"github.com/oullin/database"
"github.com/oullin/env"
"github.com/oullin/metal/env"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/postgres"
)
Expand Down
11 changes: 7 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ package main

import (
"fmt"
"github.com/getsentry/sentry-go"
_ "github.com/lib/pq"
"github.com/oullin/boost"
"github.com/oullin/metal/kernel"
"github.com/oullin/pkg"
"github.com/rs/cors"
"log/slog"
baseHttp "net/http"
"time"
)

var app *boost.App
var app *kernel.App

func init() {
validate := pkg.GetDefaultValidator()
secrets := boost.Ignite("./.env", validate)
application, err := boost.MakeApp(secrets, validate)
secrets := kernel.Ignite("./.env", validate)
application, err := kernel.MakeApp(secrets, validate)

if err != nil {
panic(fmt.Sprintf("init: Error creating application: %s", err))
Expand All @@ -27,6 +29,7 @@ func init() {
func main() {
defer app.CloseDB()
defer app.CloseLogs()
defer sentry.Flush(2 * time.Second)

app.Boot()

Expand Down
2 changes: 1 addition & 1 deletion cli/accounts/factory.go → metal/cli/accounts/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"github.com/oullin/database"
"github.com/oullin/database/repository"
"github.com/oullin/env"
"github.com/oullin/metal/env"
"github.com/oullin/pkg/auth"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package accounts

import (
"github.com/oullin/cli/clitest"
"github.com/oullin/metal/cli/clitest"
"testing"

"github.com/oullin/database"
Expand Down
File renamed without changes.
Loading
Loading