Skip to content

Travis CI Stages, some updates #95

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

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
33 changes: 31 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: go

go:
- 1.x

Expand All @@ -11,5 +12,33 @@ install:
- make get-tools
- make get-deps

script:
- make
stages:
- name: test
- name: build
- name: publish
if: tag IS present
# FIXME: now upload release from local
# - name: release
# if: branch = master
# if: tag IS present

jobs:
fast_finish: true
include:
- stage: test
name: "Check Tests"
script: make
- stage: build
name: "Build Tests"
script: make build && make package
- stage: publish
name: "Publish Pre-Release"
script: make build && make package && make publish
# - stage: release
# name: "Publish Release"
# script: make build && make package && make release

notifications:
email:
on_success: never
on_failure: always
66 changes: 48 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
PACKAGE = go-http-tunnel

OUTPUT_DIR = build
OS = "darwin freebsd linux windows"
ARCH = "386 amd64 arm"
OSARCH = "!darwin/386 !darwin/arm !windows/arm"

GIT_COMMIT = $(shell git describe --always --exclude '*')
GIT_TAG = $(shell git describe --tags | cut -d- -f1)
UNAME := $(shell uname -s)

ifeq ($(UNAME),Darwin)
SHA256 := shasum -a 256
else
SHA256 := sha256sum
endif

GO_FILES := $(shell \
find . '(' -path '*/.*' -o -path './vendor' ')' -prune \
Expand All @@ -20,21 +36,27 @@ check: .check-fmt .check-vet .check-lint .check-ineffassign .check-static .check

.PHONY: .check-fmt
.check-fmt:
@echo "==> Checking formatting..."
$(eval FMT_LOG := $(shell mktemp -t gofmt.XXXXX))
@cat /dev/null > $(FMT_LOG)
@gofmt -e -s -l -d $(GO_FILES) > $(FMT_LOG) || true
@[ ! -s "$(FMT_LOG)" ] || (echo "$@ failed:" | cat - $(FMT_LOG) && false)
@[ ! -s "$(FMT_LOG)" ] || (echo "$@ failed:" | cat - $(FMT_LOG) && false) && (echo "$@ passed.")

.PHONY: .check-vet
.check-vet:
@go vet ./...
@echo "==> Examines source code and reports suspicious constructs..."
$(eval VET_LOG := $(shell mktemp -t govet.XXXXX))
@cat /dev/null > $(VET_LOG)
@go vet ./... > $(VET_LOG) || true
@[ ! -s "$(VET_LOG)" ] || (echo "$@ failed:" | cat - $(VET_LOG) && false) && (echo "$@ passed.")

.PHONY: .check-lint
.check-lint:
@echo "==> Checking lint..."
$(eval LINT_LOG := $(shell mktemp -t golint.XXXXX))
@cat /dev/null > $(LINT_LOG)
@$(foreach pkg, $(GO_FILES), golint $(pkg | grep -v $LINT_IGNORE) >> $(LINT_LOG) || true;)
@[ ! -s "$(LINT_LOG)" ] || (echo "$@ failed:" | cat - $(LINT_LOG) && false)
@[ ! -s "$(LINT_LOG)" ] || (echo "$@ failed:" | cat - $(LINT_LOG) && false) && (echo "$@ passed.")


.PHONY: .check-ineffassign
Expand Down Expand Up @@ -69,35 +91,43 @@ get-tools:
@go get -u github.com/golang/dep/cmd/dep
@go get -u golang.org/x/lint/golint
@go get -u github.com/golang/mock/gomock

@go get -u github.com/client9/misspell/cmd/misspell
@go get -u github.com/gordonklaus/ineffassign
@go get -u github.com/mitchellh/gox
@go get -u github.com/tcnksm/ghr
@go get -u honnef.co/go/tools/cmd/staticcheck

OUTPUT_DIR = build
OS = "darwin freebsd linux windows"
ARCH = "386 amd64 arm"
OSARCH = "!darwin/386 !darwin/arm !windows/arm"
GIT_COMMIT = $(shell git describe --always)

.PHONY: release
release: check test clean build package

.PHONY: build
build:
mkdir ${OUTPUT_DIR}
mkdir -p ${OUTPUT_DIR}
CGO_ENABLED=0 GOARM=5 gox -ldflags "-w -X main.version=$(GIT_COMMIT)" \
-os=${OS} -arch=${ARCH} -osarch=${OSARCH} -output "${OUTPUT_DIR}/pkg/{{.OS}}_{{.Arch}}/{{.Dir}}" \
./cmd/tunnel ./cmd/tunneld

.PHONY: package
package:
mkdir ${OUTPUT_DIR}/dist
mkdir -p ${OUTPUT_DIR}/dist
cd ${OUTPUT_DIR}/pkg/; for osarch in *; do (cd $$osarch; tar zcvf ../../dist/tunnel_$$osarch.tar.gz ./*); done;
cd ${OUTPUT_DIR}/dist; sha256sum * > ./SHA256SUMS
cd ${OUTPUT_DIR}/dist; $(SHA256) * > ./SHA256SUMS

.PHONY: tags
tags: ; @ ## Used only for informations
@git log --simplify-by-decoration --decorate --pretty=oneline | fgrep 'tag: '

.PHONY: publish
publish:
ghr -recreate -u mmatczuk -t ${GITHUB_TOKEN} -r go-http-tunnel pre-release ${OUTPUT_DIR}/dist
publish: ; @ ## TODO: Setup GITHUB_USER and GITHUB_TOKEN on Environment Variables of Travis CI Repository Settings
ifeq ($(shell [[ ! -z "$(GITHUB_USER)" && ! -z "$(GITHUB_TOKEN)" ]] && echo true),true)
@echo "Uploading to GitHub Releases a pre-release version:"
@ghr -recreate -u ${GITHUB_USER} -t ${GITHUB_TOKEN} -r ${PACKAGE} -prerelease -n "v${GIT_TAG}" pre-release ${OUTPUT_DIR}/dist
else
@echo "Skipped. You need setup Travis CI Environment Variables."
endif

.PHONY: release
release: ; @ ## INFO: Use for publish release version
ifeq ($(shell [[ ! -z "$(GITHUB_USER)" && ! -z "$(GITHUB_TOKEN)" ]] && echo true),true)
@echo "Uploading to GitHub Releases a pre-release version:"
@ghr -recreate -u ${GITHUB_USER} -t ${GITHUB_TOKEN} -r ${PACKAGE} -n "v${GIT_TAG}" ${GIT_COMMIT} ${OUTPUT_DIR}/dist
else
@echo "Skipped. You need setup Travis CI Environment Variables."
endif