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

Version 2.3.0 #51

Merged
merged 16 commits into from
Dec 1, 2023
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
55 changes: 35 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,61 @@ on:
branches: [master, develop]
pull_request:
branches: [master]
workflow_dispatch:
inputs:
force_run:
description: 'Force workflow run'
required: true
type: choice
options: [yes, no]

permissions:
actions: read
contents: read
statuses: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
Go:
name: Go
runs-on: ubuntu-latest

env:
SRC_DIR: src/github.com/${{ github.repository }}
GO111MODULE: auto

strategy:
matrix:
go: [ '1.16.x', '1.17.x', '1.18.x', '1.19.x' ]
go: [ '1.18.x', '1.19.x', '1.20.x', '1.21.x' ]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
id: go

- name: Setup PATH
run: |
echo "GOPATH=${{ github.workspace }}" >> "$GITHUB_ENV"
echo "GOBIN=${{ github.workspace }}/bin" >> "$GITHUB_ENV"
echo "${{ github.workspace }}/bin" >> "$GITHUB_PATH"

- name: Checkout
uses: actions/checkout@v3
with:
path: ${{env.SRC_DIR}}

- name: Download dependencies
working-directory: ${{env.SRC_DIR}}
run: make deps

- name: Build binary
working-directory: ${{env.SRC_DIR}}
run: make all

- name: Run tests
working-directory: ${{env.SRC_DIR}}
run: bash .scripts/script.sh

Typos:
name: Typos
runs-on: ubuntu-latest

needs: Go

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Check spelling
continue-on-error: true
uses: crate-ci/typos@master
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 2

Expand Down
2 changes: 2 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[files]
extend-exclude = ["go.sum"]
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################

# This Makefile generated by GoMakeGen 2.2.0 using next command:
# This Makefile generated by GoMakeGen 2.3.0 using next command:
# gomakegen --mod --strip .
#
# More info: https://kaos.sh/gomakegen
Expand All @@ -13,6 +13,7 @@ ifdef VERBOSE ## Print verbose information (Flag)
VERBOSE_FLAG = -v
endif

COMPAT ?= 1.18
MAKEDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
GITREV ?= $(shell test -s $(MAKEDIR)/.git && git rev-parse --short HEAD)

Expand Down Expand Up @@ -50,7 +51,7 @@ else
endif

