Skip to content

Commit

Permalink
chore: use GitHub Actions.
Browse files Browse the repository at this point in the history
- use GitHub Actions instead of TravisCI
- updates golangci-lint to v1.36.0 and applies my rules
  • Loading branch information
ldez authored Feb 1, 2021
1 parent d73111c commit ccb8072
Show file tree
Hide file tree
Showing 14 changed files with 256 additions and 77 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/go-cross.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Build Cross OS

on:
push:
branches:
- master
pull_request:

jobs:

cross:
name: Go
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: ${{ github.workspace }}/go/src/github.com/traefik/yaegi

strategy:
matrix:
go-version: [ 1.14, 1.15 ]
os: [ubuntu-latest, macos-latest, windows-latest]

include:
- os: ubuntu-latest
go-path-suffix: /go
- os: macos-latest
go-path-suffix: /go
- os: windows-latest
go-path-suffix: \go

steps:
# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

# https://github.com/marketplace/actions/checkout
- name: Checkout code
uses: actions/checkout@v2
with:
path: go/src/github.com/traefik/yaegi

# https://github.com/marketplace/actions/cache
- name: Cache Go modules
uses: actions/cache@v2
with:
path: |
~/go/pkg/mod # Module download cache
~/.cache/go-build # Build cache (Linux)
~/Library/Caches/go-build # Build cache (Mac)
'%LocalAppData%\go-build' # Build cache (Windows)
key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-${{ matrix.go-version }}-go-
- name: Setup GOPATH
run: go env -w GOPATH=${{ github.workspace }}${{ matrix.go-path-suffix }}

# TODO fail on windows
# - name: Tests
# run: go test -v -cover ./...
# env:
# GOPATH: ${{ github.workspace }}${{ matrix.go-path }}

- name: Build
run: go build -race -v -ldflags "-s -w" -trimpath
110 changes: 110 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Main

on:
push:
branches:
- master
pull_request:

env:
GO_VERSION: 1.15
GOLANGCI_LINT_VERSION: v1.36.0

jobs:

linting:
name: Linting
runs-on: ubuntu-latest
steps:
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Check and get dependencies
run: |
go mod tidy
git diff --exit-code go.mod
# git diff --exit-code go.sum
go mod download
- name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}

- name: Run golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}
run: make check

generate:
name: Checks code and generated code
runs-on: ubuntu-latest
needs: linting
strategy:
matrix:
go-version: [ 1.14, 1.15 ]
steps:
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Check generated code
run: |
rm -f interp/op.go
make generate
git update-index -q --refresh
CHANGED=$(git diff-index --name-only HEAD --)
test -z "$CHANGED" || echo $CHANGED
test -z "$CHANGED"
main:
name: Build and Test
runs-on: ubuntu-latest
needs: linting
defaults:
run:
working-directory: ${{ github.workspace }}/go/src/github.com/traefik/yaegi
strategy:
matrix:
go-version: [ 1.14, 1.15 ]

steps:
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Check out code
uses: actions/checkout@v2
with:
path: go/src/github.com/traefik/yaegi
fetch-depth: 0

# https://github.com/marketplace/actions/cache
- name: Cache Go modules
uses: actions/cache@v2
with:
path: ./_test/tmp
key: ${{ runner.os }}-yaegi-${{ hashFiles('**//_test/tmp/') }}
restore-keys: |
${{ runner.os }}-yaegi-
- name: Setup GOPATH
run: go env -w GOPATH=${{ github.workspace }}/go

- name: Build
run: go build -v ./...

- name: Run tests
run: make tests
env:
GOPATH: ${{ github.workspace }}/go
42 changes: 42 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Release

on:
push:
tags:
- v[0-9]+.[0-9]+*

env:
GO_VERSION: 1.15

jobs:

release:
name: Create a release
runs-on: ubuntu-latest

steps:
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Cache Go modules
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_REPO }}
12 changes: 11 additions & 1 deletion .golangci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,23 @@
"gochecknoinits",
"gochecknoglobals",
"wsl",
"nlreturn",
"godox",
"funlen",
"gocognit",
"stylecheck",
"gomnd",
"testpackage",
"paralleltest",
"tparallel",
"goerr113",
"wrapcheck",
"nestif",
"exhaustive",
"nlreturn",
"exhaustivestruct",
"forbidigo",
"ifshort",
"errorlint", # TODO: must be reactivate before fixes
]

[issues]
Expand All @@ -61,3 +68,6 @@
[[issues.exclude-rules]]
path = "interp/interp.go"
text = "`out` can be `io.Writer`"
[[issues.exclude-rules]]
path = "interp/interp_eval_test.go"
linters = ["thelper"]
60 changes: 0 additions & 60 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions cmd/yaegi/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func genLicense(fname string) (string, error) {

f, err := os.Open(fname)
if err != nil {
return "", fmt.Errorf("could not open LICENSE file: %v", err)
return "", fmt.Errorf("could not open LICENSE file: %w", err)
}
defer func() { _ = f.Close() }()

Expand All @@ -116,7 +116,7 @@ func genLicense(fname string) (string, error) {
license.WriteString("//" + txt + "\n")
}
if sc.Err() != nil {
return "", fmt.Errorf("could not scan LICENSE file: %v", err)
return "", fmt.Errorf("could not scan LICENSE file: %w", err)
}

return license.String(), nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/yaegi/yaegi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func TestYaegiCmdCancel(t *testing.T) {

yaegi := filepath.Join(tmp, "yaegi")
build := exec.Command("go", "build", "-race", "-o", yaegi, ".")
err = build.Run()
out, err := build.CombinedOutput()
if err != nil {
t.Fatalf("failed to build yaegi command: %v", err)
t.Fatalf("failed to build yaegi command: %v: %s", err, out)
}

// Test src must be terminated by a single newline.
Expand Down
8 changes: 5 additions & 3 deletions example/pkg/pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestPackages(t *testing.T) {
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
goPath, err := filepath.Abs(test.goPath)
goPath, err := filepath.Abs(filepath.FromSlash(test.goPath))
if err != nil {
t.Fatal(err)
}
Expand All @@ -115,7 +115,7 @@ func TestPackages(t *testing.T) {

var msg string
if test.evalFile != "" {
if _, err := i.EvalPath(test.evalFile); err != nil {
if _, err := i.EvalPath(filepath.FromSlash(test.evalFile)); err != nil {
fatalStderrf(t, "%v", err)
}
msg = stdout.String()
Expand Down Expand Up @@ -146,6 +146,8 @@ func TestPackages(t *testing.T) {
}

func fatalStderrf(t *testing.T, format string, args ...interface{}) {
t.Helper()

fmt.Fprintf(os.Stderr, format+"\n", args...)
t.FailNow()
}
Expand All @@ -159,7 +161,7 @@ func TestPackagesError(t *testing.T) {
{
desc: "different packages in the same directory",
goPath: "./_pkg9/",
expected: "1:21: import \"github.com/foo/pkg\" error: found packages pkg and pkgfalse in _pkg9/src/github.com/foo/pkg",
expected: `1:21: import "github.com/foo/pkg" error: found packages pkg and pkgfalse in ` + filepath.FromSlash("_pkg9/src/github.com/foo/pkg"),
},
}

Expand Down
Loading

0 comments on commit ccb8072

Please sign in to comment.