Skip to content

Commit

Permalink
Adding linting steps to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusgomes28 committed Feb 18, 2024
1 parent 0188d1c commit 7915d76
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/actions/golangci-lint/action.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/failfast.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion admin-app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 4 additions & 1 deletion database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package database

import (
"database/sql"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7915d76

Please sign in to comment.