ifdef COMPAT ## Compatible Go version (String)
go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT)
go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) -go=$(COMPAT)
else
go mod tidy $(VERBOSE_FLAG)
endif
Expand Down Expand Up @@ -94,6 +95,6 @@ help: ## Show this info
| sed 's/ifdef //' \
| awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-14s\033[0m %s\n", $$1, $$2}'
@echo -e ''
@echo -e '\033[90mGenerated by GoMakeGen 2.2.0\033[0m\n'
@echo -e '\033[90mGenerated by GoMakeGen 2.3.0\033[0m\n'

################################################################################
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

### Installation

To build the `gomakegen` from scratch, make sure you have a working Go 1.16+ workspace (_[instructions](https://golang.org/doc/install)_), then:
To build the `gomakegen` from scratch, make sure you have a working Go 1.18+ workspace (_[instructions](https://go.dev/doc/install)_), then:

```
go install github.com/essentialkaos/gomakegen@latest
Expand Down Expand Up @@ -60,7 +60,7 @@ gomakegen --generate-man | sudo gzip > /usr/share/man/man1/gomakegen.1.gz
### Usage

```
Usage: gomakegen {options} dir
Usage: gomakegen {options} source-dir

Options

Expand Down
20 changes: 12 additions & 8 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import (
// App info
const (
APP = "GoMakeGen"
VER = "2.2.0"
VER = "2.3.0"
DESC = "Utility for generating makefiles for Go applications"
)

Expand Down Expand Up @@ -152,7 +152,7 @@ func Init(gitRev string, gomod []byte) {
showAbout(gitRev)
return
case options.GetB(OPT_VERB_VER):
support.ShowSupportInfo(APP, VER, gitRev, gomod)
support.Print(APP, VER, gitRev, gomod)
return
case options.GetB(OPT_HELP) || len(args) == 0:
showUsage()
Expand Down Expand Up @@ -217,9 +217,9 @@ func filterSources(sources []string) []string {
func exportMakefile(makefile *Makefile) {
switch {
case makefile.DepUsed:
fmtc.Println("{r}▲ Warning! Dep is deprecated and must not be used for new projects.{!}\n")
fmtc.Println("{r}▲ Warning! Dep is deprecated and should not be used for new projects.{!}\n")
case makefile.GlideUsed:
fmtc.Println("{r}▲ Warning! Glide is deprecated and must not be used for new projects.{!}\n")
fmtc.Println("{r}▲ Warning! Glide is deprecated and should not be used for new projects.{!}\n")
}

err := ioutil.WriteFile(options.GetS(OPT_OUTPUT), makefile.Render(), 0644)
Expand Down Expand Up @@ -1056,7 +1056,7 @@ func (m *Makefile) getModTarget() string {
result += "\tgo mod init\n"
result += "endif\n\n"
result += "ifdef COMPAT ## Compatible Go version (String)\n"
result += "\tgo mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT)\n"
result += "\tgo mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) -go=$(COMPAT)\n"
result += "else\n"
result += "\tgo mod tidy $(VERBOSE_FLAG)\n"
result += "endif\n\n"
Expand Down Expand Up @@ -1157,6 +1157,10 @@ func (m *Makefile) getDefaultVariables() string {
result += "VERBOSE_FLAG = -v\n"
result += "endif\n\n"

if m.ModUsed {
result += "COMPAT ?= 1.18\n"
}

result += "MAKEDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))\n"
result += "GITREV ?= $(shell test -s $(MAKEDIR)/.git && git rev-parse --short HEAD)\n\n"

Expand Down Expand Up @@ -1195,8 +1199,8 @@ func getGoVersion() version.Version {
return ver
}

// getOptionName parse option name in options package notation
// and retunr long option name
// getOptionName parses option name in options package notation
// and returns long option name
func getOptionName(opt string) string {
longOpt, _ := options.ParseOptionName(opt)
return longOpt
Expand Down Expand Up @@ -1263,7 +1267,7 @@ func genMan() int {

// genUsage generates usage info
func genUsage() *usage.Info {
info := usage.NewInfo("", "dir")
info := usage.NewInfo("", "source-dir")

info.AddOption(OPT_GLIDE, "Add target to fetching dependencies with glide")
info.AddOption(OPT_DEP, "Add target to fetching dependencies with dep")
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/essentialkaos/gomakegen
go 1.19

require (
github.com/essentialkaos/depsy v1.0.0
github.com/essentialkaos/ek/v12 v12.57.1
github.com/essentialkaos/depsy v1.1.0
github.com/essentialkaos/ek/v12 v12.90.0
)

require golang.org/x/sys v0.4.0 // indirect
require golang.org/x/sys v0.15.0 // indirect
18 changes: 9 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
github.com/essentialkaos/check v1.3.0 h1:ria+8o22RCLdt2D/1SHQsEH5Mmy5S+iWHaGHrrbPUc0=
github.com/essentialkaos/depsy v1.0.0 h1:FikBtTnNhk+xFO/hFr+CfiKs6QnA3wMD6tGL0XTEUkc=
github.com/essentialkaos/depsy v1.0.0/go.mod h1:XVsB2eVUonEzmLKQP3ig2P6v2+WcHVgJ10zm0JLqFMM=
github.com/essentialkaos/ek/v12 v12.57.1 h1:9dj32HLCVmseBoa43F6HaZz1qbKts5GNBCtFdrpQPno=
github.com/essentialkaos/ek/v12 v12.57.1/go.mod h1:G8ghiSKh8ToJQCdB2bAhE3CnI6dn9nTJdWH3bQIVr1U=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk=
github.com/essentialkaos/depsy v1.1.0 h1:U6dp687UkQwXlZU17Hg2KMxbp3nfZAoZ8duaeUFYvJI=
github.com/essentialkaos/depsy v1.1.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8=
github.com/essentialkaos/ek/v12 v12.90.0 h1:Y7WaRbrFY4JKPRYpjWbCOfVHWJPx8TZcIla8dXFJ2dI=
github.com/essentialkaos/ek/v12 v12.90.0/go.mod h1:NSx0QzX8Fplo21PbGNBkmL1j5pyWVKErTgJeSB1kpdA=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
85 changes: 37 additions & 48 deletions support/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"os/exec"
"runtime"
"runtime/debug"
"strings"

"github.com/essentialkaos/ek/v12/fmtc"
Expand All @@ -24,20 +25,9 @@ import (

// ////////////////////////////////////////////////////////////////////////////////// //

// Pkg contains basic package info
type Pkg struct {
Name string
Version string
}

// Pkgs is slice with packages
type Pkgs []Pkg

// ////////////////////////////////////////////////////////////////////////////////// //

// ShowSupportInfo prints verbose info about application, system, dependencies and
// Print prints verbose info about application, system, dependencies and
// important environment
func ShowSupportInfo(app, ver, gitRev string, gomod []byte) {
func Print(app, ver, gitRev string, gomod []byte) {
fmtutil.SeparatorTitleColorTag = "{s-}"
fmtutil.SeparatorFullscreen = false
fmtutil.SeparatorColorTag = "{s-}"
Expand Down Expand Up @@ -66,6 +56,10 @@ func showApplicationInfo(app, ver, gitRev string) {
runtime.GOOS, runtime.GOARCH,
))

if gitRev == "" {
gitRev = extractGitRevFromBuildInfo()
}

if gitRev != "" {
if !fmtc.DisableColors && fmtc.IsTrueColorSupported() {
printInfo(7, "Git SHA", gitRev+getHashColorBullet(gitRev))
Expand All @@ -87,6 +81,25 @@ func showApplicationInfo(app, ver, gitRev string) {
}
}

// showEnvInfo shows info about environment
func showEnvInfo() {
fmtutil.Separator(false, "ENVIRONMENT")

cmd := exec.Command("go", "version")
out, err := cmd.Output()

if err != nil {
printInfo(2, "Go", "")
return
}

goVer := string(out)
goVer = strutil.ReadField(goVer, 2, false, " ")
goVer = strutil.Exclude(goVer, "go")

printInfo(2, "Go", goVer)
}

// showDepsInfo shows information about all dependencies
func showDepsInfo(gomod []byte) {
deps := depsy.Extract(gomod, false)
Expand All @@ -106,32 +119,21 @@ func showDepsInfo(gomod []byte) {
}
}

// showEnvInfo shows info about environment
func showEnvInfo() {
fmtutil.Separator(false, "ENVIRONMENT")
// extractGitRevFromBuildInfo extracts git SHA from embedded build info
func extractGitRevFromBuildInfo() string {
info, ok := debug.ReadBuildInfo()

cmd := exec.Command("go", "version")
out, err := cmd.Output()

if err != nil {
printInfo(2, "Go", "")
return
if !ok {
return ""
}

rawInfo := strutil.Exclude(string(out), "\n")
goVer := strutil.ReadField(rawInfo, 2, false, " ")
goVer = strutil.Exclude(goVer, "go")
goArch := strutil.ReadField(rawInfo, 3, false, " ")

if goVer == "" || goArch == "" {
printInfo(2, "Go", "")
return
for _, s := range info.Settings {
if s.Key == "vcs.revision" && len(s.Value) > 7 {
return s.Value[:7]
}
}

printInfo(
2, "Go",
fmtc.Sprintf("%s {s}(%s){!}", goVer, goArch),
)
return ""
}

// getHashColorBullet return bullet with color from hash
Expand All @@ -145,7 +147,7 @@ func getHashColorBullet(v string) string {

// printInfo formats and prints info record
func printInfo(size int, name, value string) {
name = name + ":"
name += ":"
size++

if value == "" {
Expand All @@ -158,16 +160,3 @@ func printInfo(size int, name, value string) {
}

// ////////////////////////////////////////////////////////////////////////////////// //

// getMaxSize returns max package name size
func (p Pkgs) getMaxSize() int {
size := 0

for _, pkg := range p {
if len(pkg.Name) > size {
size = len(pkg.Name)
}
}

return size
}
Loading