Skip to content

Commit

Permalink
Merge pull request #132 from shogo82148/migrate-to-github-actions
Browse files Browse the repository at this point in the history
Migrate to GitHub Actions
  • Loading branch information
Songmu authored Jun 15, 2021
2 parents 9ccb9be + 5638db0 commit 250d333
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 3 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.*
!.gitignore
!.github/
!.travis.yml
ghr
.envrc
*.test
pkg
/cover.out
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
)

func TestRun(t *testing.T) {
client := testGithubClient(t)

t.Parallel()

outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
Expand All @@ -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())
Expand Down Expand Up @@ -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}

Expand All @@ -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())
Expand Down
7 changes: 7 additions & 0 deletions github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ func TestMain(m *testing.M) {

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)
Expand Down

0 comments on commit 250d333

Please sign in to comment.