Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate CI to GitHub Actions #81

Merged
merged 1 commit into from
Jul 29, 2021
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
18 changes: 18 additions & 0 deletions .github/workflows/linter.yaml
Original file line number Diff line number Diff line change
@@ -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
46 changes: 46 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
linters:
enable:
- dogsled
- dupl
- gofmt
- goimports
- misspell
- nakedret
- stylecheck
- unconvert
- unparam
- whitespace
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tmpl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestFetchTemplate(t *testing.T) {
}{
// custom template files
{
"non-existant template file",
"non-existent template file",
"",
"/does/not/exist",
spdxOff,
Expand All @@ -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
Expand Down