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
33 changes: 33 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: golangci-lint
on:
push:
branches:
- main
pull_request:

permissions:
contents: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable

- name: Install Goreleaser
uses: goreleaser/goreleaser-action@v6
with:
version: "v2.8.2"
install-only: true

- name: Build railcar binaries
run: make railcar-build-binaries

- name: golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: v2.1.2
9 changes: 9 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# https://golangci-lint.run/
version: "2"
linters:
enable:
- gocyclo
formatters:
enable:
- gofumpt
- goimports
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ railcar-build-binaries:
.Phony: go-test
go-test:
go test ./... --race

.Phony: lint
lint:
golangci-lint run
10 changes: 6 additions & 4 deletions cmd/conductor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ func main() {
if err != nil {
pterm.Fatal.Println(err)
}
defer file.Close()
defer func() {
_ = file.Close()
}()

byt, err := io.ReadAll(file)
if err != nil {
Expand All @@ -41,7 +43,7 @@ func main() {
case githooks.CommitMsg:
commitMsg, err := os.ReadFile(os.Args[2])
if err != nil {
pterm.Fatal.Printfln("Error reading commit message file: ", err)
pterm.Fatal.Println("Error reading commit message file: ", err)
}

// Process the commit message
Expand All @@ -57,7 +59,7 @@ func main() {
case githooks.PrepareCommitMsg:
commitMsg, err := os.ReadFile(os.Args[2])
if err != nil {
pterm.Fatal.Printfln("Error reading commit message file: ", err)
pterm.Fatal.Println("Error reading commit message file: ", err)
}
if len(cfg.RailCar.CommitOperations.PrepareCommitMsg) != 0 {
run(cfg.RailCar.CommitOperations.PrepareCommitMsg, string(commitMsg))
Expand Down Expand Up @@ -95,7 +97,7 @@ func run(data []config.HookStep, hookData string) {

if strings.Contains(v.Command, "{HOOK_INPUT}") {
hookData = strings.TrimSuffix(hookData, "\n")
newStr := strings.Replace(v.Command, "{HOOK_INPUT}", hookData, -1)
newStr := strings.ReplaceAll(v.Command, "{HOOK_INPUT}", hookData)
cmd = exec.Command("sh", "-c", newStr)
} else {
cmd = exec.Command("sh", "-c", fmt.Sprintf("%s %s", v.Command, hookData))
Expand Down
4 changes: 3 additions & 1 deletion internal/blueprint/blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ func (b *BluePrint) Write() error {
if err != nil {
return err
}
defer file.Close()
defer func() {
_ = file.Close()
}()

if err := tmpl.Execute(file, b.Values); err != nil {
return err
Expand Down
4 changes: 3 additions & 1 deletion internal/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ func TestGitDirs(t *testing.T) {
oldWd, err := os.Getwd()
require.NoError(t, err)
require.NoError(t, os.Chdir(tempDir))
defer os.Chdir(oldWd)
defer func() {
_ = os.Chdir(oldWd)
}()

err = validate.GitDirs()
if tc.fail {
Expand Down