Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update service template with go tool support #200

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ version: 2.1

orbs:
slack: circleci/slack@5.1.1
go: circleci/go@2.2.4

workflows:
main-workflow:
@@ -47,7 +48,7 @@ executors:
- image: &goimage cimg/go:1.24
ccc:
docker:
- image: circleci/command-convenience:0.1
- image: circleci/command-convenience:experimental-enshrinkify-ccc
auth:
username: $DOCKER_HUB_USER
password: $DOCKER_HUB_PASSWORD
@@ -77,6 +78,9 @@ jobs:
- run:
name: go tidy
command: go mod tidy -v
- run:
name: run goimports
command: ./do run-goimports
- run:
name: verify no changes
command: git diff --ignore-matching-lines='Generated on ' --exit-code
@@ -270,8 +274,9 @@ commands:
setup:
steps:
- checkout
- run: go mod download
- run: ./do install-devtools
- go/with-cache:
steps:
- run: go mod download

store_results:
steps:
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -4,8 +4,7 @@ run:

# Do not treat these as gospel, adjust as appropriate
linters-settings:
govet:
check-shadowing: false
shadow: false
golint:
min-confidence: 0
gocyclo:
1 change: 0 additions & 1 deletion cmd/api/main.go
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ import (
"github.com/circleci/ex/system"
"github.com/circleci/ex/termination"

/* todo rename 'ex-service-template' to 'your-service' */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this? helpful note when setting up services IMO

"github.com/circleci/ex-service-template/api/api"
"github.com/circleci/ex-service-template/books"
"github.com/circleci/ex-service-template/cmd"
47 changes: 8 additions & 39 deletions do
Original file line number Diff line number Diff line change
@@ -3,7 +3,8 @@ set -eu -o pipefail

_version=1.0.${CIRCLE_BUILD_NUM-0}-$(git rev-parse --short HEAD 2>/dev/null || echo latest)
reportDir="test-reports"
serviceName="ex-service-template"
serviceName="ex-service-template" #FIXME: update with the new service name
package="github.com/circleci/${serviceName}"

make-target() {
mkdir -p "target"
@@ -35,7 +36,7 @@ help_build="Build the binaries for production"
build() {
local date ldflags
date=$(date "+%FT%T%z")
ldflags="-s -w -X github.com/circleci/${serviceName}/cmd.Version=$_version -X github.com/circleci/${serviceName}/cmd.Date=$date"
ldflags="-s -w -X ${package}/cmd.Version=$_version -X ${package}/cmd.Date=$date"

GOOS=linux GOARCH=amd64 binary "$ldflags" &

@@ -59,7 +60,7 @@ build() {
# shellcheck disable=SC2034
help_lint="Run golanci-lint to lint go files."
lint() {
exec ./bin/golangci-lint run "${@:-./...}"
exec go tool golangci-lint run "${@:-./...}"
}

# This variable is used, but shellcheck can't tell.
@@ -79,26 +80,25 @@ help_test="Run normal unit tests"
test() {
mkdir -p "${reportDir}"
# -count=1 is used to forcibly disable test result caching
./bin/gotestsum --junitfile="${reportDir}/junit.xml" -- -race -count=1 "${@:-./...}"
go tool gotestsum --junitfile="${reportDir}/junit.xml" -- -race -count=1 "${@:-./...}"
}

# This variable is used, but shellcheck can't tell.
# shellcheck disable=SC2034
help_run_goimports="Run goimports for package"
run-goimports () {
./bin/gosimports -local "github.com/circleci/ex-service-template" -w
go tool gosimports -local "${package}" -w .
}

# This variable is used, but shellcheck can't tell.
# shellcheck disable=SC2034
help_godoc="Run godoc to read documentation."
godoc() {
install-go-bin "golang.org/x/tools/cmd/godoc@v0.1.3"
local url
url="http://localhost:6060/pkg/github.com/circleci/${serviceName}/"
url="http://localhost:6060/pkg/${package}/"
command -v xdg-open && xdg-open $url &
command -v open && open $url &
./bin/godoc -http=127.0.0.1:6060
go tool godoc -http=127.0.0.1:6060
}

# This variable is used, but shellcheck can't tell.
@@ -108,29 +108,6 @@ go-mod-tidy() {
go mod tidy -v
}

install-go-bin() {
local binDir="$PWD/bin"
for pkg in "${@}"; do
echo "${pkg}"
(
cd tools
GOBIN="${binDir}" go install "${pkg}"
)
done
}

# This variable is used, but shellcheck can't tell.
# shellcheck disable=SC2034
help_install_devtools="Install tools that other tasks expect into ./bin"
install-devtools() {
local tools=()
while IFS='' read -r value; do
tools+=("$value")
done < <(grep _ tools/tools.go | awk -F'"' '{print $2}')

install-go-bin "${tools[@]}"
}

# This variable is used, but shellcheck can't tell.
# shellcheck disable=SC2034
help_create_stub_test_files="Create an empty pkg_test in all directories with no tests.
@@ -145,14 +122,6 @@ create-stub-test-files() {
xargs -r --max-args=2 bash -c 'echo "package $0" > "$1/pkg_test.go"'
}

# This variable is used, but shellcheck can't tell.
# shellcheck disable=SC2034
help_run_goimports="Run goimports for package"
run-goimports () {
command -v ./bin/goimports || install-go-bin "golang.org/x/tools/cmd/goimports@v0.0.0-20201208183658-cc330816fc52"
./bin/goimports -local "github.com/circleci/${serviceName}" -w "${@:-.}"
}

# This variable is used, but shellcheck can't tell.
# shellcheck disable=SC2034
help_version="Print version"
Loading
Oops, something went wrong.