Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create base CI commands #1

Merged
merged 1 commit into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: CI
run: go build
11 changes: 5 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
vendor/
.idea/
.vscode/
.tools/
build/
53 changes: 53 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

run:
concurrency: 1
deadline: 2m
issues-exit-code: 1
tests: true
skip-files:
- easyjson

issues:
exclude-use-default: false

output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true

linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0.8
gofmt:
simplify: true
errcheck:
check-type-assertions: true
check-blank: true
gocyclo:
min-complexity: 30
misspell:
locale: US
gosimple:
go: "1.16"
checks: ["all"]
prealloc:
simple: true
range-loops: true
for-loops: false

linters:
disable-all: true
enable:
- govet
- gofmt
- errcheck
- misspell
- gocyclo
- ineffassign
- goimports
- gosimple
- prealloc
fast: false

6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# devtool
# devtool

[![Release](https://img.shields.io/github/release/dewep-online/devtool.svg?style=flat-square)](https://github.com/dewep-online/devtool/releases/latest)
[![Go Report Card](https://goreportcard.com/badge/github.com/dewep-online/devtool)](https://goreportcard.com/report/github.com/dewep-online/devtool)
[![CI](https://github.com/dewep-online/devtool/actions/workflows/ci.yml/badge.svg)](https://github.com/dewep-online/devtool/actions/workflows/ci.yml)
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module github.com/dewep-online/devtool

go 1.17

require github.com/deweppro/go-app v1.6.1

require github.com/deweppro/go-errors v0.0.4 // indirect
22 changes: 22 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deweppro/go-algorithms v1.2.0/go.mod h1:zYdfRdlpaXgdT36OgvdjH1qtTZFWEeBi3KUQmWltMPI=
github.com/deweppro/go-app v1.6.1 h1:NH7W/NDQmHLrFgXl9Zy3nGM91+w9q4vo9wfSfWHmAgg=
github.com/deweppro/go-app v1.6.1/go.mod h1:1oMjMJH9hxas3/Nl73O2E+E5mJoMheqrZ1fmQ6M46EE=
github.com/deweppro/go-chan-pool v1.1.2/go.mod h1:6meJsORhraeyvJNPy4hx8xgBNjp2xx3KGB/d5Q5a/I4=
github.com/deweppro/go-errors v0.0.4 h1:TW91LRqHAkUauDJ5lzz73LziANH7mjli1tyvtwzXRCM=
github.com/deweppro/go-errors v0.0.4/go.mod h1:BLsNcxaHh1fjNl/o1TB69JwA8XueSk/Nszkvw4ZwI/I=
github.com/deweppro/go-logger v1.3.0/go.mod h1:jxBBLyHmIvJ4erGUj5qeE6ir36ztyAL1pI+9GymOHVI=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
15 changes: 15 additions & 0 deletions init/devtool.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
After=network.target

[Service]
User=root
Group=root
Restart=on-failure
RestartSec=30s
Type=simple
ExecStart=/usr/bin/devtool --config=/etc/devtool/config.yaml
KillMode=process
KillSignal=SIGTERM

[Install]
WantedBy=default.target
53 changes: 53 additions & 0 deletions internal/build/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package build

import (
"strings"

"github.com/dewep-online/devtool/internal/global"
"github.com/dewep-online/devtool/pkg/exec"
"github.com/dewep-online/devtool/pkg/files"
"github.com/deweppro/go-app/console"
)

func Cmd() console.CommandGetter {
return console.NewCommand(func(setter console.CommandSetter) {
setter.Setup("build", "")
setter.Flag(func(flagsSetter console.FlagsSetter) {
flagsSetter.StringVar("arch", "amd64,arm64", "")
})
setter.ExecFunc(func(_ []string, arch string) {
console.Infof("setup tools")
buildDir := global.GetBuildDir()
global.SetupEnv()

cmds := []string{
"go mod tidy",
"go mod download",
"go generate ./...",
}

mainFiles, err := files.Detect("main.go")
console.FatalIfErr(err, "detect main.go")

for _, main := range mainFiles {
appName := files.Folder(main)
archList := strings.Split(arch, ",")

for _, arch = range archList {
cmds = append(cmds, "rm -rf "+buildDir+"/"+appName+"_"+arch)

switch arch {
case "arm64":
cmds = append(cmds, "GODEBUG=netdns=9 GO111MODULE=on CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc go build -a -o "+buildDir+"/"+appName+"_"+arch+" "+main)
case "amd64":
cmds = append(cmds, "GODEBUG=netdns=9 GO111MODULE=on CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o "+buildDir+"/"+appName+"_"+arch+" "+main)
default:
console.Fatalf("use only arch=[amd64,arm64]")
}
}
}

exec.CommandPack("bash", cmds...)
})
})
}
49 changes: 49 additions & 0 deletions internal/global/global.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package global

import (
"os"
exec2 "os/exec"
"regexp"

"github.com/dewep-online/devtool/pkg/files"
"github.com/deweppro/go-app/console"
)

const (
ToolsDir = ".tools"
BuildDir = "build"
InitDir = "init"
ScriptsDir = "scripts"
)

func GetToolsDir() string {
return files.CurrentDir() + "/" + ToolsDir
}

func GetBuildDir() string {
return files.CurrentDir() + "/" + BuildDir
}

func GetInitDir() string {
return files.CurrentDir() + "/" + InitDir
}

func GetScriptsDir() string {
return files.CurrentDir() + "/" + ScriptsDir
}

func SetupEnv() {
console.FatalIfErr(os.Setenv("GOBIN", GetToolsDir()), "setup env")
}

var rex = regexp.MustCompile(`go(\d+)\.(\d+)`)

func GoVersion() string {
b, err := exec2.Command("bash", "-c", "go version").CombinedOutput()
console.FatalIfErr(err, "detect go version")
result := rex.FindAllString(string(b), 1)
for _, s := range result {
return s
}
return "unknown"
}
34 changes: 34 additions & 0 deletions internal/lint/lint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package lint

import (
"github.com/dewep-online/devtool/internal/global"
"github.com/dewep-online/devtool/pkg/exec"
"github.com/dewep-online/devtool/pkg/files"
"github.com/deweppro/go-app/console"
)

func Cmd() console.CommandGetter {
return console.NewCommand(func(setter console.CommandSetter) {
setter.Setup("lint", "")
setter.ExecFunc(func(_ []string) {
console.Infof("setup tools")
toolsDir := global.GetToolsDir()
global.SetupEnv()

exec.CommandPack("bash",
"go mod tidy",
"go mod download",
"go generate ./...",
toolsDir+"/golangci-lint --version",
toolsDir+"/golangci-lint -v run ./...",
)

mainFiles, err := files.Detect("main.go")
console.FatalIfErr(err, "detect main.go")

for _, main := range mainFiles {
exec.CommandPack("bash", "go build -race -v -o /tmp/bin.test "+main)
}
})
})
}
Loading