Skip to content

Commit 9c7450d

Browse files
authored
Makefile tooling (#15)
1 parent fe3b8bc commit 9c7450d

File tree

8 files changed

+146
-33
lines changed

8 files changed

+146
-33
lines changed

.github/workflows/main.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
steps:
18-
- name: Checkout code
19-
uses: actions/checkout@v1
20-
2118
- name: Setup go
2219
uses: actions/setup-go@v1
2320
with:
2421
go-version: 1.13
2522

23+
- name: Checkout code
24+
uses: actions/checkout@v1
25+
2626
- name: Build binary
2727
run: go build -o dist/retry -ldflags="-s -w -X main.version=$(git describe --tags)" .
2828

@@ -34,22 +34,29 @@ jobs:
3434
runs-on: ubuntu-latest
3535

3636
steps:
37+
- name: Setup go
38+
uses: actions/setup-go@v1
39+
with:
40+
go-version: 1.13
41+
3742
- name: Checkout code
3843
uses: actions/checkout@v1
3944

4045
- name: Run tests
41-
run: go test -v -race -cover ./...
46+
run: make test
4247

43-
golang-ci-lint:
48+
lint:
4449
name: Lint
4550
runs-on: ubuntu-latest
4651

4752
steps:
53+
- name: Setup go
54+
uses: actions/setup-go@v1
55+
with:
56+
go-version: 1.13
57+
4858
- name: Checkout code
4959
uses: actions/checkout@v1
5060

51-
- name: Run GolangCI-Lint
52-
uses: docker://golangci/golangci-lint:v1.21.0-alpine
53-
with:
54-
entrypoint: /usr/bin/golangci-lint
55-
args: run -v
61+
- name: Lint code
62+
run: make lint

.github/workflows/release.yml

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,7 @@ jobs:
2020
with:
2121
go-version: 1.13
2222

23-
- name: Install UPX 3.94
24-
run: |
25-
wget -q https://github.com/upx/upx/releases/download/v3.94/upx-3.94-amd64_linux.tar.xz
26-
tar -xvf upx-3.94-amd64_linux.tar.xz
27-
mkdir -p /opt/hostedtoolcache/upx-3.94/bin
28-
install upx-3.94-amd64_linux/upx /opt/hostedtoolcache/upx-3.94/bin/upx
29-
rm -rf upx-3.94-amd64_linux*
30-
echo ::set-env name=PATH::/opt/hostedtoolcache/upx-3.94/bin:$PATH
31-
32-
- name: Install GoReleaser 0.123.3
33-
run: |
34-
wget -q https://github.com/goreleaser/goreleaser/releases/download/v0.123.3/goreleaser_Linux_x86_64.tar.gz
35-
tar -xvf goreleaser_Linux_x86_64.tar.gz goreleaser
36-
mkdir -p /opt/hostedtoolcache/goreleaser-0.123.3/bin
37-
install goreleaser /opt/hostedtoolcache/goreleaser-0.123.3/bin/goreleaser
38-
rm -rf goreleaser*
39-
echo ::set-env name=PATH::/opt/hostedtoolcache/goreleaser-0.123.3/bin:$PATH
40-
4123
- name: Run GoReleaser
4224
env:
4325
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44-
run: goreleaser release
26+
run: make release

.goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ builds:
2222

2323
hooks:
2424
pre: go mod tidy
25-
post: ./upx.sh
25+
post: make compress
2626

2727
archives:
2828
- id: retry

Makefile

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#### Environment ####
2+
3+
# Enforce usage of the Go modules system.
4+
export GO111MODULE := on
5+
6+
# Determine where `go get` will install binaries to.
7+
GOBIN := $(HOME)/go/bin
8+
ifdef GOPATH
9+
GOBIN := $(GOPATH)/bin
10+
endif
11+
12+
# Current operating system name.
13+
PLATFORM := $(shell uname -s)
14+
15+
# All target for when make is run on its own.
16+
.PHONY: all
17+
all: test lint
18+
19+
#### Binary Dependencies ####
20+
21+
# Install binary for goimports.
22+
goimports := $(GOBIN)/goimports
23+
$(goimports):
24+
@cd /tmp && go get -u golang.org/x/tools/cmd/goimports
25+
26+
# Install binary for golangci-lint.
27+
golangci-lint := $(GOBIN)/golangci-lint
28+
$(golangci-lint):
29+
@./scripts/install-golangci-lint $(golangci-lint)
30+
31+
# Install binary for goreleaser.
32+
goreleaser := $(GOBIN)/goreleaser
33+
$(goreleaser):
34+
@./scripts/install-goreleaser $(goreleaser)
35+
36+
# Install binary for upx.
37+
ifeq "$(PLATFORM)" "Linux"
38+
upx := $(GOBIN)/upx
39+
else
40+
upx := /usr/local/bin/upx
41+
endif
42+
$(upx):
43+
@./scripts/install-upx $(upx)
44+
45+
#### Linting ####
46+
47+
# Run code linters.
48+
.PHONY: lint
49+
lint: $(golangci-lint) style
50+
$(golangci-lint) run
51+
52+
# Run code formatters. Unformatted code will fail in CircleCI.
53+
.PHONY: style
54+
style: $(goimports)
55+
ifdef GITHUB_ACTIONS
56+
$(goimports) -l .
57+
else
58+
$(goimports) -l -w .
59+
endif
60+
61+
#### Testing ####
62+
63+
# Run Go tests and generate a JUnit XML style test report for ingestion by CircleCI.
64+
.PHONY: test
65+
test: $(go-junit-report)
66+
@go test -v -race -cover ./...
67+
68+
#### Release ####
69+
70+
.PHONY: compress
71+
compress: $(upx)
72+
$(upx) --best --ultra-brute dist/retry_*/retry*
73+
74+
.PHONY: release
75+
release: $(goreleaser)
76+
ifdef GITHUB_ACTIONS
77+
$(goreleaser) release
78+
else
79+
$(goreleaser) --rm-dist --skip-publish --skip-validate --snapshot
80+
endif

scripts/install-golangci-lint

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
platform="$(uname -s)"
5+
if [ "$platform" = Linux ]; then
6+
prefix=golangci-lint-1.21.0-linux-amd64
7+
elif [ "$platform" = Darwin ]; then
8+
prefix=golangci-lint-1.21.0-darwin-amd64
9+
fi
10+
11+
cd "$(mktemp -d)" || exit 1
12+
wget -q "https://github.com/golangci/golangci-lint/releases/download/v1.21.0/${prefix}.tar.gz"
13+
tar -xf "${prefix}.tar.gz"
14+
mkdir -p "$(dirname "$1")"
15+
install "${prefix}/golangci-lint" "$1"
16+
rm -rf "$PWD"

scripts/install-goreleaser

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
platform="$(uname -s)"
5+
if [ "$platform" = Linux ]; then
6+
prefix=goreleaser_Linux_x86_64
7+
elif [ "$platform" = Darwin ]; then
8+
prefix=goreleaser_Darwin_x86_64
9+
fi
10+
11+
cd "$(mktemp -d)" || exit 1
12+
wget -q "https://github.com/goreleaser/goreleaser/releases/download/v0.123.3/${prefix}.tar.gz"
13+
tar -xf "${prefix}.tar.gz"
14+
mkdir -p "$(dirname "$1")"
15+
install goreleaser "$1"
16+
rm -rf "$PWD"

scripts/install-upx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
platform="$(uname -s)"
5+
if [ "$platform" = Darwin ]; then
6+
HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 exec brew install upx
7+
fi
8+
prefix=upx-3.94-amd64_linux
9+
10+
cd "$(mktemp -d)" || exit 1
11+
wget -q "https://github.com/upx/upx/releases/download/v3.94/${prefix}.tar.xz"
12+
tar -xf "${prefix}.tar.xz"
13+
mkdir -p "$(dirname "$1")"
14+
install "${prefix}/upx" "$1"
15+
rm -rf "$PWD"

upx.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)