From 7915d76c952da26b551d42c22f6b1730b1844b09 Mon Sep 17 00:00:00 2001 From: matheusgomes28 Date: Sat, 17 Feb 2024 21:35:34 +0000 Subject: [PATCH] Adding linting steps to CI --- .../workflows/actions/golangci-lint/action.yml | 15 +++++++++++++++ .github/workflows/build.yml | 2 +- .github/workflows/failfast.yml | 18 ++++++++++++++++++ .github/workflows/pipeline.yml | 7 ++++--- admin-app/app.go | 7 ++++++- database/database.go | 5 ++++- 6 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/actions/golangci-lint/action.yml create mode 100644 .github/workflows/failfast.yml diff --git a/.github/workflows/actions/golangci-lint/action.yml b/.github/workflows/actions/golangci-lint/action.yml new file mode 100644 index 0000000..8cc3807 --- /dev/null +++ b/.github/workflows/actions/golangci-lint/action.yml @@ -0,0 +1,15 @@ +name: golangci-lint step +description: golangci-lint step +inputs: + linters: + description: Linter to run + required: true +runs: + using: composite + steps: + - name: Golang CI 2 + run: | + templ generate + LINTERS="${{ inputs.linters }}" + golangci-lint run --disable-all -E ${LINTERS//;/ -E } + shell: bash diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2ee72ab..09ae49f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest container: - image: mattgomes28/urchin-golang:0.1 + image: mattgomes28/urchin-golang:0.2 options: --user 1001 steps: diff --git a/.github/workflows/failfast.yml b/.github/workflows/failfast.yml new file mode 100644 index 0000000..8887946 --- /dev/null +++ b/.github/workflows/failfast.yml @@ -0,0 +1,18 @@ +name: Fail Fast + +on: [workflow_call] + +jobs: + format-check: + runs-on: ubuntu-latest + container: + image: mattgomes28/urchin-golang:0.2 + options: --user 1001 + + steps: + - uses: actions/checkout@v3 + + - uses: ./.github/workflows/actions/golangci-lint + name: Running Linters 🧪 + with: + linters: errcheck;staticcheck;unused;gosimple;gofmt diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 9d934b4..e46c48c 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -7,11 +7,12 @@ on: branches: [ "main" ] jobs: - # failfast: - # uses: ./.github/workflows/failfast.yml + failfast: + uses: ./.github/workflows/failfast.yml + build: uses: ./.github/workflows/build.yml - # needs: failfast + needs: failfast # tests: # uses: ./.github/workflows/test.yml # needs: build diff --git a/admin-app/app.go b/admin-app/app.go index 1dc507f..9c5ae6d 100644 --- a/admin-app/app.go +++ b/admin-app/app.go @@ -186,7 +186,12 @@ func Run(app_settings common.AppSettings, database database.Database) error { r.POST("/posts", postPostHandler(&database)) r.PUT("/posts", putPostHandler(&database)) r.DELETE("/posts", deletePostHandler(&database)) - r.Run(fmt.Sprintf(":%s", app_settings.WebserverPort)) + + err := r.Run(fmt.Sprintf(":%s", app_settings.WebserverPort)) + if err != nil { + log.Error().Msgf("could not run app: %v", err) + return err + } return nil } diff --git a/database/database.go b/database/database.go index eac7c80..628c6be 100644 --- a/database/database.go +++ b/database/database.go @@ -2,6 +2,7 @@ package database import ( "database/sql" + "errors" "fmt" "time" @@ -82,7 +83,9 @@ func (db *Database) ChangePost(id int, title string, excerpt string, content str if err != nil { return err } - defer tx.Rollback() + defer func() { + err = errors.Join(tx.Rollback()) + }() if len(title) > 0 { _, err := tx.Exec("UPDATE posts SET title = ? WHERE id = ?;", title, id)