Skip to content

Commit

Permalink
Merge pull request #39 from Ilyes512/use-golangci-lint-and-fixed-all-…
Browse files Browse the repository at this point in the history
…current-issues

Use-golangci-lint-and-fixed-all-current-issues
  • Loading branch information
Ilyes512 committed Nov 21, 2023
2 parents e43a6b3 + 85cffcb commit 057eb4f
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ permissions: read-all

jobs:
build:
name: build
runs-on: ubuntu-22.04
steps:
- name: Checkout
Expand All @@ -21,6 +22,7 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: stable
check-latest: true
- name: Use Goreleaser for building Boilr
uses: goreleaser/goreleaser-action@v5
with:
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: golangci-lint

on:
pull_request:
push:
branches:
- main

permissions:
contents: read
pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: stable
check-latest: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
only-new-issues: true
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: stable
check-latest: true
- name: Use Goreleaser to release Boilr
uses: goreleaser/goreleaser-action@v5
with:
Expand Down
10 changes: 10 additions & 0 deletions Taskfile.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version: '3'
silent: true

env:
GOLANGCI_LINT_VERSION: latest
# BUILDKIT_PROGRESS: plain

vars:
Expand Down Expand Up @@ -36,6 +37,15 @@ tasks:
golang:{{.GO_VERSION}}
/bin/bash -c 'go list -f "{{`{{if not (or .Main .Indirect)}}{{.Path}}{{end}}`}}" -m all | xargs -r go list -m -u'

go:lint:
desc: Lint go code using Golangci-lint
cmds:
- docker run --rm
--workdir /workspace
--volume $(pwd):/workspace
golangci/golangci-lint:{{.GOLANGCI_LINT_VERSION}}
golangci-lint run

go:remove-cache-volumes:
desc: Remove Go cache volumes
cmds:
Expand Down
5 changes: 4 additions & 1 deletion pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@ func Run() {
Version.PersistentFlags().BoolP("dont-prettify", "", false, "Only print the version without fancy formatting")
Root.AddCommand(Version)

Root.Execute()
err := Root.Execute()
if err != nil {
panic(err)
}
}
5 changes: 3 additions & 2 deletions pkg/cmd/use_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ func TestUseExecutesProjectTemplate(t *testing.T) {
tmpDirPath, err := ioutil.TempDir("", "template-test")
if err != nil {
t.Fatalf("ioutil.TempDir() got error -> %v", err)
} else {
//defer os.RemoveAll(tmpDirPath)
}
// else {
// defer os.RemoveAll(tmpDirPath)
// }

if err := os.MkdirAll(filepath.Join(tmpDirPath, "input", "{{Name}}", "{{Date}}"), 0744); err != nil {
t.Fatalf("os.MkdirAll should have created template directories -> got error %v", err)
Expand Down
4 changes: 1 addition & 3 deletions pkg/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"github.com/Ilyes512/boilr/pkg/util/tlog"
)

type templateFunc func() interface{}

// Interface for prompts.
type Interface interface {
// PromptMessage returns a proper prompt message for the given field with the given default value.
Expand Down Expand Up @@ -92,7 +90,7 @@ func Func(defval interface{}) Interface {
return boolPrompt(defval)
case []interface{}:
if len(defval) == 0 {
tlog.Warn(fmt.Sprintf("empty list of choices"))
tlog.Warn("empty list of choices")
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/template/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Metadata struct {

// String returns the string slice form of Metadata.
func (m Metadata) String() []string {
tDelta := time.Now().Sub(time.Time(m.Created))
tDelta := time.Since(time.Time(m.Created))
return []string{m.Tag, m.Repository, units.HumanDuration(tDelta) + " ago"}
}

Expand Down Expand Up @@ -55,5 +55,5 @@ func (t *JSONTime) UnmarshalJSON(b []byte) error {

// String returns the string form of JSONTime.
func (t JSONTime) String() string {
return fmt.Sprintf("%s", time.Time(t).Format(timeFormat))
return time.Time(t).Format(timeFormat)
}
3 changes: 1 addition & 2 deletions pkg/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ type dirTemplate struct {
FuncMap template.FuncMap
Metadata Metadata

alignment string
ShouldUseDefaults bool
}

Expand Down Expand Up @@ -208,7 +207,7 @@ func (t *dirTemplate) Execute(dirPrefix string) error {
return err
}
if isBin {
_, err = origF.Seek(io.SeekStart, 0)
_, err = origF.Seek(0, io.SeekStart)
if err != nil {
return err
}
Expand Down

0 comments on commit 057eb4f

Please sign in to comment.