Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI

on: ["push", "release"]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
lint:
name: "Lint the repository"
uses: ./.github/workflows/job-lint.yml
test:
name: "Run tests and lint artifacts"
needs:
- lint
secrets: inherit
strategy:
fail-fast: false # Run the whole matrix for maximum information. No matter if we fail with one job early.
matrix:
os:
- "macOS-latest"
- "ubuntu-latest"
- "windows-latest"
uses: ./.github/workflows/job-test.yml
with:
os: ${{ matrix.os }}
24 changes: 0 additions & 24 deletions .github/workflows/go.yml

This file was deleted.

18 changes: 18 additions & 0 deletions .github/workflows/job-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
workflow_call:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Lint
run: make lint
shell: bash # Explicitly use Bash because otherwise failing Windows jobs are not erroring.
34 changes: 34 additions & 0 deletions .github/workflows/job-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
on:
workflow_call:
inputs:
os:
required: true
type: string

jobs:
test:
runs-on: ${{ inputs.os }}
steps:
- uses: actions/checkout@v4

- uses: jlumbroso/free-disk-space@main
if: contains(inputs.os, 'ubuntu')

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Set up Git
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "<>"
shell: bash # Explicitly use Bash because otherwise failing Windows jobs are not erroring.

- name: Build
run: make install
shell: bash # Explicitly use Bash because otherwise failing Windows jobs are not erroring.

- name: Test
run: make test
shell: bash # Explicitly use Bash because otherwise failing Windows jobs are not erroring.
16 changes: 7 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
# Binaries for programs and plugins.
/bin
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
# Test binary, built with `go test -c`.
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
# Output of the go coverage tool, specifically when used with LiteIDE.
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
# Test artifacts
/limittest/memory

# Go workspace file
# Go workspace file.
go.work

# Ignore local configurations.
Expand Down
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"augustocdias.tasks-shell-input",
"golang.go",
"spadin.memento-inputs",
"Symflower.symflower"
]
}
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"gopls": {
// Disable analyzers that we are currently not interested in because they do not obey our conventions.
"analyses": {
"simplifycompositelit": false,
},
// Add parameter placeholders when completing a function.
"usePlaceholders": true,
},
"symflower.lint.onOpen": true,
"symflower.lint.onSave": true,
}
55 changes: 23 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,46 @@ export ARGS

ifdef ARGS
HAS_ARGS := "1"
PACKAGE := $(ARGS)
else
HAS_ARGS :=
PACKAGE := $(PACKAGE_BASE)/...
endif

all: install-dependencies install-tools install lint test-verbose
.PHONY: all
ifdef NO_UNIT_TEST_CACHE
export NO_UNIT_TEST_CACHE=-count=1
else
export NO_UNIT_TEST_CACHE=
endif

clean:
.DEFAULT_GOAL := help

clean: # Clean up artifacts of the development environment to allow for untainted builds, installations and updates.
go clean -i $(PACKAGE)
go clean -i -race $(PACKAGE)
.PHONY: clean

clean-coverage:
find $(ROOT_DIR) | grep .coverprofile | xargs rm
.PHONY: clean-coverage
editor: # Open our default IDE with the project's configuration.
@# WORKAROUND VS.code does not call Delve with absolute paths to files which it needs to set breakpoints. Until either Delve or VS.code have a fix we need to disable "-trimpath" which converts absolute to relative paths of Go builds which is a requirement for reproducible builds.
GOFLAGS="$(GOFLAGS) -trimpath=false" $(ROOT_DIR)/scripts/editor.sh
.PHONY: editor

help: # Show this help message.
@grep -E '^[a-zA-Z-][a-zA-Z0-9.-]*?:.*?# (.+)' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?# "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help

install:
go install -v $(PACKAGE)
.PHONY: install

install-dependencies:
go get -t -v $(PACKAGE)
go test -i -v $(PACKAGE)
.PHONY: install-dependencies

install-tools:
# Install linting tools
go get -u -v github.com/kisielk/errcheck/...
go get -u -v honnef.co/go/tools/cmd/megacheck

# Install code coverage tools
go get -u -v github.com/onsi/ginkgo/ginkgo/...
go get -u -v github.com/modocache/gover/...
go get -u -v github.com/mattn/goveralls/...
.PHONY: install-tools
install-all: install install-tools-linting install-tools-testing
.PHONY: install-all

lint:
$(ROOT_DIR)/scripts/lint.sh
go tool github.com/kisielk/errcheck ./...
go vet ./...
.PHONY: lint

test:
go test -race -test.timeout $(UNIT_TEST_TIMEOUT)s $(PACKAGE)
test: # [<Go package] - # Test everything, or only the specified package.
go tool gotest.tools/gotestsum --format standard-verbose --hide-summary skipped -- $(NO_UNIT_TEST_CACHE) -race -test.timeout $(UNIT_TEST_TIMEOUT)s -test.run='$(word 2,$(ARGS))' -v $(if $(ARGS), $(word 1,$(ARGS)), $(PACKAGE))
.PHONY: test

