diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..fbf67c3 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,56 @@ +name: Test +on: + push: + pull_request: + +jobs: + test: + name: Test + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - macos-latest + - windows-latest + go: + - "1.x" + + steps: + - name: Set up Go ${{ matrix.go }} + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: restore cache + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Test + run: make cover + env: + GITHUB_TOKEN: ${{ secrets.GHTOOLS_GITHUB_TOKEN }} + + - name: Send coverage + uses: shogo82148/actions-goveralls@v1 + with: + path-to-profile: cover.out + parallel: true + flag-name: OS-${{ matrix.os }}-Go-${{ matrix.go }} + + # notifies that all test jobs are finished. + finish: + needs: test + runs-on: ubuntu-latest + steps: + - uses: shogo82148/actions-goveralls@v1 + with: + parallel-finished: true diff --git a/.gitignore b/.gitignore index e8bbcf4..9bdfa5a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ .* !.gitignore +!.github/ !.travis.yml ghr .envrc *.test pkg +/cover.out diff --git a/Makefile b/Makefile index 9b72095..a21e8f6 100644 --- a/Makefile +++ b/Makefile @@ -79,7 +79,6 @@ lint: devel-deps cover: go test -coverprofile=cover.out go tool cover -html cover.out - rm cover.out .PHONY: release release: bump crossbuild upload diff --git a/cli_test.go b/cli_test.go index 21266cd..7adb55d 100644 --- a/cli_test.go +++ b/cli_test.go @@ -10,6 +10,8 @@ import ( ) func TestRun(t *testing.T) { + client := testGithubClient(t) + t.Parallel() outStream, errStream := new(bytes.Buffer), new(bytes.Buffer) @@ -24,7 +26,6 @@ func TestRun(t *testing.T) { t.Fatalf("%q exits %d, want %d\n\n%s", command, got, want, errStream.String()) } - client := testGithubClient(t) release, err := client.GetRelease(context.TODO(), tag) if err != nil { t.Fatalf("GetRelease failed: %s\n\n%s", err, outStream.String()) @@ -59,6 +60,8 @@ func TestRun(t *testing.T) { } func TestRun_recreate(t *testing.T) { + client := testGithubClient(t) + outStream, errStream := new(bytes.Buffer), new(bytes.Buffer) cli := &CLI{outStream: outStream, errStream: errStream} @@ -82,7 +85,6 @@ func TestRun_recreate(t *testing.T) { t.Fatalf("%q exits %d, want %d\n\n%s", command, got, want, errStream.String()) } - client := testGithubClient(t) release, err := client.GetRelease(context.TODO(), tag) if err != nil { t.Fatalf("GetRelease failed: %s\n\n%s", err, outStream.String()) diff --git a/github_test.go b/github_test.go index 9405735..5719221 100644 --- a/github_test.go +++ b/github_test.go @@ -20,6 +20,13 @@ const ( func testGithubClient(t *testing.T) GitHub { token := os.Getenv(EnvGitHubToken) + if token == "" { + if os.Getenv("CI") != "" { + t.Skipf("The %s environment value is not configured. skip it.", EnvGitHubToken) + } else { + t.Fatalf("The %s environment value is not configured. To skip it, set CI=true", EnvGitHubToken) + } + } client, err := NewGitHubClient(TestOwner, TestRepo, token, defaultBaseURL) if err != nil { t.Fatal("NewGitHubClient failed:", err)