From 43c621fcaa17a310032dbd17bf15251ef3e17d11 Mon Sep 17 00:00:00 2001 From: Grzegorz Bernady Date: Fri, 16 Feb 2024 15:07:25 +0100 Subject: [PATCH] Add basic workflows --- .github/dependabot.yml | 19 ++++++++++++++ .github/workflows/build.yml | 30 +++++++++++++++++++++ .github/workflows/codeql.yml | 37 ++++++++++++++++++++++++++ .gitignore | 14 ++++++---- .golangci-lint.yml | 29 ++++++++++++++++++++ Makefile | 51 ++++++++++++++++++++++++++++++++---- README.md | 3 +++ 7 files changed, 173 insertions(+), 10 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/codeql.yml create mode 100644 .golangci-lint.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..ca901a3 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,19 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + commit-message: + prefix: "deps" + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "weekly" + commit-message: + prefix: "deps" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..da3bfb7 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,30 @@ +name: Build + +on: + push: + branches: [ 'main' ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ 'main' ] + +jobs: + test: + name: Test + runs-on: ${{ matrix.os }} + permissions: + contents: read + strategy: + matrix: + os: [ 'macos-latest', 'ubuntu-latest' ] + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.21' + check-latest: true + # - name: Run linters + # run: make lint + - name: Run tests + run: make test \ No newline at end of file diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..7a4b7da --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,37 @@ +name: CodeQL + +on: + push: + branches: [ 'main' ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ 'main' ] + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + strategy: + fail-fast: false + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.21' + check-latest: true + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: go + - name: Autobuild + uses: github/codeql-action/autobuild@v3 + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: '/language:go' \ No newline at end of file diff --git a/.gitignore b/.gitignore index 38eff99..b1de4fa 100644 --- a/.gitignore +++ b/.gitignore @@ -8,10 +8,6 @@ *.so *.dylib -# JetBrains -.idea/ - - # Test binary, built with `go test -c` *.test @@ -24,6 +20,14 @@ # Go workspace file go.work -gcore-cli +# Editor and IDE paraphernalia +.idea .vscode +*.swp +*.swo +*~ + +# Project +bin/ dist/ +gcore-cli diff --git a/.golangci-lint.yml b/.golangci-lint.yml new file mode 100644 index 0000000..39ba199 --- /dev/null +++ b/.golangci-lint.yml @@ -0,0 +1,29 @@ +run: + allow-parallel-runners: true + timeout: 5m + +issues: + # don't skip warning about doc comments + # don't exclude the default set of lint + exclude-use-default: false + +linters: + disable-all: true + enable: + - errcheck + - exportloopref + - goconst + - gocyclo + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - misspell + - nakedret + - prealloc + - staticcheck + - typecheck + - unconvert + - unparam + - unused \ No newline at end of file diff --git a/Makefile b/Makefile index e7bf8a2..9c68d26 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,49 @@ -all: gcore-cli +all: build -.PHONY: gcore-cli +##@ General -build: gcore-cli +.PHONY: help +help: ## Show this help + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " %-15s %s\n", $$1, $$2 } /^##@/ { printf "\n%s\n", substr($$0, 5) } ' $(MAKEFILE_LIST) -gcore-cli: - CGO_ENABLED=0 go build -ldflags="-extldflags=-static" -o gcore-cli cmd/gcore-cli/main.go +##@ Development + +.PHONY: fmt +fmt: ## Run go fmt against code + go fmt ./... + +.PHONY: vet +vet: ## Run go vet against code + go vet ./... + +.PHONY: lint +lint: golangci-lint ## Run golangci-lint against code + $(GOLANGCI_LINT) run -v ./... + +.PHONY: test +test: fmt vet ## Run tests + go test -v -covermode=count -coverprofile=cover.out ./... + +##@ Build + +.PHONY: build +build: fmt vet ## Build gcore-cli binary + CGO_ENABLED=0 go build -trimpath -ldflags="-extldflags=-static" -o gcore-cli ./cmd/gcore-cli + +##@ Build Dependencies + +## Location to install dependencies to +LOCALBIN ?= $(shell pwd)/bin +$(LOCALBIN): + mkdir -p $(LOCALBIN) + +## Tool Binaries +GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint + +## Tool Versions +GOLANGCI_LINT_VERSION ?= v1.56.2 + +.PHONY: golangci-lint +golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. +$(GOLANGCI_LINT): $(LOCALBIN) + GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) diff --git a/README.md b/README.md index 77563bf..2fcd490 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # gcore-cli +[![Build](https://github.com/G-Core/gcore-cli/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/G-Core/gcore-cli/actions/workflows/build.yml) +[![Go Report Card](https://goreportcard.com/badge/github.com/G-Core/gcore-cli)](https://goreportcard.com/report/github.com/G-Core/gcore-cli) + `gcore-cli` is the official Gcore command line tool. ## Installation