Skip to content

Commit

Permalink
Add dockerfile and shellcheck linters, refactor golangci-lint and hac…
Browse files Browse the repository at this point in the history
…k dir (#45)
  • Loading branch information
mszostok committed Oct 17, 2020
1 parent 32b0e86 commit 3c8cc7f
Show file tree
Hide file tree
Showing 22 changed files with 290 additions and 219 deletions.
31 changes: 30 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
issues:
exclude:
# Check this issue for more info: https://github.com/kyoh86/scopelint/issues/4
- Using the variable on range scope `tc` in function literal
- Using the variable on range scope `tc` in function literal

run:
tests: true
linters:
disable-all: true
enable:
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
- golint
- gofmt
- misspell
- gochecknoinits
- unparam
- scopelint
- gosec
- goimports
- whitespace
- bodyclose
- gocyclo

fast: false
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ branches:
env:
global:
- GO111MODULE=on
- RUN_ON_CI=true
- INSTALL_DEPS=true

script: skip

Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Get latest CA certs & git
FROM alpine:latest as deps
RUN apk --update add ca-certificates
RUN apk --update add git
FROM alpine:3.12.0 as deps

# hadolint ignore=DL3018
RUN apk --no-cache add ca-certificates git

FROM scratch

Expand All @@ -16,4 +17,3 @@ COPY --from=deps /lib /lib
COPY --from=deps /usr/lib /usr/lib

CMD ["/codeowners-validator"]

26 changes: 20 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ export GOPROXY = https://proxy.golang.org
all: build-race test-unit test-integration test-lint
.PHONY: all

# Build
############
# Building #
############

build:
go build -o codeowners-validator ./main.go
.PHONY: build
Expand All @@ -17,23 +20,34 @@ build-race:
go build -race -o codeowners-validator ./main.go
.PHONY: build-race

# Test
###########
# Testing #
###########

test-unit:
./hack/ci/run-test-unit.sh
./hack/run-test-unit.sh
.PHONY: test-unit

test-integration: build
env BINARY_PATH=$(PWD)/codeowners-validator ./hack/ci/run-test-integration.sh
env BINARY_PATH=$(PWD)/codeowners-validator ./hack/run-test-integration.sh
.PHONY: test-integration

test-lint:
./hack/ci/run-lint.sh
./hack/run-lint.sh
.PHONY: test-lint

test-hammer:
go test -count=100 ./...
.PHONY: test-hammer

cover-html: test-unit
test-unit-cover-html: test-unit
go tool cover -html=./coverage.txt
.PHONY: cover-html

###############
# Development #
###############

fix-lint-issues:
LINT_FORCE_FIX=true ./hack/run-lint.sh
.PHONY: fix-lint
7 changes: 7 additions & 0 deletions hack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Hack directory

This package contains various scripts that are used by Codeowners Validator developers.

## Purpose

This directory contains tools, such as Go fmt, Go lint, and Go vet, that help to maintain the source code compliant to Go best coding practices. It also includes utility scripts that generate code, and scripts executed on CI pipelines.
27 changes: 0 additions & 27 deletions hack/ci/compress.sh

This file was deleted.

59 changes: 0 additions & 59 deletions hack/ci/run-lint.sh

This file was deleted.

41 changes: 0 additions & 41 deletions hack/ci/run-test-integration.sh

This file was deleted.

70 changes: 0 additions & 70 deletions hack/ci/run-test-unit.sh

This file was deleted.

31 changes: 31 additions & 0 deletions hack/compress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Inspired by https://liam.sh/post/makefiles-for-go-projects

# standard bash error handling
set -o nounset # treat unset variables as an error and exit immediately.
set -o errexit # exit immediately when a command fails.
set -E # needs to be set if we want the ERR trap

readonly CURRENT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
readonly ROOT_PATH=$( cd "${CURRENT_DIR}/.." && pwd )

# shellcheck source=./hack/lib/utilities.sh
source "${CURRENT_DIR}/lib/utilities.sh" || { echo 'Cannot load CI utilities.'; exit 1; }

function main() {
# This will find all files (not symlinks) with the executable bit set:
# https://apple.stackexchange.com/a/116371
binariesToCompress=$(find "${ROOT_PATH}/dist" -perm +111 -type f)

shout "Staring compression for: \n$binariesToCompress"

command -v upx > /dev/null || { echo 'UPX binary not found, skipping compression.'; exit 1; }

# I just do not like playing with xargs ¯\_(ツ)_/¯
for i in $binariesToCompress
do
upx --brute "$i"
done
}

main
File renamed without changes.
Loading

0 comments on commit 3c8cc7f

Please sign in to comment.