Skip to content

Commit

Permalink
Set up initial CI config (#27)
Browse files Browse the repository at this point in the history
* Add build & test CI workflow

* Add lint CI workflow

* Fix linter issues

* Set disable-all linters to true

* Drop paramTypeCombine check from gocritic
  • Loading branch information
atanasdinov authored Oct 31, 2023
1 parent 700bd5d commit 3029c9b
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 13 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -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 ./...
22 changes: 22 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -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
46 changes: 46 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions cmd/eib/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

const (
// nolint: unused
embeddedScriptsBaseDir = "scripts"
)

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions pkg/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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))
}
}
10 changes: 5 additions & 5 deletions pkg/build/raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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()
Expand All @@ -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) {
Expand All @@ -86,4 +86,4 @@ func TestCreateModifyCommand(t *testing.T) {

expectedPath := filepath.Join("build-dir", modifyScriptName)
assert.Equal(t, expectedPath, cmd.Path)
}
}
2 changes: 1 addition & 1 deletion pkg/config/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (

type ImageConfig struct {
APIVersion string `yaml:"apiVersion"`
Image Image `yaml:"image"`
Image Image `yaml:"image"`
}

type Image struct {
Expand Down

0 comments on commit 3029c9b

Please sign in to comment.