Skip to content

Commit

Permalink
Init project
Browse files Browse the repository at this point in the history
  • Loading branch information
olblak committed May 6, 2023
1 parent dd4157f commit df13493
Show file tree
Hide file tree
Showing 19 changed files with 2,871 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@

# Go workspace file
go.work

bin/
122 changes: 122 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
linters-settings:
depguard:
list-type: blacklist
packages:
- github.com/alecthomas/assert
- github.com/magiconair/properties/assert
packages-with-error-message:
- github.com/alecthomas/assert: "use github.com/stretchr/testify/assert"
- github.com/magiconair/properties/assert: "use github.com/stretchr/testify/assert"
dupl:
threshold: 100
exhaustive:
default-signifies-exhaustive: false
funlen:
lines: 200
statements: 150
goconst:
min-len: 3
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
gocyclo:
min-complexity: 15
golint:
min-confidence: 0
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: [argument,case,condition,return]
govet:
check-shadowing: true
fieldalignment:
settings:
printf:
funcs:
- (github.com/jenkins-x/jx-logging/pkg/log/Logger()).Debugf
- (github.com/jenkins-x/jx-logging/pkg/log/Logger()).Infof
- (github.com/jenkins-x/jx-logging/pkg/log/Logger()).Warnf
- (github.com/jenkins-x/jx-logging/pkg/log/Logger()).Errorf
- (github.com/jenkins-x/jx-logging/pkg/log/Logger()).Fatalf
lll:
line-length: 140
maligned:
suggest-new: true
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- asciicheck
- depguard
- dogsled
- errcheck
- funlen
# - gocognit
- goconst
# - gocyclo
# - godot
- gofmt
- goimports
# - golint
- goprintffuncname
- gosec
- gosimple
- ineffassign
# - interfacer # deprecated since 1.38.0
# - lll
# - maligned # deprecated since 1.38.0
- misspell
- nakedret
- nolintlint
# Disabled until fixed for go1.18 - https://github.com/golangci/golangci-lint/issues/2649
# - rowserrcheck
# Disabled until fixed for go1.18 - https://github.com/golangci/golangci-lint/issues/2649
#- structcheck
# - stylecheck
- typecheck
- unconvert
- unparam
- unused
# - whitespace
issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd
- funlen
- path: _expansion_test\.go
linters:
- testpackage
# https://github.com/go-critic/go-critic/issues/926
- linters:
- gocritic
text: "unnecessaryDefer:"
run:
timeout: 5m
skip-dirs:
- test/testdata_etc
- internal/cache
- internal/renameio
- internal/robustio
66 changes: 66 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
GOVERSION=$(shell go version)
export GOVERSION

DOCKER_BUILDKIT=1
export DOCKER_BUILDKIT

UDASH_DB_URI=postgres://udash:password@localhost:5432/udash?sslmode=disable
export UDASH_DB_URI

local_bin=./dist/updatecli_$(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH)/updatecli

.PHONY: app.build
app.build: ## Build application localy
go build -o bin/udash \
-ldflags='-w -s -X "github.com/updatecli/udash/pkg/version.BuildTime=$(shell date)" -X "github.com/updatecli/udash/pkg/version.GoVersion=$(shell go version)" -X "github.com/updatecli/udash/pkg/version.Version=42"'

server.start: app.build ## Start application localy
./bin/udash server start --debug

.PHONY: build
build: ## Build updatecli as a "dirty snapshot" (no tag, no release, but all OS/arch combinations)
goreleaser build --snapshot --rm-dist

.PHONY: build.all
build.all: ## Build updatecli for "release" (tag or release and all OS/arch combinations)
goreleaser --rm-dist --skip-publish

clean: ## Clean go test cache
go clean -testcache

.PHONY: release ## Create a new updatecli release including packages
release: ## release.snapshot generate a snapshot release but do not published it (no tag, but all OS/arch combinations)
goreleaser --rm-dist

.PHONY: release.snapshot ## Create a new snapshot release without publishing assets
release.snapshot: ## release.snapshot generate a snapshot release but do not published it (no tag, but all OS/arch combinations)
goreleaser --snapshot --rm-dist --skip-publish

.PHONY: db
db.reset: db.delete db.start ## Reset development database

.PHONY: db.connect
db.connect: ## Connect to development database
docker exec -i -t udash-db-1 psql --username=udash --password udash

.PHONY: db.start
db.start: ## Start development database
docker compose up -d db

.PHONY: db.delete
db.delete: ## Delete development database
docker compose down db -v

