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 to GitHub Actions #132

Merged
merged 4 commits into from
Jun 15, 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
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 }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please set secrets for GitHub Actions.
https://docs.github.com/en/actions/reference/encrypted-secrets
https://docs.github.com/en/rest/reference/actions#secrets

It needs collaborator access to do it.


- 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 @@ -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)
}
}
Comment on lines +23 to +29
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this because secrets are not passed to the runner when a workflow is triggered from a forked repository.
See https://docs.github.com/en/actions/reference/encrypted-secrets#using-encrypted-secrets-in-a-workflow

client, err := NewGitHubClient(TestOwner, TestRepo, token, defaultBaseURL)
if err != nil {
t.Fatal("NewGitHubClient failed:", err)
Expand Down