Skip to content

Commit

Permalink
Add versioned tools, run fmt and lint in CI (#15)
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Shkuro <[email protected]>
  • Loading branch information
yurishkuro authored Jun 29, 2024
1 parent ab049e9 commit 1785266
Show file tree
Hide file tree
Showing 14 changed files with 1,292 additions and 40 deletions.
21 changes: 8 additions & 13 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ on:
pull_request:
branches: [main]

env:
golangci-lint-version: v1.46.2

jobs:
build:
name: Build, test and lint
Expand All @@ -17,7 +14,7 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Set up Go
- name: Set up Go
uses: actions/[email protected]
with:
go-version: 1.22.4
Expand All @@ -29,13 +26,11 @@ jobs:
- name: Test
run: go test ./...

# Disable lint step temporarily. Need to migrate it to tools/go.mod
# - name: Lint
# uses: golangci/golangci-lint-action@v3
# with:
# version: ${{ env.golangci-lint-version }}
- name: Install tools
run: make install-ci

- name: Lint
run: make lint

- name: Format
run: |
go fmt ./...
git diff --exit-code .
- name: Check Format
run: make fmt && git diff --exit-code .
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor/
microsim
.tools/
40 changes: 40 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2023 The Jaeger Authors.
# SPDX-License-Identifier: Apache-2.0

SHELL := /bin/bash

# These DOCKER_xxx vars are used when building Docker images.
DOCKER_NAMESPACE?=yurishkuro
DOCKER_TAG?=latest

# SRC_ROOT is the top of the source tree.
SRC_ROOT := $(shell git rev-parse --show-toplevel)

GO := go

# All .go files that are not auto-generated and should be auto-formatted and linted.
ALL_SRC = $(shell find . -name '*.go' \
-not -name '_*' \
-not -name '.*' \
-not -name 'mocks*' \
-not -name '*.pb.go' \
-not -path './vendor/*' \
-not -path './internal/tools/*' \
-not -path '*/mocks/*' \
-not -path '*/*-gen/*' \
-type f | \
sort)

# import other Makefiles after the variables are defined
include Makefile.Tools.mk

.PHONY: fmt
fmt:
@echo Running gofmt on ALL_SRC ...
@$(GOFMT) -e -s -l -w $(ALL_SRC)
@echo Running gofumpt on ALL_SRC ...
@$(GOFUMPT) -e -l -w $(ALL_SRC)

.PHONY: lint
lint:
$(LINT) -v run
39 changes: 39 additions & 0 deletions Makefile.Tools.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (c) 2024 The Jaeger Authors.
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

TOOLS_MOD_DIR := $(SRC_ROOT)/internal/tools
TOOLS_BIN_DIR := $(SRC_ROOT)/.tools
TOOLS_MOD_REGEX := "\s+_\s+\".*\""
TOOLS_PKG_NAMES := $(shell grep -E $(TOOLS_MOD_REGEX) < $(TOOLS_MOD_DIR)/tools.go | tr -d " _\"")
TOOLS_BIN_NAMES := $(addprefix $(TOOLS_BIN_DIR)/, $(notdir $(shell echo $(TOOLS_PKG_NAMES) | sed 's|/v[0-9]||g')))

GOFUMPT := $(TOOLS_BIN_DIR)/gofumpt
GOVERSIONINFO := $(TOOLS_BIN_DIR)/goversioninfo
LINT := $(TOOLS_BIN_DIR)/golangci-lint
MOCKERY := $(TOOLS_BIN_DIR)/mockery

# this target is useful for setting up local workspace, but from CI we want to call more specific ones
.PHONY: install-tools
install-tools: $(TOOLS_BIN_NAMES)

.PHONY: install-test-tools
install-test-tools: $(LINT) $(GOFUMPT)

.PHONY: install-build-tools
install-build-tools: $(GOVERSIONINFO)

.PHONY: install-ci
install-ci: install-test-tools install-build-tools

list-internal-tools:
@echo Third party tool modules:
@echo $(TOOLS_PKG_NAMES) | tr ' ' '\n' | sed 's/^/- /g'
@echo Third party tool binaries:
@echo $(TOOLS_BIN_NAMES) | tr ' ' '\n' | sed 's/^/- /g'

$(TOOLS_BIN_DIR):
mkdir -p $@

$(TOOLS_BIN_NAMES): $(TOOLS_BIN_DIR) $(TOOLS_MOD_DIR)/go.mod
cd $(TOOLS_MOD_DIR) && $(GO) build -o $@ -trimpath $(shell echo $(TOOLS_PKG_NAMES) | tr ' ' '\n' | grep $(notdir $@))
1 change: 0 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
// Get makes a traced HTTP GET call.
func Get(ctx context.Context, url string, tracer trace.Tracer) error {
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)

if err != nil {
return err
}
Expand Down
30 changes: 15 additions & 15 deletions config/hotrod.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (

var hotrod = &model.Config{
Services: []*model.Service{
&model.Service{
{
Name: "ui",
Endpoints: []*model.Endpoint{
&model.Endpoint{
{
Name: "/",
Depends: &model.Dependencies{
Service: &model.ServiceDep{
Expand All @@ -20,10 +20,10 @@ var hotrod = &model.Config{
},
},
},
&model.Service{
{
Name: "frontend",
Endpoints: []*model.Endpoint{
&model.Endpoint{
{
Name: "/dispatch",
Depends: &model.Dependencies{
Seq: model.Sequence{
Expand All @@ -49,10 +49,10 @@ var hotrod = &model.Config{
},
},
},
&model.Service{
{
Name: "customer",
Endpoints: []*model.Endpoint{
&model.Endpoint{
{
Name: "/customer",
Depends: &model.Dependencies{
Seq: model.Sequence{
Expand All @@ -62,10 +62,10 @@ var hotrod = &model.Config{
},
},
},
&model.Service{
{
Name: "driver",
Endpoints: []*model.Endpoint{
&model.Endpoint{
{
Name: "/FindNearest",
Depends: &model.Dependencies{
Seq: model.Sequence{
Expand All @@ -86,30 +86,30 @@ var hotrod = &model.Config{
},
Count: 2,
},
&model.Service{
{
Name: "route",
Count: 3,
Endpoints: []*model.Endpoint{
&model.Endpoint{
{
Name: "/GetShortestRoute",
},
},
},
&model.Service{
{
Name: "mysql",
Endpoints: []*model.Endpoint{
&model.Endpoint{
{
Name: "/sql_select",
},
},
},
&model.Service{
{
Name: "redis",
Endpoints: []*model.Endpoint{
&model.Endpoint{
{
Name: "/FindDriverIDs",
},
&model.Endpoint{
{
Name: "/GetDriver",
},
},
Expand Down
6 changes: 6 additions & 0 deletions internal/tools/empty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

// Package tools is used to track versions of 3rd party tools used for building / testing CI.
// See tools.go for imported tools and go.mod for the versions of those tools.
package tools
Loading

0 comments on commit 1785266

Please sign in to comment.