.PHONY: help
help: ## Show this Makefile's help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'


.PHONY: Run application linting tests
lint: ## Execute the Golang's linters on updatecli's source code
golangci-lint run

.PHONY: Run application tests
test: ## Execute the Golang's tests for updatecli
go test ./... -race -coverprofile=coverage.txt -covermode=atomic

95 changes: 95 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package cmd

import (
"os"

"github.com/fsnotify/fsnotify"
"github.com/olblak/udash/pkg/engine"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var (
// Server configuration file
cfgFile string

// Verbose allows to enable/disable debug logging
verbose bool
rootCmd = &cobra.Command{
Use: "udash",
Short: "udash is another Update monitoring platform",
PostRun: func(cmd *cobra.Command, args []string) {
logrus.Infoln("See you next time")
},
}
)

// Execute executes the root command.
func Execute() {
if err := rootCmd.Execute(); err != nil {
logrus.Errorf("%s", err)
os.Exit(1)
}
}

func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "set config file")
rootCmd.PersistentFlags().BoolVarP(&verbose, "debug", "", false, "set log level")

rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
if verbose {
logrus.SetLevel(logrus.DebugLevel)
}
}

rootCmd.AddCommand(
versionCmd,
serverCmd,
)
}

func initConfig() {

viper.SetConfigName("config") // name of config file (without extension)
if cfgFile != "" {
viper.SetConfigName(cfgFile)
}

viper.SetConfigType("yaml") // REQUIRED if the config file does not have the extension in the name
viper.AddConfigPath("/etc/udash/") // path to look for the config file in
viper.AddConfigPath("$HOME/.udash") // call multiple times to add many search paths
viper.AddConfigPath(".") // optionally look for config in the working directory
// Find and read the config file
if err := viper.ReadInConfig(); err != nil {
logrus.Errorln(err)
}

viper.OnConfigChange(func(e fsnotify.Event) {
logrus.Infof("Config file changed:", e.Name)
})
viper.WatchConfig()

}

func run(command string) error {

var o engine.Options

if err := viper.Unmarshal(&o); err != nil {
return err
}

e := engine.Engine{
Options: o,
}

switch command {
case "start":
e.Start()
default:
logrus.Warnf("Wrong command %q", command)
}
return nil
}
33 changes: 33 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cmd

import (
"os"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var (
serverCmd = &cobra.Command{
Use: "server",
Short: "The Udash server",
}

serverStartCmd = &cobra.Command{
Use: "start",
Short: "starts an Udash server",
Run: func(cmd *cobra.Command, args []string) {
err := run("start")
if err != nil {
logrus.Errorf("command failed")
os.Exit(1)
}
},
}
)

func init() {
serverCmd.AddCommand(
serverStartCmd,
)
}
24 changes: 24 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"strings"

"github.com/sirupsen/logrus"

"github.com/spf13/cobra"

"github.com/olblak/udash/pkg/version"
)

var (
// Version Contains application version
versionCmd = &cobra.Command{
Use: "version",
Short: "Print current application version",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
logrus.Infof("\n%s\n", strings.ToTitle("Version"))
version.Show()
},
}
)
27 changes: 27 additions & 0 deletions data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"date": "Fri, 05 May 2023 07:21:42 +0200",
"report": {
"name": "Pipeline Example",
"sources": {
"updatecli": {
"name": "Get latest Updatecli version",
"result": "",
"information": "v0.49.2",
"description": "GitHub release version \"v0.49.2\" found matching pattern \"latest\" of kind \"latest\""
}
},
"targets": {
"githubAction": {
"name": "[bug-report] Update updatecli version to \"v0.49.2\"",
"result": "",
"oldInformation": "v0.49.2",
"newInformation": "v0.49.2",
"description": "all contents from 'file' and 'files' combined already up to date",
"files": [
".github/workflows/updatecli.yaml"
],
"changed": false
}
}
}
}
1 change: 1 addition & 0 deletions db/migrations/000001_create_pipelines_tables.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS pipelines;
10 changes: 10 additions & 0 deletions db/migrations/000001_create_pipelines_tables.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BEGIN;
CREATE TABLE IF NOT EXISTS pipelines(
id SERIAL PRIMARY KEY,
data JSON NOT NULL,
created_at TIMESTAMP,
updated_at TIMESTAMP
);
ALTER TABLE pipelines ALTER COLUMN created_at SET DEFAULT now();
ALTER TABLE pipelines ALTER COLUMN updated_at SET DEFAULT now();
COMMIT;
Loading

0 comments on commit df13493

Please sign in to comment.