diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..9b67af1 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,27 @@ +# Golang CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-go/ for more details +version: 2 +jobs: + build: + docker: + # specify the version + - image: circleci/golang:1.17 + + # Specify service dependencies here if necessary + # CircleCI maintains a library of pre-built images + # documented at https://circleci.com/docs/2.0/circleci-images/ + # - image: circleci/postgres:9.4 + + #### TEMPLATE_NOTE: go expects specific checkout path representing url + #### expecting it in the form of + #### /go/src/github.com/circleci/go-tool + #### /go/src/bitbucket.org/circleci/go-tool + working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}} + steps: + - checkout + + # specify any bash command here prefixed with `run: ` + - run: go get -u golang.org/x/lint/golint && golint -set_exit_status + - run: go get -v -t -d ./... + #- run: go test -v ./... diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..8d1800f --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,67 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [master] + pull_request: + # The branches below must be a subset of the branches above + branches: [master] + schedule: + - cron: "44 23 * * 3" + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: ["go"] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/.gitignore b/.gitignore index 64a5435..6f05095 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ .vscode/* waybar-livestatus vendor/ +dist/ + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..e4b36bf --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,38 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + # you may remove this if you don't need go generate + - go generate ./... +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - amd64 + - arm64 +archives: + - replacements: + linux: Linux + amd64: x86_64 + arm64: aarch64 + +checksum: + name_template: "checksums.txt" +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + +signs: + - artifacts: all +# modelines, feel free to remove those if you don't want/use them: +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj diff --git a/Makefile b/Makefile index b2bd092..025722e 100644 --- a/Makefile +++ b/Makefile @@ -25,18 +25,13 @@ generate: .PHONY: build build: main.go - go build -trimpath -ldflags "-X github.com/cyrinux/waybar-livestatus/helpers.Version=$(VERSION) -linkmode=external" -o $(BIN) main.go + go build -o $(BIN) main.go .PHONY: debug debug: main.go - go build -gcflags='all=-N -l' -ldflags "-X github.com/cyrinux/waybar-livestatus/helpers.Version=$(VERSION) -linkmode=external" -o $(BIN) main.go + go build -o $(BIN) main.go dlv exec ./waybar-livestatus -.PHONY: release -release: build - strip $(BIN) 2>/dev/null || true - upx -9 $(BIN) 2>/dev/null || true - .PHONY: vendor vendor: go mod tidy @@ -109,3 +104,7 @@ graphviz: @dot -Tsvg ~/protodot/generated/alert.dot -o alert.dot.svg @rm -vf ~/protodot/generated/alert* @xdg-open alert.dot.png + +.PHONY: release +release: + goreleaser --rm-dist diff --git a/alert/alert.pb.go b/alert/alert.pb.go index 83f7432..7ec0492 100644 --- a/alert/alert.pb.go +++ b/alert/alert.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.26.0 -// protoc v3.21.2 +// protoc v3.21.12 // source: alert/alert.proto package alert diff --git a/helpers/config.go b/helpers/config.go index 0742703..93c11fa 100644 --- a/helpers/config.go +++ b/helpers/config.go @@ -15,9 +15,6 @@ import ( "github.com/rs/zerolog/log" ) -// Version give the software version -var Version string - // CONFIG define the configuration content type CONFIG struct { Server string `toml:"server" default:""` @@ -29,7 +26,6 @@ type CONFIG struct { Debug bool `toml:"debug" default:"false"` Popup bool `toml:"popup" default:"true"` Warnings bool `toml:"warnings" default:"true"` - Version bool `default:"false"` NotificationSnoozeCycle int `toml:"notification_snooze_cycle" default:"10"` Acknowledged int `toml:"acknowledged" default:"0"` NotificationsEnabled int `toml:"notifications_enabled" default:"1"` @@ -87,7 +83,6 @@ func GetConfig() *CONFIG { flag.BoolVar(&config.Client, "c", false, "Client mode.") flag.BoolVar(&config.NotesURL, "u", config.NotesURL, "Display notes_url.") flag.BoolVar(&config.Popup, "n", config.Popup, "Disable notification popup alert.") - flag.BoolVar(&config.Version, "V", false, "Print version and exit.") flag.BoolVar(&config.Warnings, "w", config.Warnings, "Get also state warnings. Default show critical only.") flag.IntVar(&config.Refresh, "r", config.Refresh, "Refresh rate in seconds. Min 15.") diff --git a/helpers/notification.go b/helpers/notification.go index 211b2b3..f44629b 100644 --- a/helpers/notification.go +++ b/helpers/notification.go @@ -2,11 +2,12 @@ package helpers import ( "fmt" + "os" + "strings" + notify "github.com/TheCreeper/go-notify" "github.com/rs/zerolog" "github.com/rs/zerolog/log" - "os" - "strings" ) // Alert define a event @@ -48,7 +49,7 @@ func SendNotification(notifications chan *Alert, config *CONFIG) { alertsWithCounter := make(map[Alert]int) if config.Debug { - startAlert := Alert{Host: "Livestatus", Desc: fmt.Sprintf("starting version %v", Version)} + startAlert := Alert{Host: "Livestatus", Desc: fmt.Sprint("starting")} if _, err := createNotification(&startAlert, ""); err != nil { log.Error().Msgf("Error sending notification: %v", err) } diff --git a/main.go b/main.go index 56a788e..9fc6086 100644 --- a/main.go +++ b/main.go @@ -89,11 +89,6 @@ func main() { // get config var config = helpers.GetConfig() - if config.Version { - fmt.Println("Waybar Livestatus version:", helpers.Version) - os.Exit(0) - } - // start the client and exit if config.Client { err := client.Start(config)