test-with-coverage:
ginkgo -r -cover -race -skipPackage="testdata" $(PACKAGE)
.PHONY: test-with-coverage

test-verbose:
go test -race -test.timeout $(UNIT_TEST_TIMEOUT)s -v $(PACKAGE)
.PHONY: test-verbose
18 changes: 14 additions & 4 deletions archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@ func ZipExtractFile(archiveFilePath string, destinationPath string) (err error)
if err != nil {
return err
}
defer archive.Close()
defer func() {
if e := archive.Close(); e != nil {
err = errors.Join(err, e)
}
}()

for _, f := range archive.File {
filePath := filepath.Join(destinationPath, f.Name)
Expand All @@ -235,7 +239,9 @@ func ZipExtractFile(archiveFilePath string, destinationPath string) (err error)
return
}
if f.FileInfo().IsDir() {
os.MkdirAll(filePath, os.ModePerm)
if err := os.MkdirAll(filePath, os.ModePerm); err != nil {
return err
}

continue
}
Expand All @@ -258,8 +264,12 @@ func ZipExtractFile(archiveFilePath string, destinationPath string) (err error)
return err
}

destinationFile.Close()
fileInArchive.Close()
if err := destinationFile.Close(); err != nil {
return err
}
if err := fileInArchive.Close(); err != nil {
return err
}
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func CacheObjectWrite(cachePath string, identifier string, cacheObjectType Cache
cacheObjectPathRelative := cacheObjectPath(identifier)
cacheObjectPath := filepath.Join(cachePath, cacheObjectPathRelative)

if os.MkdirAll(cacheObjectPath, 0755); err != nil {
if err := os.MkdirAll(cacheObjectPath, 0755); err != nil {
return err
}

Expand Down
25 changes: 17 additions & 8 deletions capture_test_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

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

func TestCapture(t *testing.T) {
Expand All @@ -25,16 +26,24 @@ func TestCaptureRecursive(t *testing.T) {
// Use at least one more file descriptor than our current limit, so we make sure that there are no file descriptor leaks.
for i := 0; i <= int(limit); i++ {
out, err := Capture(func() {
fmt.Fprintf(os.Stdout, "1")
fmt.Fprintf(os.Stderr, "2")
fmt.Fprintf(os.Stdout, "3")
fmt.Fprintf(os.Stderr, "4")
_, err := fmt.Fprintf(os.Stdout, "1")
require.NoError(t, err)
_, err = fmt.Fprintf(os.Stderr, "2")
require.NoError(t, err)
_, err = fmt.Fprintf(os.Stdout, "3")
require.NoError(t, err)
_, err = fmt.Fprintf(os.Stdout, "4")
require.NoError(t, err)

out, err := Capture(func() {
fmt.Fprintf(os.Stdout, "A")
fmt.Fprintf(os.Stderr, "B")
fmt.Fprintf(os.Stdout, "C")
fmt.Fprintf(os.Stderr, "D")
_, err := fmt.Fprintf(os.Stdout, "A")
require.NoError(t, err)
_, err = fmt.Fprintf(os.Stderr, "B")
require.NoError(t, err)
_, err = fmt.Fprintf(os.Stdout, "C")
require.NoError(t, err)
_, err = fmt.Fprintf(os.Stderr, "D")
require.NoError(t, err)

})
assert.NoError(t, err)
Expand Down
15 changes: 12 additions & 3 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,24 @@ func ContextWithInterrupt(ctx context.Context, logWriter io.Writer) (contextWith
for {
switch <-c {
case os.Interrupt, os.Kill:
io.WriteString(logWriter, "Received termination signal")
_, err := io.WriteString(logWriter, "Received termination signal")
if err != nil {
panic(err)
}
count++

if count == 1 {
io.WriteString(logWriter, "Canceling analysis and writing results")
_, err := io.WriteString(logWriter, "Canceling analysis and writing results")
if err != nil {
panic(err)
}

cancelContext()
} else {
io.WriteString(logWriter, "Exiting immediately")
_, err := io.WriteString(logWriter, "Exiting immediately")
if err != nil {
panic(err)
}

//revive:disable:deep-exit
os.Exit(1)
Expand Down
7 changes: 5 additions & 2 deletions env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

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

func TestIsEnvEnabled(t *testing.T) {
Expand All @@ -18,8 +19,10 @@ func TestIsEnvEnabled(t *testing.T) {

validate := func(t *testing.T, tc *testCase) {
t.Run(tc.Value, func(t *testing.T) {
os.Setenv(envTestName, tc.Value)
defer os.Unsetenv(envTestName)
require.NoError(t, os.Setenv(envTestName, tc.Value))
defer func() {
require.NoError(t, os.Unsetenv(envTestName))
}()

actual := IsEnvEnabled(envTestName, tc.EnabledValues...)

Expand Down
Loading
Loading