From 792e7a34625bca7218e53187973608974b11ce0f Mon Sep 17 00:00:00 2001 From: Will Norris Date: Tue, 27 Jul 2021 12:23:29 -0700 Subject: [PATCH] migrate CI to GitHub Actions use codecov.io to report on code coverage. fix a few issues raised by golangci-lint --- .github/workflows/linter.yaml | 18 ++++++++++++++ .github/workflows/tests.yaml | 46 +++++++++++++++++++++++++++++++++++ .golangci.yaml | 12 +++++++++ .travis.yml | 13 ---------- main.go | 8 +++--- tmpl.go | 2 +- tmpl_test.go | 4 +-- 7 files changed, 84 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/linter.yaml create mode 100644 .github/workflows/tests.yaml create mode 100644 .golangci.yaml delete mode 100644 .travis.yml diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml new file mode 100644 index 0000000..1f87c86 --- /dev/null +++ b/.github/workflows/linter.yaml @@ -0,0 +1,18 @@ +on: [push, pull_request] +name: linter + +jobs: + lint: + strategy: + matrix: + go-version: [1.x] + platform: [ubuntu-latest] + runs-on: ${{ matrix.platform }} + + steps: + - uses: actions/checkout@v2 + + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.41 diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..84f4818 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,46 @@ +on: [push, pull_request] +name: tests + +jobs: + test: + strategy: + matrix: + go-version: [1.x, 1.15.x] + platform: [ubuntu-latest] + include: + # only update test coverage stats with the most recent go version on linux + - go-version: 1.x + platform: ubuntu-latest + update-coverage: true + runs-on: ${{ matrix.platform }} + + permissions: + # styfle/cancel-workflow-action needs to be able to cancel existing action workflows + actions: write + + steps: + - name: Cancel previous + uses: styfle/cancel-workflow-action@89f242ee29e10c53a841bfe71cc0ce7b2f065abc #0.9.0 + with: + access_token: ${{ github.token }} + + - uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - uses: actions/checkout@v2 + + - name: Cache go modules + uses: actions/cache@v2 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go- + + - name: Run go test + run: go test -v -race -coverprofile coverage.txt -covermode atomic ./... + + - name: Upload coverage to Codecov + if: ${{ matrix.update-coverage }} + uses: codecov/codecov-action@v2 diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..1526bd3 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,12 @@ +linters: + enable: + - dogsled + - dupl + - gofmt + - goimports + - misspell + - nakedret + - stylecheck + - unconvert + - unparam + - whitespace diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 606f878..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -dist: bionic -git: - depth: 3 -language: go -go: - - 1.13.x -before_script: - - go get golang.org/x/lint/golint -script: - - go mod tidy - - gofmt -d -e -l -s . - - golint -set_exit_status ./... - - go test -v ./... diff --git a/main.go b/main.go index 10be4ec..67e1304 100644 --- a/main.go +++ b/main.go @@ -178,7 +178,9 @@ func main() { }() for _, d := range flag.Args() { - walk(ch, d) + if err := walk(ch, d); err != nil { + log.Fatal(err) + } } close(ch) <-done @@ -189,8 +191,8 @@ type file struct { mode os.FileMode } -func walk(ch chan<- *file, start string) { - filepath.Walk(start, func(path string, fi os.FileInfo, err error) error { +func walk(ch chan<- *file, start string) error { + return filepath.Walk(start, func(path string, fi os.FileInfo, err error) error { if err != nil { log.Printf("%s error: %v", path, err) return nil diff --git a/tmpl.go b/tmpl.go index e12bcc8..d60ca96 100644 --- a/tmpl.go +++ b/tmpl.go @@ -68,7 +68,7 @@ func fetchTemplate(license string, templateFile string, spdx spdxFlag) (string, // unknown license, but SPDX headers requested t = tmplSPDX } else { - return "", fmt.Errorf("unknown license: %q. Include the '-s' flag to request SPDX style headers using this license.", license) + return "", fmt.Errorf("unknown license: %q. Include the '-s' flag to request SPDX style headers using this license", license) } } else if spdx == spdxOn { // append spdx headers to recognized license diff --git a/tmpl_test.go b/tmpl_test.go index 4ed972c..0d9830a 100644 --- a/tmpl_test.go +++ b/tmpl_test.go @@ -40,7 +40,7 @@ func TestFetchTemplate(t *testing.T) { }{ // custom template files { - "non-existant template file", + "non-existent template file", "", "/does/not/exist", spdxOff, @@ -62,7 +62,7 @@ func TestFetchTemplate(t *testing.T) { "", spdxOff, "", - errors.New(`unknown license: "unknown". Include the '-s' flag to request SPDX style headers using this license.`), + errors.New(`unknown license: "unknown". Include the '-s' flag to request SPDX style headers using this license`), }, // pre-defined license templates, no SPDX