Skip to content

Commit

Permalink
Merge pull request #2 from ymtdzzz/chore/ci_lint_and_test
Browse files Browse the repository at this point in the history
Add dependabot and CI to run test and lint
  • Loading branch information
ymtdzzz authored Mar 31, 2024
2 parents b3e1e39 + ed3edf7 commit 5b14d28
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 22 deletions.
18 changes: 18 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
time: "09:00"
timezone: "Asia/Tokyo"
reviewers:
- "ymtdzzz"
- package-ecosystem: "gomod"
directory: "/tuiexporter"
schedule:
interval: "weekly"
time: "09:00"
timezone: "Asia/Tokyo"
reviewers:
- "ymtdzzz"
50 changes: 50 additions & 0 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: lint-and-test

on: push

jobs:
lint:
name: Run lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: './go.mod'
- name: Run lint
run: make install-lint-tools lint
lint-exporter:
name: Run lint for exporter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: './go.mod'
- name: Run lint for exporter
run: make install-lint-tools lint-exporter

test:
name: Run test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: './go.mod'
- name: Run test
run: make test
test-exporter:
name: Run test for exporter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: './go.mod'
- name: Run test for exporter
run: make test-exporter
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
otel-tui
.DS_Store
cover.*
coverage.*
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.PHONY: help
help: ## Print help.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

install-lint-tools: ## Install lint tools
go install honnef.co/go/tools/cmd/staticcheck@latest
go install github.com/alexkohler/prealloc@latest
go install github.com/securego/gosec/v2/cmd/gosec@latest

DIR=./...
lint: ## Run static analysis
go vet "$(DIR)"
test -z "`gofmt -s -d .`"
staticcheck "$(DIR)"
prealloc -set_exit_status "$(DIR)"
gosec "$(DIR)"

lint-exporter: ## Run static analysis for exporter
$(MAKE) lint DIR="./tuiexporter/..."

.PHONY: test
test: ## run test ex.) make test OPT="-run TestXXX"
go test -v "$(DIR)" "$(OPT)"

test-exporter: ## run test for exporter
$(MAKE) test DIR="./tuiexporter/..."

test-coverage: ## Run test with coverage
$(MAKE) test OPT="-coverprofile=coverage.out"
go tool cover -html=coverage.out

test-coverage-exporter: ## Run test with coverage for exporter
$(MAKE) test-coverage DIR="./tuiexporter/..."
13 changes: 5 additions & 8 deletions components.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion main_windows.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tuiexporter/internal/telemetry/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestStoreAddSpanWithoutRotation(t *testing.T) {
// assert cache spanid2span
assert.Equal(t, 4, len(store.cache.spanid2span))
for _, span := range testdata.Spans {
got, _ := store.cache.spanid2span[span.SpanID().String()]
got := store.cache.spanid2span[span.SpanID().String()]
assert.Equal(t, span, got.Span)
}

Expand Down Expand Up @@ -206,7 +206,7 @@ func TestStoreAddSpanWithRotation(t *testing.T) {
assert.Equal(t, 1, len(store.cache.spanid2span))
{
want := testdata2.Spans[0]
got, _ := store.cache.spanid2span[want.SpanID().String()]
got := store.cache.spanid2span[want.SpanID().String()]
assert.Equal(t, want, got.Span)
}

Expand Down
2 changes: 0 additions & 2 deletions tuiexporter/internal/test/tracegen.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build test

package test

import (
Expand Down
2 changes: 1 addition & 1 deletion tuiexporter/internal/tui/component/timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func DrawTimeline(traceID string, cache *telemetry.TraceCache, setFocusFn func(p
totalRow = placeSpan(grid, n, totalRow, 0, &tvs, &nodes)
}

rows := make([]int, totalRow+2, totalRow+2)
rows := make([]int, totalRow+2)
for i := 0; i < totalRow+1; i++ {
rows[i] = 1
}
Expand Down
10 changes: 4 additions & 6 deletions tuiexporter/internal/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,10 @@ func (t *TUIApp) Stop() error {
func (t *TUIApp) refresh() {
tick := time.NewTicker(refreshInterval)
for {
select {
case <-tick.C:
if t.refreshedAt.Before(t.store.UpdatedAt()) {
t.app.Draw()
t.refreshedAt = time.Now()
}
<-tick.C
if t.refreshedAt.Before(t.store.UpdatedAt()) {
t.app.Draw()
t.refreshedAt = time.Now()
}
}
}

0 comments on commit 5b14d28

Please sign in to comment.