Skip to content

Commit

Permalink
chore: add goreleaser config
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrinux committed Dec 29, 2022
1 parent bb9a868 commit 3f0d3d5
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 21 deletions.
27 changes: 27 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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 ./...
67 changes: 67 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.vscode/*
waybar-livestatus
vendor/
dist/

dist/
38 changes: 38 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 6 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion alert/alert.pb.go

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

5 changes: 0 additions & 5 deletions helpers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:""`
Expand All @@ -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"`
Expand Down Expand Up @@ -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.")
Expand Down
7 changes: 4 additions & 3 deletions helpers/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 0 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3f0d3d5

Please sign in to comment.