diff --git a/Makefile b/Makefile index 951dd422..23290d37 100644 --- a/Makefile +++ b/Makefile @@ -107,6 +107,10 @@ build-docs: prepare mkdocs.yml mkdocs/* @find docs -type d -exec chmod 755 {} \; || : @find docs -type f -exec chmod 644 {} \; || : +.PHONY: release +release: xcompile + ${DOCKRUN} bash ./scripts/publish.sh + # ---------------------------------------------- # utilities diff --git a/Makefile.variables b/Makefile.variables index 5400b8ef..599eaa0b 100644 --- a/Makefile.variables +++ b/Makefile.variables @@ -8,6 +8,8 @@ LDFLAGS := LDFLAGS += -X main.GitCommit=${GIT_COMMIT}${GIT_DIRTY} LDFLAGS += -X main.GitDescribe=${GIT_DESCRIBE} +GITHUB_TOKEN ?= + # Windows environment? CYG_CHECK := $(shell hash cygpath 2>/dev/null && echo 1) ifeq ($(CYG_CHECK),1) @@ -29,6 +31,7 @@ DEV_IMAGE := ${PROJECT}_dev DOCKRUN := docker run --rm \ -e LDFLAGS="${LDFLAGS}" \ + -e GITHUB_TOKEN="${GITHUB_TOKEN}" \ -v ${ROOT}/vendor:/go/src \ -v ${ROOT}:/${PROJECT}/src/${IMPORT_PATH} \ -w /${PROJECT}/src/${IMPORT_PATH} \ diff --git a/scripts/devtools.sh b/scripts/devtools.sh index ed2d6e4a..6024d31a 100755 --- a/scripts/devtools.sh +++ b/scripts/devtools.sh @@ -4,6 +4,7 @@ go get -u github.com/alecthomas/gometalinter go get -u golang.org/x/tools/cmd/goimports go get -u github.com/mitchellh/gox go get -u github.com/kardianos/govendor +go get -u github.com/aktau/github-release # install all the linters gometalinter --install --update diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100755 index 00000000..09e8a054 --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +GITHUB_TOKEN="${GITHUB_TOKEN:?missing required input \'GITHUB_TOKEN\'}" + +CURRENT="$(git describe --tags --abbrev=0)" +PREVIOUS="$(git describe --tags --abbrev=0 --always "${CURRENT}"^)" +OWNER="mikefarah" +REPO="yaml" + +release() { + mapfile -t logs < <(git log --pretty=oneline --abbrev-commit "${PREVIOUS}".."${CURRENT}") + description="$(printf '%s\n' "${logs[@]}")" + github-release release \ + --user "$OWNER" \ + --repo "$REPO" \ + --tag "$CURRENT" \ + --description "$description" || + github-release edit \ + --user "$OWNER" \ + --repo "$REPO" \ + --tag "$CURRENT" \ + --description "$description" +} + +upload() { + mapfile -t files < <(find ./build -mindepth 1 -maxdepth 1) + for file in "${files[@]}"; do + BINARY=$(basename "${file}") + echo "--> ${BINARY}" + github-release upload \ + --user "$OWNER" \ + --repo "$REPO" \ + --tag "$CURRENT" \ + --name "${BINARY}" \ + --file "$file" + done +} + +release +upload