diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml new file mode 100644 index 00000000..66d493fd --- /dev/null +++ b/.github/workflows/build_and_test.yml @@ -0,0 +1,16 @@ +on: [ push, pull_request ] +name: Build & Test + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21' + - name: Build + run: go build -v ./... + - name: Test + run: go test -v ./... diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 00000000..02a63879 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,22 @@ +on: [ push, pull_request ] +name: Lint + +permissions: + contents: read + pull-requests: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: '1.21' + cache: false + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.55 + only-new-issues: true diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..ea56b4cd --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,46 @@ +linters-settings: + gocritic: + enabled-tags: + - diagnostic + - style + - performance + disabled-checks: + - whyNoLint + - paramTypeCombine + gocyclo: + min-complexity: 15 + gofmt: + rewrite-rules: + - pattern: 'interface{}' + replacement: 'any' + govet: + check-shadowing: true + settings: + printf: + funcs: + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf + +linters: + disable-all: true + enable: + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - unused + - gofmt + - goimports + - goconst + - revive + - gocritic + - gosec + - unparam + - errorlint + - gocyclo + +run: + timeout: 5m diff --git a/cmd/eib/main.go b/cmd/eib/main.go index 33aab2ae..dc6e65b6 100644 --- a/cmd/eib/main.go +++ b/cmd/eib/main.go @@ -88,12 +88,12 @@ func parseImageConfig(configFile string, configDir string) (*config.ImageConfig, configFilePath := filepath.Join(configDir, configFile) configData, err := os.ReadFile(configFilePath) if err != nil { - return nil, fmt.Errorf("image configuration file \"%s\" cannot be read: %s", configFile, err) + return nil, fmt.Errorf("image configuration file \"%s\" cannot be read: %w", configFile, err) } imageConfig, err := config.Parse(configData) if err != nil { - return nil, fmt.Errorf("error parsing configuration file \"%s\": %s", configFile, err) + return nil, fmt.Errorf("error parsing configuration file \"%s\": %w", configFile, err) } return imageConfig, nil diff --git a/pkg/build/build.go b/pkg/build/build.go index 3c4af2e0..d1e43a59 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -11,6 +11,7 @@ import ( ) const ( + // nolint: unused embeddedScriptsBaseDir = "scripts" ) @@ -167,6 +168,7 @@ func (b *Builder) writeFile(filename string, contents string, templateData any) return nil } +// nolint: unused func (b *Builder) copyCombustionFile(scriptSubDir string, scriptName string) error { sourcePath := filepath.Join(embeddedScriptsBaseDir, scriptSubDir, scriptName) src, err := os.ReadFile(sourcePath) diff --git a/pkg/build/build_test.go b/pkg/build/build_test.go index bb3dc5d9..92c3fc6c 100644 --- a/pkg/build/build_test.go +++ b/pkg/build/build_test.go @@ -49,11 +49,11 @@ func TestCleanUpBuildDirTrue(t *testing.T) { defer os.RemoveAll(tmpDir) bc := config.BuildConfig{ - BuildDir: tmpDir, + BuildDir: tmpDir, DeleteBuildDir: true, } builder := New(nil, &bc) - builder.prepareBuildDir() + require.NoError(t, builder.prepareBuildDir()) // Test err = builder.cleanUpBuildDir() @@ -72,11 +72,11 @@ func TestCleanUpBuildDirFalse(t *testing.T) { defer os.RemoveAll(tmpDir) bc := config.BuildConfig{ - BuildDir: tmpDir, + BuildDir: tmpDir, DeleteBuildDir: false, } builder := New(nil, &bc) - builder.prepareBuildDir() + require.NoError(t, builder.prepareBuildDir()) // Test err = builder.cleanUpBuildDir() @@ -186,4 +186,4 @@ func TestWriteFileWithTemplate(t *testing.T) { foundData, err := os.ReadFile(expectedFilename) require.NoError(t, err) assert.Equal(t, "ooF and raB", string(foundData)) -} \ No newline at end of file +} diff --git a/pkg/build/raw_test.go b/pkg/build/raw_test.go index 4a63229d..7150ce3b 100644 --- a/pkg/build/raw_test.go +++ b/pkg/build/raw_test.go @@ -30,7 +30,7 @@ func TestCreateRawImageCopyCommand(t *testing.T) { require.NotNil(t, cmd) assert.Equal(t, copyExec, cmd.Path) - expectedArgs := []string { + expectedArgs := []string{ copyExec, builder.generateBaseImageFilename(), builder.generateOutputImageFilename(), @@ -51,10 +51,10 @@ func TestWriteModifyScript(t *testing.T) { } buildConfig := config.BuildConfig{ ImageConfigDir: "config-dir", - BuildDir: tmpDir, + BuildDir: tmpDir, } builder := New(&imageConfig, &buildConfig) - builder.prepareBuildDir() + require.NoError(t, builder.prepareBuildDir()) // Test err = builder.writeModifyScript() @@ -68,7 +68,7 @@ func TestWriteModifyScript(t *testing.T) { foundContents := string(foundBytes) assert.Contains(t, foundContents, "guestfish --rw -a config-dir/output-image") - assert.Contains(t, foundContents, "copy-in " + builder.combustionDir) + assert.Contains(t, foundContents, "copy-in "+builder.combustionDir) } func TestCreateModifyCommand(t *testing.T) { @@ -86,4 +86,4 @@ func TestCreateModifyCommand(t *testing.T) { expectedPath := filepath.Join("build-dir", modifyScriptName) assert.Equal(t, expectedPath, cmd.Path) -} \ No newline at end of file +} diff --git a/pkg/config/image.go b/pkg/config/image.go index 25123fac..3547e62d 100644 --- a/pkg/config/image.go +++ b/pkg/config/image.go @@ -13,7 +13,7 @@ const ( type ImageConfig struct { APIVersion string `yaml:"apiVersion"` - Image Image `yaml:"image"` + Image Image `yaml:"image"` } type Image struct {