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 17, 2024
1 parent 0188d1c commit cfac76d
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/actions/golangci-lint/action.yml
Original file line number Diff line number Diff line change
@@ -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
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
39 changes: 39 additions & 0 deletions .github/workflows/failfast.yml
Original file line number Diff line number Diff line change
@@ -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

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 cfac76d

Please sign in to comment.