Skip to content

Commit

Permalink
chore(stencil): stencil-golang v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredallard committed Dec 22, 2024
1 parent 8ddf52b commit 08b95cd
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 76 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ permissions:
contents: write
packages: write
issues: write
# Below are required for attestations
# Used by attestations in the release workflow.
id-token: write
attestations: write

Expand Down Expand Up @@ -58,11 +58,11 @@ jobs:
- uses: actions/cache@v4
with:
path: ${{ steps.go.outputs.cache_dir }}
key: ${{ runner.os }}-go-build-cache-rel-${{ hashFiles('**/go.sum') }}
key: ${{ github.workflow }}-${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }}
- uses: actions/cache@v4
with:
path: ${{ steps.go.outputs.mod_cache_dir }}
key: ${{ runner.os }}-go-mod-cache-${{ hashFiles('go.sum') }}
key: ${{ github.workflow }}-${{ runner.os }}-go-mod-cache-${{ hashFiles('go.sum') }}
- name: Retrieve goreleaser version
run: |-
echo "version=$(mise current goreleaser)" >> "$GITHUB_OUTPUT"
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ launch.json

# Currently a build artifact
CHANGELOG.md

## <<Stencil::Block(custom)>>

## <</Stencil::Block>>
45 changes: 15 additions & 30 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,38 @@
# yaml-language-server: $schema=https://json.schemastore.org/golangci-lint
lintroller:
tier: "platinum"

# Linter settings
linters-settings:
dupl:
threshold: 100
errcheck:
check-blank: true
funlen:
lines: 500
statements: 50
gocyclo:
min-complexity: 25
goconst:
min-len: 3
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
lll:
line-length: 140

linters:
# Inverted configuration with enable-all and disable is not scalable during updates of golangci-lint.
# Inverted configuration with enable-all and disable is not scalable
# during updates of golangci-lint.
disable-all: true
enable:
- bodyclose
- dogsled
- errcheck
- errorlint
- exhaustive # Checks exhaustiveness of enum switch statements.
- exhaustive
- copyloopvar
- funlen
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goheader
- goimports
- revive
- gosec
- gosimple
- govet
Expand All @@ -45,6 +41,7 @@ linters:
- misspell
- nakedret
- staticcheck
- revive
- typecheck
- unconvert
- unparam
Expand All @@ -61,24 +58,12 @@ issues:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- gocyclo
- errcheck
- gosec
- funlen
- gochecknoglobals # Globals in test files are tolerated.
- goconst # Repeated consts in test files are tolerated.
# This rule is buggy and breaks on our `///Block` lines. Disable for now.
- linters:
- gocritic
text: "commentFormatting: put a space"
# This rule incorrectly flags nil references after assert.Assert(t, x != nil)
- path: _test\.go
text: "SA5011"
linters:
- staticcheck
- linters:
- lll
source: "^//go:generate "
- gocyclo
- goheader # Don't require license headers in test files.
- gosec

output:
sort-results: true
14 changes: 6 additions & 8 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
version: 2
project_name: stencil
before:
hooks:
- go mod tidy
report_sizes: true
metadata:
mod_timestamp: "{{ .CommitTimestamp }}"
builds:
- main: ./cmd/{{ .ProjectName }}
- main: ./cmd/stencil
flags:
- -trimpath
ldflags:
- -s
- -w
## <<Stencil::Block(ldflags)>>
## <<Stencil::Block(stencilLdflags)>>
- -X go.rgst.io/stencil/internal/version.version={{.Version}}
- -X go.rgst.io/stencil/internal/version.commit={{.Commit}}
- -X go.rgst.io/stencil/internal/version.date={{ .CommitDate }}
Expand All @@ -26,16 +23,17 @@ builds:
goarch:
- amd64
- arm64
## <<Stencil::Block(extraArch)>>
## <<Stencil::Block(stencilExtraArch)>>
- "386"
- arm
- ppc64
## <</Stencil::Block>>
goos:
- linux
- darwin
## <<Stencil::Block(extraOS)>>
- windows
## <<Stencil::Block(stencilExtraOS)>>

