diff --git a/.github/workflows/actions/golangci-lint/action.yml b/.github/workflows/actions/golangci-lint/action.yml new file mode 100644 index 0000000..cbd5efa --- /dev/null +++ b/.github/workflows/actions/golangci-lint/action.yml @@ -0,0 +1,12 @@ +name: golangci-lint step +description: golangci-lint step +inputs: + linter: + description: Linter to run + required: true +runs: + using: composite + steps: + - name: Golang CI 2 + run: golangci-lint run --disable-all -E ${{ inputs.linter }} + 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..d887242 --- /dev/null +++ b/.github/workflows/failfast.yml @@ -0,0 +1,39 @@ +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 errcheck 🧪 + with: + linter: errcheck + + - uses: ./.github/workflows/actions/golangci-lint + name: Running staticcheck 🧪 + with: + linter: staticcheck + + - uses: ./.github/workflows/actions/golangci-lint + name: Running unused 🧪 + with: + linter: unused + + - uses: ./.github/workflows/actions/golangci-lint + name: Running gosimple 🧪 + with: + linter: gosimple + + - uses: ./.github/workflows/actions/golangci-lint + name: Running gofmt 🧪 + with: + linter: gofmt + \ No newline at end of file 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)