Skip to content

Commit de841e5

Browse files
authored
Move to GH actions (#129)
* Move to GH actions Move from Travis CI to GitHub actions because TravisCI is kind of laggy & only free up to some small amount of CI minutes. * github/go: migrate more stuff * github/go: add missing keyword * github/go: add env var * github/go: add chromedp * Remove unused file, add shouldSkip * github/go: add separate jobs * .github: add coveralls * *: fix after sdk.NewClient() changes * rest: dashboard: set board IDs to different values * actions: only calc coverage on newest Grafana * actions: specify ./... * .github: use atomic mode * go: update chromedp * gh actions: try fix * *: add more prints * github/go: quote val * github: try another way * github: run tests once
1 parent db1192e commit de841e5

File tree

15 files changed

+157
-184
lines changed

15 files changed

+157
-184
lines changed

.github/workflows/go.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
lint:
11+
strategy:
12+
matrix:
13+
go: [1.16, 1.15, 1.14]
14+
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v2
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: ${{ matrix.go }}
23+
24+
- uses: actions/cache@v2
25+
with:
26+
path: |
27+
~/go/pkg/mod
28+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
29+
restore-keys: |
30+
${{ runner.os }}-go-
31+
32+
- name: Run linters
33+
uses: golangci/golangci-lint-action@v2
34+
with:
35+
version: v1.41
36+
37+
test:
38+
strategy:
39+
matrix:
40+
go: [1.16, 1.15, 1.14]
41+
grafana: [6.7.1, 6.6.2, 6.5.3, 6.4.5]
42+
43+
env:
44+
GRAFANA_INTEGRATION: 1
45+
46+
services:
47+
grafana:
48+
# Docker Hub image
49+
image: "grafana/grafana:${{ matrix.grafana }}"
50+
ports:
51+
- 3000:3000
52+
options: >-
53+
-e GF_AUTH_ANONYMOUS_ENABLED=true
54+
chromedp:
55+
image: "chromedp/headless-shell:91.0.4472.69"
56+
ports:
57+
- 9222:9222
58+
options: >-
59+
--shm-size 2G
60+
61+
runs-on: ubuntu-latest
62+
steps:
63+
- uses: actions/checkout@v2
64+
65+
- name: Set up Go
66+
uses: actions/setup-go@v2
67+
with:
68+
go-version: ${{ matrix.go }}
69+
70+
- uses: actions/cache@v2
71+
with:
72+
path: |
73+
~/go/pkg/mod
74+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
75+
restore-keys: |
76+
${{ runner.os }}-go-
77+
78+
# Calculate coverage with the newest Go version.
79+
- name: Calc coverage
80+
if: "${{ matrix.go == '1.16' && matrix.grafana == '6.7.1' }}"
81+
run: |
82+
go test -v -covermode=atomic -coverprofile=coverage.out ./...
83+
- name: Test
84+
if: "${{ matrix.go != '1.16' && matrix.grafana != '6.7.1' }}"
85+
run: go test -v ./...
86+
- name: Convert coverage.out to coverage.lcov
87+
if: "${{ matrix.go == '1.16' && matrix.grafana == '6.7.1' }}"
88+
uses: jandelgado/[email protected]
89+
- name: Coveralls
90+
if: "${{ matrix.go == '1.16' && matrix.grafana == '6.7.1' }}"
91+
uses: coverallsapp/[email protected]
92+
with:
93+
github-token: ${{ secrets.github_token }}
94+
path-to-lcov: coverage.lcov

board_visual_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package sdk_test
33
import (
44
"context"
55
"fmt"
6-
"log"
76
"testing"
7+
"time"
88

99
"github.com/chromedp/chromedp"
1010
"github.com/grafana-tools/sdk"
@@ -32,6 +32,8 @@ import (
3232
// Smoke tests for Grafana's singlestat panel.
3333
// Adds a new dashboard with example data via the API and checks if something is there.
3434
func TestSinglestatPanel(t *testing.T) {
35+
shouldSkip(t)
36+
3537
/* These are just defaults values Grafana uses that I have tested */
3638
b := sdk.NewBoard("exampleboard")
3739
b.Time.From = "now-5m"
@@ -74,12 +76,16 @@ func TestSinglestatPanel(t *testing.T) {
7476
durl := getDebugURL(t)
7577

7678
t.Logf("Got Chrome's URL: %s", durl)
77-
actxt, cancelActxt := chromedp.NewRemoteAllocator(context.Background(), durl)
79+
timeoutCtx, cancelTimeoutCtx := context.WithTimeout(context.Background(), 10*time.Second)
80+
defer cancelTimeoutCtx()
81+
82+
actxt, cancelActxt := chromedp.NewRemoteAllocator(timeoutCtx, durl)
7883
defer cancelActxt()
7984

8085
ctx, cancel := chromedp.NewContext(
8186
actxt,
82-
chromedp.WithLogf(log.Printf),
87+
chromedp.WithLogf(t.Logf),
88+
chromedp.WithDebugf(t.Logf),
8389
)
8490
defer cancel()
8591

cmd/backup-dashboards/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ func main() {
4646
os.Exit(0)
4747
}
4848
ctx := context.Background()
49-
c := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
49+
c, err := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
50+
if err != nil {
51+
fmt.Fprintf(os.Stderr, "Failed to create a client: %s\n", err)
52+
os.Exit(1)
53+
}
5054
if boardLinks, err = c.SearchDashboards(ctx, "", false); err != nil {
5155
fmt.Fprint(os.Stderr, err)
5256
os.Exit(1)

cmd/backup-datasources/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ func main() {
4848
os.Exit(0)
4949
}
5050
ctx := context.Background()
51-
c := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
51+
c, err := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
52+
if err != nil {
53+
fmt.Fprintf(os.Stderr, "Failed to create a client: %s\n", err)
54+
os.Exit(1)
55+
}
5256
if datasources, err = c.GetAllDatasources(ctx); err != nil {
5357
fmt.Fprint(os.Stderr, err)
5458
os.Exit(1)

cmd/import-dashboards-raw/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ func main() {
5252
os.Exit(0)
5353
}
5454
ctx := context.Background()
55-
c := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
55+
c, err := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
56+
if err != nil {
57+
fmt.Fprintf(os.Stderr, "Failed to create a client: %s\n", err)
58+
os.Exit(1)
59+
}
5660
filesInDir, err = ioutil.ReadDir(".")
5761
if err != nil {
5862
log.Fatal(err)

cmd/import-dashboards/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ func main() {
5151
os.Exit(0)
5252
}
5353
ctx := context.Background()
54-
c := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
54+
c, err := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
55+
if err != nil {
56+
fmt.Fprintf(os.Stderr, "Failed to create a client: %s\n", err)
57+
os.Exit(1)
58+
}
5559
filesInDir, err = ioutil.ReadDir(".")
5660
if err != nil {
5761
log.Fatal(err)

cmd/import-datasources/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ func main() {
5252
os.Exit(0)
5353
}
5454
ctx := context.Background()
55-
c := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
55+
c, err := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
56+
if err != nil {
57+
fmt.Fprintf(os.Stderr, "Failed to create a client: %s\n", err)
58+
os.Exit(1)
59+
}
5660
if datasources, err = c.GetAllDatasources(ctx); err != nil {
5761
fmt.Fprint(os.Stderr, err)
5862
os.Exit(1)

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ module github.com/grafana-tools/sdk
33
go 1.13
44

55
require (
6-
github.com/chromedp/cdproto v0.0.0-20210122124816-7a656c010d57
7-
github.com/chromedp/chromedp v0.6.5
6+
github.com/chromedp/cdproto v0.0.0-20210706234513-2bc298e8be7f
7+
github.com/chromedp/chromedp v0.7.3
88
github.com/gosimple/slug v1.1.1
99
github.com/pkg/errors v0.9.1
1010
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be // indirect
11+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
1112
)

go.sum

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
github.com/chromedp/cdproto v0.0.0-20210122124816-7a656c010d57 h1:htpyTFarq7OHx9SpkQ+7x20thTQA6JAsgnuMGoPbH4E=
22
github.com/chromedp/cdproto v0.0.0-20210122124816-7a656c010d57/go.mod h1:55pim6Ht4LJKdVLlyFJV/g++HsEA1hQxPbB5JyNdZC0=
3+
github.com/chromedp/cdproto v0.0.0-20210526005521-9e51b9051fd0/go.mod h1:At5TxYYdxkbQL0TSefRjhLE3Q0lgvqKKMSFUglJ7i1U=
4+
github.com/chromedp/cdproto v0.0.0-20210706234513-2bc298e8be7f h1:lg5k1KAxmknil6Z19LaaeiEs5Pje7hPzRfyWSSnWLP0=
5+
github.com/chromedp/cdproto v0.0.0-20210706234513-2bc298e8be7f/go.mod h1:At5TxYYdxkbQL0TSefRjhLE3Q0lgvqKKMSFUglJ7i1U=
36
github.com/chromedp/chromedp v0.6.5 h1:hPaDYBpvD2WFicln0ByzV+XRhSOtLgAgsu39O455iWY=
47
github.com/chromedp/chromedp v0.6.5/go.mod h1:/Q6h52DkrFuvOgmCuR6O3xT5g0bZYoPqjANKBEvQGEY=
8+
github.com/chromedp/chromedp v0.7.3 h1:FvgJICfjvXtDX+miuMUY0NHuY8zQvjS/TcEQEG6Ldzs=
9+
github.com/chromedp/chromedp v0.7.3/go.mod h1:9gC521Yzgrk078Ulv6KIgG7hJ2x9aWrxMBBobTFk30A=
510
github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic=
611
github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww=
712
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
@@ -10,14 +15,22 @@ github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
1015
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
1116
github.com/gobwas/ws v1.0.4 h1:5eXU1CZhpQdq5kXbKb+sECH5Ia5KiO6CYzIzdlVx6Bs=
1217
github.com/gobwas/ws v1.0.4/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
18+
github.com/gobwas/ws v1.1.0-rc.5 h1:QOAag7FoBaBYYHRqzqkhhd8fq5RTubvI4v3Ft/gDVVQ=
19+
github.com/gobwas/ws v1.1.0-rc.5/go.mod h1:nzvNcVha5eUziGrbxFCo6qFIojQHjJV5cLYIbezhfL0=
1320
github.com/gosimple/slug v1.1.1 h1:fRu/digW+NMwBIP+RmviTK97Ho/bEj/C9swrCspN3D4=
1421
github.com/gosimple/slug v1.1.1/go.mod h1:ER78kgg1Mv0NQGlXiDe57DpCyfbNywXXZ9mIorhxAf0=
1522
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
1623
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
1724
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
1825
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
26+
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
27+
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
1928
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
2029
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
2130
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be h1:ta7tUOvsPHVHGom5hKW5VXNc2xZIkfCKP8iaqOyYtUQ=
2231
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be/go.mod h1:MIDFMn7db1kT65GmV94GzpX9Qdi7N/pQlwb+AN8wh+Q=
32+
golang.org/x/sys v0.0.0-20201207223542-d4d67f95c62d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
2333
golang.org/x/sys v0.0.0-20210122093101-04d7465088b8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
34+
golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
35+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
36+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

0 commit comments

Comments
 (0)