Skip to content

Commit

Permalink
Merge pull request #5 from chezmoi/build-infra
Browse files Browse the repository at this point in the history
chore: add basic build infrastructure
  • Loading branch information
twpayne authored Nov 20, 2023
2 parents 250a984 + ee12a37 commit e6d2fc7
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 27 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: main
on:
pull_request:
push:
branches:
- master
tags:
- v*
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe
- run: go test ./...
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe
- uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc
with:
version: v1.55.2
140 changes: 140 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
linters:
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- decorder
- dogsled
- dupl
- dupword
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
- exportloopref
- forbidigo
- forcetypeassert
- gci
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoinits
- gochecksumtype
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- goerr113
- gofmt
- gofumpt
- goheader
- goimports
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- gosmopolitan
- govet
- grouper
- importas
- inamedparam
- ineffassign
- interfacebloat
- ireturn
- lll
- loggercheck
- makezero
- mirror
- misspell
- musttag
- nakedret
- nestif
- nilerr
- nilnil
- noctx
- nolintlint
- nonamedreturns
- nosprintfhostport
- perfsprint
- prealloc
- predeclared
- promlinter
- protogetter
- reassign
- revive
- rowserrcheck
- sloglint
- sqlclosecheck
- staticcheck
- stylecheck
- tagalign
- tagliatelle
- tenv
- testableexamples
- testifylint
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
disable:
- cyclop
- depguard
- exhaustruct
- funlen
- gochecknoglobals
- godox
- gomnd
- maintidx
- nlreturn
- paralleltest
- testpackage
- varnamelen
- wrapcheck
- wsl

linters-settings:
gci:
sections:
- standard
- default
- prefix(github.com/chezmoi/templatefuncs)
gofumpt:
extra-rules: true
goimports:
local-prefixes: github.com/chezmoi/templatefuncs
govet:
disable:
- fieldalignment
- shadow
enable-all: true
misspell:
locale: US
stylecheck:
checks:
- all

issues:
exclude-rules:
- linters:
- dupl
- scopelint
path: "_test\\.go"
- linters:
- forbidigo
- gosec
path: "internal/"
- linters:
- goerr113
text: do not define dynamic errors, use wrapped static errors instead
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ module github.com/chezmoi/templatefuncs

go 1.19

require github.com/stretchr/testify v1.8.1
require github.com/alecthomas/assert/v2 v2.4.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
github.com/alecthomas/repr v0.3.0 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
)
23 changes: 6 additions & 17 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
github.com/alecthomas/assert/v2 v2.4.0 h1:/ZiZ0NnriAWPYYO+4eOjgzNELrFQLaHNr92mHSHFj9U=
github.com/alecthomas/assert/v2 v2.4.0/go.mod h1:fw5suVxB+wfYJ3291t0hRTqtGzFYdSwstnRQdaQx2DM=
github.com/alecthomas/repr v0.3.0 h1:NeYzUPfjjlqHY4KtzgKJiWd6sVq2eNUPTi34PiFGjY8=
github.com/alecthomas/repr v0.3.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
2 changes: 1 addition & 1 deletion templatefuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func toStringTemplateFunc(arg any) string {
case float32:
return strconv.FormatFloat(float64(arg), 'f', -1, 32)
case float64:
return strconv.FormatFloat(float64(arg), 'f', -1, 64)
return strconv.FormatFloat(arg, 'f', -1, 64)
case int:
return strconv.Itoa(arg)
case int32:
Expand Down
9 changes: 4 additions & 5 deletions templatefuncs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"testing"
"text/template"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/alecthomas/assert/v2"
)

func TestEachString(t *testing.T) {
Expand Down Expand Up @@ -138,11 +137,11 @@ func TestFuncMap(t *testing.T) {
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
tmpl, err := template.New("").Funcs(funcMap).Parse(tc.template)
require.NoError(t, err)
require.NotNil(t, tmpl)
assert.NoError(t, err)
assert.NotZero(t, tmpl)

var actual strings.Builder
require.NoError(t, tmpl.Execute(&actual, tc.data))
assert.NoError(t, tmpl.Execute(&actual, tc.data))
assert.Equal(t, tc.expected, actual.String())
})
}
Expand Down

0 comments on commit e6d2fc7

Please sign in to comment.