Skip to content

Commit

Permalink
Add github action for build and lint (#6)
Browse files Browse the repository at this point in the history
Signed-off-by: Pradeep Chhetri <[email protected]>
  • Loading branch information
chhetripradeep authored Jan 7, 2023
1 parent 7d3414c commit eeed098
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build, Test, Format and Lint

on:
push:
pull_request:

jobs:
build-binaries:
runs-on: ubuntu-latest
name: Build binary
steps:
- uses: actions/[email protected]

- uses: actions/setup-go@v2
with:
go-version: ^1.19

- name: Build binaries
run: make build

format-lint:
runs-on: ubuntu-latest
name: Format and lint
steps:
- uses: actions/[email protected]

- uses: actions/setup-go@v2
with:
go-version: ^1.19

- name: Install tools
run: make install-tools

- name: Format
run: make fmt && git diff --quiet

- name: Lint
run: make lint
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ build:
fmt:
go fmt ./...

.PHONY: lint
lint: install-tools
golangci-lint -v run --allow-parallel-runners ./...

.PHONY: install
install:
go install
goimports -w -local github.com/chhetripradeep/chtop ./

.PHONY: install-tools
install-tools:
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
7 changes: 5 additions & 2 deletions pkg/metric/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import (

func LoadMetrics(v *viper.Viper, first bool) (ClickHouseMetrics, error) {
metrics := DefaultClickHouseMetrics()
v.UnmarshalKey("clickhousemetrics", &metrics)
err := v.UnmarshalKey("clickhousemetrics", &metrics)
if err != nil {
panic("failed to unmarshal metrics section from configuration file")
}
if !first || metrics.File == "" {
return metrics, nil
}

v = viper.New()
v.SetConfigFile(metrics.File)
err := v.ReadInConfig()
err = v.ReadInConfig()
if err != nil {
return metrics, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ func (m Model) View() string {
asciigraph.SeriesColors(m.Theme.GraphColor()),
)

plot += fmt.Sprintf("\n\n")
plot += lipgloss.JoinVertical(
lipgloss.Top,
setTitle(m.ClickHouseMetrics.Metrics[i].Name).String(),
graph,
setFooter(fmt.Sprintf("Current Value: %.2f\n\n", m.ClickHouseMetrics.Metrics[i].Latest)).String(),
)
plot += "\n"
}
return plot
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/theme/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import (

func LoadTheme(v *viper.Viper, first bool) (*Theme, error) {
theme := DefaultTheme()
v.UnmarshalKey("theme", theme)
err := v.UnmarshalKey("theme", theme)
if err != nil {
panic("failed to unmarshal theme section from configuration file")
}
if !first || theme.File == "" {
return theme, nil
}

v = viper.New()
v.SetConfigFile(theme.File)
err := v.ReadInConfig()
err = v.ReadInConfig()
if err != nil {
return theme, err
}
Expand Down

0 comments on commit eeed098

Please sign in to comment.