Skip to content

Commit

Permalink
Move to GH actions (grafana-tools#129)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
GiedriusS authored Jul 9, 2021
1 parent db1192e commit de841e5
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 184 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Go

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
lint:
strategy:
matrix:
go: [1.16, 1.15, 1.14]

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

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

- uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run linters
uses: golangci/golangci-lint-action@v2
with:
version: v1.41

test:
strategy:
matrix:
go: [1.16, 1.15, 1.14]
grafana: [6.7.1, 6.6.2, 6.5.3, 6.4.5]

env:
GRAFANA_INTEGRATION: 1

services:
grafana:
# Docker Hub image
image: "grafana/grafana:${{ matrix.grafana }}"
ports:
- 3000:3000
options: >-
-e GF_AUTH_ANONYMOUS_ENABLED=true
chromedp:
image: "chromedp/headless-shell:91.0.4472.69"
ports:
- 9222:9222
options: >-
--shm-size 2G
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

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

- uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
# Calculate coverage with the newest Go version.
- name: Calc coverage
if: "${{ matrix.go == '1.16' && matrix.grafana == '6.7.1' }}"
run: |
go test -v -covermode=atomic -coverprofile=coverage.out ./...
- name: Test
if: "${{ matrix.go != '1.16' && matrix.grafana != '6.7.1' }}"
run: go test -v ./...
- name: Convert coverage.out to coverage.lcov
if: "${{ matrix.go == '1.16' && matrix.grafana == '6.7.1' }}"
uses: jandelgado/[email protected]
- name: Coveralls
if: "${{ matrix.go == '1.16' && matrix.grafana == '6.7.1' }}"
uses: coverallsapp/[email protected]
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: coverage.lcov
12 changes: 9 additions & 3 deletions board_visual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package sdk_test
import (
"context"
"fmt"
"log"
"testing"
"time"

"github.com/chromedp/chromedp"
"github.com/grafana-tools/sdk"
Expand Down Expand Up @@ -32,6 +32,8 @@ import (
// Smoke tests for Grafana's singlestat panel.
// Adds a new dashboard with example data via the API and checks if something is there.
func TestSinglestatPanel(t *testing.T) {
shouldSkip(t)

/* These are just defaults values Grafana uses that I have tested */
b := sdk.NewBoard("exampleboard")
b.Time.From = "now-5m"
Expand Down Expand Up @@ -74,12 +76,16 @@ func TestSinglestatPanel(t *testing.T) {
durl := getDebugURL(t)

t.Logf("Got Chrome's URL: %s", durl)
actxt, cancelActxt := chromedp.NewRemoteAllocator(context.Background(), durl)
timeoutCtx, cancelTimeoutCtx := context.WithTimeout(context.Background(), 10*time.Second)
defer cancelTimeoutCtx()

actxt, cancelActxt := chromedp.NewRemoteAllocator(timeoutCtx, durl)
defer cancelActxt()

ctx, cancel := chromedp.NewContext(
actxt,
chromedp.WithLogf(log.Printf),
chromedp.WithLogf(t.Logf),
chromedp.WithDebugf(t.Logf),
)
defer cancel()

Expand Down
6 changes: 5 additions & 1 deletion cmd/backup-dashboards/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ func main() {
os.Exit(0)
}
ctx := context.Background()
c := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
c, err := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create a client: %s\n", err)
os.Exit(1)
}
if boardLinks, err = c.SearchDashboards(ctx, "", false); err != nil {
fmt.Fprint(os.Stderr, err)
os.Exit(1)
Expand Down
6 changes: 5 additions & 1 deletion cmd/backup-datasources/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ func main() {
os.Exit(0)
}
ctx := context.Background()
c := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
c, err := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create a client: %s\n", err)
os.Exit(1)
}
if datasources, err = c.GetAllDatasources(ctx); err != nil {
fmt.Fprint(os.Stderr, err)
os.Exit(1)
Expand Down
6 changes: 5 additions & 1 deletion cmd/import-dashboards-raw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ func main() {
os.Exit(0)
}
ctx := context.Background()
c := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
c, err := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create a client: %s\n", err)
os.Exit(1)
}
filesInDir, err = ioutil.ReadDir(".")
if err != nil {
log.Fatal(err)
Expand Down
6 changes: 5 additions & 1 deletion cmd/import-dashboards/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ func main() {
os.Exit(0)
}
ctx := context.Background()
c := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
c, err := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create a client: %s\n", err)
os.Exit(1)
}
filesInDir, err = ioutil.ReadDir(".")
if err != nil {
log.Fatal(err)
Expand Down
6 changes: 5 additions & 1 deletion cmd/import-datasources/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ func main() {
os.Exit(0)
}
ctx := context.Background()
c := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
c, err := sdk.NewClient(os.Args[1], os.Args[2], sdk.DefaultHTTPClient)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create a client: %s\n", err)
os.Exit(1)
}
if datasources, err = c.GetAllDatasources(ctx); err != nil {
fmt.Fprint(os.Stderr, err)
os.Exit(1)
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ module github.com/grafana-tools/sdk
go 1.13

require (
github.com/chromedp/cdproto v0.0.0-20210122124816-7a656c010d57
github.com/chromedp/chromedp v0.6.5
github.com/chromedp/cdproto v0.0.0-20210706234513-2bc298e8be7f
github.com/chromedp/chromedp v0.7.3
github.com/gosimple/slug v1.1.1
github.com/pkg/errors v0.9.1
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
)
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
github.com/chromedp/cdproto v0.0.0-20210122124816-7a656c010d57 h1:htpyTFarq7OHx9SpkQ+7x20thTQA6JAsgnuMGoPbH4E=
github.com/chromedp/cdproto v0.0.0-20210122124816-7a656c010d57/go.mod h1:55pim6Ht4LJKdVLlyFJV/g++HsEA1hQxPbB5JyNdZC0=
github.com/chromedp/cdproto v0.0.0-20210526005521-9e51b9051fd0/go.mod h1:At5TxYYdxkbQL0TSefRjhLE3Q0lgvqKKMSFUglJ7i1U=
github.com/chromedp/cdproto v0.0.0-20210706234513-2bc298e8be7f h1:lg5k1KAxmknil6Z19LaaeiEs5Pje7hPzRfyWSSnWLP0=
github.com/chromedp/cdproto v0.0.0-20210706234513-2bc298e8be7f/go.mod h1:At5TxYYdxkbQL0TSefRjhLE3Q0lgvqKKMSFUglJ7i1U=
github.com/chromedp/chromedp v0.6.5 h1:hPaDYBpvD2WFicln0ByzV+XRhSOtLgAgsu39O455iWY=
github.com/chromedp/chromedp v0.6.5/go.mod h1:/Q6h52DkrFuvOgmCuR6O3xT5g0bZYoPqjANKBEvQGEY=
github.com/chromedp/chromedp v0.7.3 h1:FvgJICfjvXtDX+miuMUY0NHuY8zQvjS/TcEQEG6Ldzs=
github.com/chromedp/chromedp v0.7.3/go.mod h1:9gC521Yzgrk078Ulv6KIgG7hJ2x9aWrxMBBobTFk30A=
github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic=
github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww=
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
Expand All @@ -10,14 +15,22 @@ github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.0.4 h1:5eXU1CZhpQdq5kXbKb+sECH5Ia5KiO6CYzIzdlVx6Bs=
github.com/gobwas/ws v1.0.4/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
github.com/gobwas/ws v1.1.0-rc.5 h1:QOAag7FoBaBYYHRqzqkhhd8fq5RTubvI4v3Ft/gDVVQ=
github.com/gobwas/ws v1.1.0-rc.5/go.mod h1:nzvNcVha5eUziGrbxFCo6qFIojQHjJV5cLYIbezhfL0=
github.com/gosimple/slug v1.1.1 h1:fRu/digW+NMwBIP+RmviTK97Ho/bEj/C9swrCspN3D4=
github.com/gosimple/slug v1.1.1/go.mod h1:ER78kgg1Mv0NQGlXiDe57DpCyfbNywXXZ9mIorhxAf0=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be h1:ta7tUOvsPHVHGom5hKW5VXNc2xZIkfCKP8iaqOyYtUQ=
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be/go.mod h1:MIDFMn7db1kT65GmV94GzpX9Qdi7N/pQlwb+AN8wh+Q=
golang.org/x/sys v0.0.0-20201207223542-d4d67f95c62d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210122093101-04d7465088b8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Loading

0 comments on commit de841e5

Please sign in to comment.