## <</Stencil::Block>>
ignore:
- goos: windows
Expand All @@ -44,7 +42,7 @@ builds:
checksum:
name_template: "checksums.txt"
snapshot:
name_template: "{{ incpatch .Version }}-next"
version_template: "{{ incpatch .Version }}-next"
changelog:
use: git
release:
Expand Down
6 changes: 1 addition & 5 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@

# Default versions of tools, to update these, set [tools.override]
[tools]
bun = "latest"
git-cliff = "latest"
golang = "1.23.4"
golangci-lint = "1.62.2"
goreleaser = "latest"
"go:gotest.tools/gotestsum" = "v1.12.0"
"go:golang.org/x/tools/cmd/goimports" = "latest"
"go:mvdan.cc/sh/v3/cmd/shfmt" = "latest"
# TODO(jaredallard): Deviated from stencil-golang.
bun = "latest"
"go:github.com/thenativeweb/get-next-version" = "latest"
"go:sigs.k8s.io/mdtoc" = "latest"

[tasks.build]
description = "Build a binary for the current platform/architecture"
outputs = ["bin/stencil"]
sources = ["cmd/**/*.go", "internal/**/*.go", "pkg/**/*.go", "go.mod", "go.sum"]
run = "go build -trimpath -o ./bin/ -v ./cmd/..."

[tasks.changelog]
Expand All @@ -32,7 +29,6 @@ run = [
"gofmt -s -w .",
"goimports -w .",
"shfmt -w .",
# TODO(jaredallard): Deviated from stencil-golang.
"bun node_modules/.bin/prettier --write '**/*.{json,yaml,yml,md,jsonschema.json}'",
]

Expand Down
38 changes: 20 additions & 18 deletions .vscode/common.code-snippets
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
{
"Copyright": {
"description": "Inserts a GNU GPLv3 license header",
"description": "Inserts a copyright header",
"prefix": ["license", "copy", "copyright"],
"body": [
"// Copyright (C) ${CURRENT_YEAR} stencil contributors",
"//",
"// Licensed under the Apache License, Version 2.0 (the \"License\");",
"// you may not use this file except in compliance with the License.",
"// You may obtain a copy of the License at",
"//",
"// http://www.apache.org/licenses/LICENSE-2.0",
"//",
"// Unless required by applicable law or agreed to in writing, software",
"// distributed under the License is distributed on an \"AS IS\" BASIS,",
"// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.",
"// See the License for the specific language governing permissions and",
"// limitations under the License.",
""
]
}
"body": [
"// Copyright (C) ${CURRENT_YEAR} stencil contributors",
"//",
"// Licensed under the Apache License, Version 2.0 (the \"License\");",
"// you may not use this file except in compliance with the License.",
"// You may obtain a copy of the License at",
"//",
"// http://www.apache.org/licenses/LICENSE-2.0",
"//",
"// Unless required by applicable law or agreed to in writing, software",
"// distributed under the License is distributed on an \"AS IS\" BASIS,",
"// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.",
"// See the License for the specific language governing permissions and",
"// limitations under the License.",
"//",
"// SPDX-License-Identifier: Apache-2.0",
"",
]
}
}
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,5 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.

Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion cmd/stencil/stencil.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

