Skip to content

Commit

Permalink
Merge pull request #5 from prometheus-operator/go-checks
Browse files Browse the repository at this point in the history
Go checks
  • Loading branch information
nicolastakashi authored May 17, 2024
2 parents b221e75 + e46053e commit a45a5b9
Show file tree
Hide file tree
Showing 10 changed files with 791 additions and 58 deletions.
1 change: 1 addition & 0 deletions .github/env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
golang-version=1.22
56 changes: 56 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: checks
on:
pull_request:
push:
branches:
- 'main'
jobs:
check-docs:
runs-on: ubuntu-latest
name: Check Documentation formatting and links
steps:
- uses: actions/checkout@v4
- name: Import environment variables from file
run: cat ".github/env" >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version: '${{ env.golang-version }}'
check-latest: true
- run: make check-docs

check-golang:
runs-on: ubuntu-latest
name: Golang linter
steps:
- uses: actions/checkout@v4
- name: Import environment variables from file
run: cat ".github/env" >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version: '${{ env.golang-version }}'
check-latest: true
- name: go.mod
run: make tidy && git diff --exit-code
- name: golangci-lint
uses: golangci/golangci-lint-action@v6.0.1
with:
version: v1.57.2
args: --timeout 10m0s --go ${{ env.golang-version }}

build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
name: Build operator binary
steps:
- uses: actions/checkout@v4
- name: Import environment variables from file
run: cat ".github/env" >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version: '${{ env.golang-version }}'
check-latest: true
- run: make poctl
25 changes: 25 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
run:
deadline: 10m

linters:
enable:
- revive
- depguard
- godot
- testifylint
- unconvert

issues:
exclude-rules:
# Disable errcheck linter for test files.
- path: _test.go
linters:
- errcheck

linters-settings:
depguard:
rules:
forbid-pkg-errors:
deny:
- pkg: "github.com/pkg/errors"
dsc: Should be replaced with standard lib errors or fmt.Errorf
32 changes: 31 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,47 @@ TOOLS_BIN_DIR ?= $(shell pwd)/tmp/bin

export PATH := $(TOOLS_BIN_DIR):$(PATH)

GO_BUILD_RECIPE=\
GOOS=$(GOOS) \
GOARCH=$(GOARCH) \
CGO_ENABLED=0 \
go build

GOLANGCILINTER_BINARY=$(TOOLS_BIN_DIR)/golangci-lint
MDOX_BINARY=$(TOOLS_BIN_DIR)/mdox
MDOX_VALIDATE_CONFIG?=.mdox.validate.yaml

TOOLING=$(MDOX_BINARY)
TOOLING=$(MDOX_BINARY) $(GOLANGCILINTER_BINARY)

MD_FILES_TO_FORMAT=$(shell ls *.md)

.PHONY: docs
docs: $(MDOX_BINARY)
@echo ">> formatting and local/remote link check"
$(MDOX_BINARY) fmt --soft-wraps -l --links.localize.address-regex="https://prometheus-operator.dev/.*" --links.validate.config-file=$(MDOX_VALIDATE_CONFIG) $(MD_FILES_TO_FORMAT)

.PHONY: check-docs
check-docs: $(MDOX_BINARY)
@echo ">> checking formatting and local/remote links"
$(MDOX_BINARY) fmt --soft-wraps --check -l --links.localize.address-regex="https://prometheus-operator.dev/.*" --links.validate.config-file=$(MDOX_VALIDATE_CONFIG) $(MD_FILES_TO_FORMAT)

.PHONY: check-golang
check-golang: $(GOLANGCILINTER_BINARY)
$(GOLANGCILINTER_BINARY) run

.PHONY: fix-golang
fix-golang: $(GOLANGCILINTER_BINARY)
$(GOLANGCILINTER_BINARY) run --fix

.PHONY: tidy
tidy:
go mod tidy -v
cd scripts && go mod tidy -v -modfile=go.mod -compat=1.18

.PHONY: poctl
poctl:
$(GO_BUILD_RECIPE) -o $@ main.go

$(TOOLS_BIN_DIR):
mkdir -p $(TOOLS_BIN_DIR)

Expand Down
2 changes: 1 addition & 1 deletion cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra"
)

// createCmd represents the create command
// createCmd represents the create command.
var createCmd = &cobra.Command{
Use: "create",
Short: "create is used to create Prometheus Operator resources.",
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra"
)

// rootCmd represents the base command when called without any subcommands
// rootCmd represents the base command when called without any subcommands.
var rootCmd = &cobra.Command{
Use: "poctl",
Short: "poctl is a command line interface for managing Prometheus Operator.",
Expand Down
4 changes: 2 additions & 2 deletions cmd/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"github.com/spf13/cobra"
)

// stackCmd represents the stack command
// stackCmd represents the stack command.
var stackCmd = &cobra.Command{
Use: "stack",
Short: "create a stack of Prometheus Operator resources.",
Long: `create a stack of Prometheus Operator resources.`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
logger, err := log.NewLogger()
if err != nil {
fmt.Println(err)
Expand Down
Loading

0 comments on commit a45a5b9

Please sign in to comment.