From 8257259018e28eccac8498fe3c85c50ff7853b61 Mon Sep 17 00:00:00 2001 From: Frederic CORDIER Date: Fri, 23 May 2025 09:01:56 +0200 Subject: [PATCH 1/3] feat: initialize cli --- .devcontainer/devcontainer.json | 22 ++++++++ .github/workflows/main.yaml | 26 +++++++++ .github/workflows/release-please.yml | 19 +++++++ .github/workflows/release.yml | 46 ++++++++++++++++ .golangci.yml | 79 ++++++++++++++++++++++++++++ .release-please-manifest.json | 1 + Makefile | 36 +++++++++++++ cmd/root.go | 20 +++++++ cmd/version/version.go | 21 ++++++++ go.mod | 10 ++++ go.sum | 10 ++++ main.go | 9 ++++ release-please-config.json | 28 ++++++++++ 13 files changed, 327 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .github/workflows/main.yaml create mode 100644 .github/workflows/release-please.yml create mode 100644 .github/workflows/release.yml create mode 100644 .golangci.yml create mode 100644 .release-please-manifest.json create mode 100644 Makefile create mode 100644 cmd/root.go create mode 100644 cmd/version/version.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 release-please-config.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..5ccf081 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,22 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/go +{ + "name": "Go 1.24", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/go:1-1.24-bullseye", + + "mounts": [ + "type=bind,source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,readonly" + ], + + "settings": { + "workbench.colorCustomizations": { + "statusBar.background": "#ff4088", + "statusBar.foreground": "#ffffff" + } + }, + "features": { + "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {} + } + +} diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..c052ddb --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,26 @@ +name: Go Test + +on: [pull_request] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + go-version: [ '1.24' ] + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + - name: Install dependencies + run: go get . + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.62.2 + - name: Run unit-tests + run: go test -v ./... + \ No newline at end of file diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 0000000..025e11d --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,19 @@ +on: + push: + branches: + - main + +permissions: + contents: write + pull-requests: write + +name: release-please + +jobs: + release-please: + runs-on: ubuntu-latest + steps: + - uses: googleapis/release-please-action@v4 + with: + token: ${{ secrets.RELEASE_TOKEN }} + release-type: go \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..dbe6646 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,46 @@ +name: release + +on: + push: + tags: + - "*" + +permissions: + contents: write + +env: + GO_VERSION: "1.24" + +jobs: + manual-release: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Perform cross builds + run: make cross + + - name: Compress binaries + run: | + cd out + tar czf web3datacli_${GITHUB_REF#refs/tags/}_darwin_amd64.tar.gz web3datacli_${GITHUB_REF#refs/tags/}_darwin_amd64/ + tar czf web3datacli_${GITHUB_REF#refs/tags/}_linux_amd64.tar.gz web3datacli_${GITHUB_REF#refs/tags/}_linux_amd64/ + + - name: Get git tag + run: echo "tag=$(git describe --tags --exact-match HEAD)" >> $GITHUB_ENV + + - name: Publish binaries + uses: svenstaro/upload-release-action@04733e069f2d7f7f0b4aebc4fbdbce8613b03ccd # 2.9.0 + with: + repo_token: ${{ secrets.RELEASE_TOKEN }} + tag: ${{ env.tag }} + release_name: ${{ env.tag }} + file_glob: true + file: out/*.tar.gz + overwrite: true \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..2c32334 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,79 @@ +version: "2" +run: + issues-exit-code: 1 +linters: + default: none + enable: + - bodyclose + - copyloopvar + - dogsled + - dupl + - errcheck + - exhaustive + - goconst + - gocyclo + - gosec + - govet + - ineffassign + - misspell + - mnd + - nakedret + - nolintlint + - prealloc + - predeclared + - staticcheck + - thelper + - tparallel + - unconvert + - unparam + - whitespace + - wsl + settings: + errcheck: + check-type-assertions: true + exhaustive: + default-signifies-exhaustive: true + goconst: + min-len: 2 + min-occurrences: 3 + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + govet: + enable-all: true + nolintlint: + require-explanation: true + require-specific: true + staticcheck: + checks: + - ST1000 + - ST1001 + wsl: + allow-assign-and-call: true + allow-assign-and-anything: true + allow-cuddle-declarations: true + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..484cfe6 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1 @@ +{ ".": "1.0.0" } diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e1ebae3 --- /dev/null +++ b/Makefile @@ -0,0 +1,36 @@ +.DEFAULT_GOAL := help + +BIN_NAME := web3datacli +BUILD_DIR := ./out + +GIT_SHA := $(shell git rev-parse HEAD | cut -c 1-8) +GIT_TAG := $(shell git describe --tags) +DATE := $(shell date +%s) +VERSION_FLAGS=\ + -X github.com/thewhitewizard/web3data-cli/cmd/version.Version=$(GIT_TAG) \ + -X github.com/thewhitewizard/web3data-cli/cmd/version.Commit=$(GIT_SHA) \ + -X github.com/thewhitewizard/web3data-cli/cmd/version.Date=$(DATE) \ + -X github.com/thewhitewizard/web3data-cli/cmd/version.BuiltBy=makefile + +.PHONY: help +help: ## Display this help. + @awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + +##@ Build + +.PHONY: $(BUILD_DIR) +$(BUILD_DIR): ## Create the build folder. + mkdir -p $(BUILD_DIR) + +.PHONY: build +build: $(BUILD_DIR) ## Build go binary. + go build -ldflags "$(VERSION_FLAGS)" -o $(BUILD_DIR)/$(BIN_NAME) main.go + +.PHONY: cross +cross: $(BUILD_DIR) ## Cross-compile go binaries without using CGO. + GOOS=linux GOARCH=amd64 go build -o $(BUILD_DIR)/$(BIN_NAME)_$(GIT_TAG)_linux_amd64 main.go + GOOS=darwin GOARCH=amd64 go build -o $(BUILD_DIR)/$(BIN_NAME)_$(GIT_TAG)_darwin_amd64 main.go + +.PHONY: clean +clean: ## Clean the binary folder. + $(RM) -r $(BUILD_DIR) diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..fff2811 --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,20 @@ +package cmd + +import ( + "github.com/thewhitewizard/web3data-cli/cmd/version" + + "github.com/spf13/cobra" +) + +var rootCmd = &cobra.Command{ + Use: "web3datacli", + Long: `A CLI tool to manage web3data`, +} + +func Execute() { + cobra.CheckErr(rootCmd.Execute()) +} + +func init() { + rootCmd.AddCommand(version.VersionCmd) +} diff --git a/cmd/version/version.go b/cmd/version/version.go new file mode 100644 index 0000000..13dbaae --- /dev/null +++ b/cmd/version/version.go @@ -0,0 +1,21 @@ +package version + +import ( + "github.com/spf13/cobra" +) + +var ( + Version = "dev" + Commit = "none" + Date = "unknown" + BuiltBy = "unknown" +) + +var VersionCmd = &cobra.Command{ + Use: "version", + Short: "Get the current version of this application", + Long: `Nothing fancy. Print the version of this application`, + Run: func(cmd *cobra.Command, args []string) { + cmd.Printf("web3datacli Version %s\n", Version) + }, +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f188909 --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module github.com/thewhitewizard/web3data-cli + +go 1.24.2 + +require github.com/spf13/cobra v1.9.1 + +require ( + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/spf13/pflag v1.0.6 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..ffae55e --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= +github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0= +github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= +github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go new file mode 100644 index 0000000..8315a54 --- /dev/null +++ b/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "github.com/thewhitewizard/web3data-cli/cmd" +) + +func main() { + cmd.Execute() +} diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..837998e --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,28 @@ +{ + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "changelog-sections": [ + { "type": "feat", "section": "๐Ÿš€ Features", "hidden": false }, + { "type": "change", "section": "๐Ÿš€ Features", "hidden": false }, + { "type": "deprecate", "section": "โš ๏ธ Changes", "hidden": false }, + { "type": "remove", "section": "โš ๏ธ Changes", "hidden": false }, + { "type": "fix", "section": "๐Ÿž Bug Fixes", "hidden": false }, + { "type": "revert", "section": "๐Ÿž Bug Fixes", "hidden": false }, + { "type": "security", "section": "๐Ÿž Bug Fixes", "hidden": false }, + { "type": "perf", "section": "โœจ Polish", "hidden": false }, + { "type": "refactor", "section": "โœจ Polish", "hidden": false }, + { "type": "style", "section": "โœจ Polish", "hidden": false }, + { "type": "build", "section": "๐Ÿงฐ Other", "hidden": false }, + { "type": "chore", "section": "๐Ÿงฐ Other", "hidden": false }, + { "type": "deps", "section": "๐Ÿงฐ Other", "hidden": true }, + { "type": "ci", "section": "๐Ÿงฐ Other", "hidden": true }, + { "type": "test", "section": "๐Ÿงช Tests", "hidden": false }, + { "type": "docs", "section": "๐Ÿ“š Documentation", "hidden": true } + ], + "packages": { + ".": { + "include-component-in-tag": false, + "release-type": "go", + "changelog-path": "CHANGELOG.md" + } + } +} From a224a6829aa3fa6b2dadb87e49a6a8e653f0e18f Mon Sep 17 00:00:00 2001 From: Frederic CORDIER Date: Fri, 23 May 2025 09:05:39 +0200 Subject: [PATCH 2/3] feat: change go version --- .devcontainer/devcontainer.json | 6 +++--- .github/workflows/main.yaml | 2 +- .github/workflows/release.yml | 2 +- go.mod | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 5ccf081..91ee927 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,10 +1,10 @@ // For format details, see https://aka.ms/devcontainer.json. For config options, see the // README at: https://github.com/devcontainers/templates/tree/main/src/go { - "name": "Go 1.24", + "name": "Go 1.23", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/go:1-1.24-bullseye", - + "image": "mcr.microsoft.com/devcontainers/go:1-1.23-bullseye", + "mounts": [ "type=bind,source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,readonly" ], diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index c052ddb..9cadf22 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go-version: [ '1.24' ] + go-version: [ '1.23' ] steps: - name: Checkout code uses: actions/checkout@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dbe6646..7c0cdce 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,7 @@ permissions: contents: write env: - GO_VERSION: "1.24" + GO_VERSION: "1.23" jobs: manual-release: diff --git a/go.mod b/go.mod index f188909..4fb7998 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/thewhitewizard/web3data-cli -go 1.24.2 +go 1.23.4 require github.com/spf13/cobra v1.9.1 From 75e2f1bc5f480985a307b8b9561cad0585b0cc0c Mon Sep 17 00:00:00 2001 From: Frederic CORDIER Date: Fri, 23 May 2025 09:06:39 +0200 Subject: [PATCH 3/3] feat: update linter --- .golangci.yml | 96 +++++++++++++++++++++------------------------------ 1 file changed, 40 insertions(+), 56 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 2c32334..68f6498 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,79 +1,63 @@ -version: "2" -run: - issues-exit-code: 1 +linters-settings: + errcheck: + check-type-assertions: true + exhaustive: + default-signifies-exhaustive: true + goconst: + min-len: 2 + min-occurrences: 3 + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + govet: + enable-all: true + stylecheck: + checks: ["ST1000", "ST1001"] + nolintlint: + require-explanation: true + require-specific: true + wsl: + allow-assign-and-anything: true + allow-cuddle-declarations: true + allow-assign-and-call: true + linters: - default: none + disable-all: true enable: - bodyclose - - copyloopvar - dogsled - dupl - errcheck + - copyloopvar - exhaustive - goconst + - gofmt + - goimports + - govet + - mnd - gocyclo - gosec + - gosimple - govet - ineffassign - misspell - - mnd - - nakedret - nolintlint + - nakedret - prealloc - predeclared - staticcheck + - stylecheck - thelper - tparallel + - typecheck - unconvert - unparam - whitespace - wsl - settings: - errcheck: - check-type-assertions: true - exhaustive: - default-signifies-exhaustive: true - goconst: - min-len: 2 - min-occurrences: 3 - gocritic: - enabled-tags: - - diagnostic - - experimental - - opinionated - - performance - - style - govet: - enable-all: true - nolintlint: - require-explanation: true - require-specific: true - staticcheck: - checks: - - ST1000 - - ST1001 - wsl: - allow-assign-and-call: true - allow-assign-and-anything: true - allow-cuddle-declarations: true - exclusions: - generated: lax - presets: - - comments - - common-false-positives - - legacy - - std-error-handling - paths: - - third_party$ - - builtin$ - - examples$ -formatters: - enable: - - gofmt - - goimports - exclusions: - generated: lax - paths: - - third_party$ - - builtin$ - - examples$ + +run: + issues-exit-code: 1