// Set the version printer to do nothing but print the version.
//
//nolint:gochecknoinits
//nolint:gochecknoinits // Why: This is acceptable.
func init() {
cli.VersionPrinter = func(_ *cli.Context) {
fmt.Println(version.Version.String())
Expand Down
2 changes: 1 addition & 1 deletion internal/codegen/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func parseBlocks(filePath string, sourceTemplate *Template) (map[string]*blockIn

// parseBlocksInner is the inner implementation of parseBlocks, reusable from inside adoptBlocks to parse blocks
// from the source template contents
// nolint: funlen
// nolint:funlen // Why: Will refactor in the future.
func parseBlocksInner(r io.ReadSeeker, filePath string, sourceTemplate *Template) (map[string]*blockInfo, error) {
blocks := make(map[string]*blockInfo)
var curBlock *blockInfo
Expand Down
2 changes: 1 addition & 1 deletion internal/codegen/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestBlockInsideBlock(t *testing.T) {
func TestWrongEndBlock(t *testing.T) {
_, err := parseBlocks("testdata/wrongendblock-test.txt", fakeBlocksTemplate())
assert.Error(t, err,
"invalid EndBlock, found EndBlock with name \"wrongend\" while inside of block with name \"helloWorld\", at testdata/wrongendblock-test.txt:3", //nolint:lll
"invalid EndBlock, found EndBlock with name \"wrongend\" while inside of block with name \"helloWorld\", at testdata/wrongendblock-test.txt:3", //nolint:lll // Why: test
"expected parseBlocks() to fail")
}

Expand Down
4 changes: 1 addition & 3 deletions internal/codegen/tpl_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ func TestTplFile_OnceFileAlreadyExists(t *testing.T) {
}

assert.NilError(t, os.WriteFile("test.go", []byte("test"), 0o644))
defer func() {
os.Remove("test.go")
}()
defer os.Remove("test.go")

fo, err := tplf.Once()
assert.NilError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/stencil/lockfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (lf *Lockfile) PruneFiles(onlyFiles []string) []string {
return missingFilenames
}

func (lf *Lockfile) PruneModules(newModuleNames []string, onlyModules []string) []string {
func (lf *Lockfile) PruneModules(newModuleNames, onlyModules []string) []string {
missingModulesList := []*LockfileModuleEntry{}
for _, lf := range lf.Modules {
if len(onlyModules) > 0 && !slices.Contains(onlyModules, lf.Name) {
Expand Down
18 changes: 15 additions & 3 deletions stencil.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ modules:
- name: github.com/rgst-io/stencil-golang
url: https://github.com/rgst-io/stencil-golang
version:
commit: 553b465e2e6fb0f3ce71a6e2b9add52e8513eb62
branch: main
commit: 2caa391c628957e7477ffd9fcd1c52a3029b254d
tag: v1.2.0
files:
- name: .cliff.toml
template: .cliff.toml.tpl
Expand All @@ -24,6 +24,12 @@ files:
- name: .github/workflows/tests.yaml
template: .github/workflows/tests.yaml.tpl
module: github.com/rgst-io/stencil-golang
- name: .gitignore
template: .gitignore.tpl
module: github.com/rgst-io/stencil-golang
- name: .golangci.yml
template: .golangci.yml.tpl
module: github.com/rgst-io/stencil-golang
- name: .goreleaser.yaml
template: .goreleaser.yaml.tpl
module: github.com/rgst-io/stencil-golang
Expand All @@ -33,6 +39,9 @@ files:
- name: .mise/tasks/changelog-release
template: .mise/tasks/changelog-release.tpl
module: github.com/rgst-io/stencil-golang
- name: .vscode/common.code-snippets
template: .vscode/common.code-snippets.tpl
module: github.com/rgst-io/stencil-golang
- name: .vscode/extensions.json
template: .vscode/extensions.json.tpl
module: github.com/rgst-io/stencil-golang
Expand All @@ -43,5 +52,8 @@ files:
template: CONTRIBUTING.md.tpl
module: github.com/rgst-io/stencil-golang
- name: LICENSE
template: LICENSE_Apache-2.0.tpl
template: LICENSE.tpl
module: github.com/rgst-io/stencil-golang
- name: package.json
template: package.json.tpl
module: github.com/rgst-io/stencil-golang
1 change: 0 additions & 1 deletion stencil.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ arguments:
license: Apache-2.0
modules:
- name: github.com/rgst-io/stencil-golang
version: main

0 comments on commit 08b95cd

Please sign in to comment.