diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..91ee927 --- /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.23", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/go:1-1.23-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..9cadf22 --- /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.23' ] + 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..7c0cdce --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,46 @@ +name: release + +on: + push: + tags: + - "*" + +permissions: + contents: write + +env: + GO_VERSION: "1.23" + +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..68f6498 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,63 @@ +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: + disable-all: true + enable: + - bodyclose + - dogsled + - dupl + - errcheck + - copyloopvar + - exhaustive + - goconst + - gofmt + - goimports + - govet + - mnd + - gocyclo + - gosec + - gosimple + - govet + - ineffassign + - misspell + - nolintlint + - nakedret + - prealloc + - predeclared + - staticcheck + - stylecheck + - thelper + - tparallel + - typecheck + - unconvert + - unparam + - whitespace + - wsl + +run: + issues-exit-code: 1 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..4fb7998 --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module github.com/thewhitewizard/web3data-cli + +go 1.23.4 + +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" + } + } +}