Skip to content

Commit

Permalink
rename the released binary name and remove top level dir in the relea…
Browse files Browse the repository at this point in the history
…se archive
  • Loading branch information
mbenabda authored and Mehdi BEN ABDALLAH committed Feb 23, 2018
1 parent 7558823 commit 0991e07
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 38 deletions.
1 change: 1 addition & 0 deletions .build_targets
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
darwin/amd64 linux/amd64 linux/386 windows/amd64
18 changes: 8 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ PROJECT_GH=mbenabda/$(PROJECT_NAME)
PKG:= github.com/$(PROJECT_GH)

HELM_HOME ?= $(shell helm home)
VERSION := $(shell sed -n -e 's/version:[ "]*\([^"]*\).*/\1/p' plugin.yaml)
TARGETS ?= darwin/amd64 linux/amd64 linux/386 windows/amd64
VERSION ?= $(shell sed -n -e 's/version:[ "]*\([^"]*\).*/\1/p' plugin.yaml)
TARGETS ?= $(shell cat .build_targets)

LDFLAGS := -X main.Version=$(VERSION)
# Clear the "unreleased" string in BuildMetadata
Expand All @@ -17,12 +17,11 @@ clean:
@rm -rf $(PROJECT_BIN_NAME) ./build ./dist

.PHONY: build-cross
build-cross: LDFLAGS += -extldflags "-static"
build-cross: LDFLAGS += -s -w -extldflags "-static"
build-cross:
CGO_ENABLED=0 gox \
-verbose \
-parallel=3 \
-output="dist/{{.OS}}-{{.Arch}}/{{.Dir}}" \
-output="dist/$(PROJECT_NAME)-{{.OS}}-{{.Arch}}/$(PROJECT_BIN_NAME)" \
-ldflags "$(LDFLAGS)" \
-osarch="$(TARGETS)" \
$(PKG)
Expand All @@ -32,9 +31,9 @@ dist: export COPYFILE_DISABLE=1 #teach OSX tar to not put ._* files in tar archi
dist:
( \
cd dist && \
find * -type d -exec cp ../README.md {} \; && \
find * -type d -exec cp ../plugin.yaml {} \; && \
find * -type d -exec tar -zcf ${PROJECT_BIN_NAME}-${VERSION}-{}.tgz {} \; \
find * -maxdepth 1 -type d -exec cp ../README.md {} \; && \
find * -maxdepth 1 -type d -exec cp ../plugin.yaml {} \; && \
ls -d * | xargs -I {} -n1 bash -c "cd {} && tar -zcf ../{}.tgz * && cd .." \
)

HAS_GLIDE := $(shell command -v glide;)
Expand Down Expand Up @@ -68,9 +67,8 @@ install: bootstrap build
cp ${PROJECT_BIN_NAME} $(HELM_HOME)/plugins/${PROJECT_NAME}/
cp plugin.yaml $(HELM_HOME)/plugins/${PROJECT_NAME}/

# usage: make clean bootstrap build-cross dist release
.PHONY: release
release: dist
release: clean bootstrap build-cross dist
ifndef GITHUB_TOKEN
$(error GITHUB_TOKEN is undefined)
endif
Expand Down
46 changes: 19 additions & 27 deletions install-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if [[ $SKIP_BIN_INSTALL == "1" ]]; then
exit
fi

# initArch discovers the architecture for this system.
# Discover the architecture for this system.
initArch() {
ARCH=$(uname -m)
case $ARCH in
Expand All @@ -54,7 +54,7 @@ initArch() {
esac
}

# initOS discovers the operating system for this system.
# Discover the operating system for this system.
initOS() {
OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')

Expand All @@ -66,38 +66,33 @@ initOS() {
esac
}

# verifySupported checks that the os/arch combination is supported for
# binary builds.
verifySupported() {
local supported="darwin-amd64\nlinux-amd64\nlinux-386\nwindows-amd64"
if ! echo "${supported}" | grep -q "${OS}-${ARCH}"; then
echo "No prebuilt binary for ${OS}-${ARCH}."
exit 1
fi

# Figure out the download url for the latest available version.
getDownloadURL() {
if ! type "curl" > /dev/null && ! type "wget" > /dev/null; then
echo "Either curl or wget is required"
exit 1
fi
}

# getDownloadURL checks the latest available version.
getDownloadURL() {
local url="https://api.github.com/repos/$PROJECT_GH/releases/latest"
local url="https://api.github.com/repos/${PROJECT_GH}/releases/latest"
local version=$(git describe --tags --exact-match 2>/dev/null)
if [ -n "$version" ]; then
url="https://api.github.com/repos/$PROJECT_GH/releases/tags/$version"
url="https://api.github.com/repos/${PROJECT_GH}/releases/tags/${version}"
fi

# Use the GitHub API to find the download url for this project.
if type "curl" > /dev/null; then
DOWNLOAD_URL=$(curl -v -s $url | grep $OS | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}')
DOWNLOAD_URL=$(curl -v -s $url | grep "${OS}-${ARCH}" | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}')
elif type "wget" > /dev/null; then
DOWNLOAD_URL=$(wget -q -O - $url | grep $OS | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}')
DOWNLOAD_URL=$(wget -q -O - $url | grep "${OS}-${ARCH}" | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}')
fi

if ! echo "${DOWNLOAD_URL}" | grep -q "${OS}-${ARCH}"; then
echo "No prebuilt binary for ${OS}-${ARCH}."
exit 1
fi
}

# downloadFile downloads the latest binary package and also the checksum
# for that binary.
# Download the plugin package.
downloadFile() {
PLUGIN_TMP_FILE="/tmp/${PROJECT_NAME}.tgz"
echo "Downloading $DOWNLOAD_URL"
Expand All @@ -108,18 +103,16 @@ downloadFile() {
fi
}

# installFile verifies the SHA256 for the file, then unpacks and
# installs it.
# Unpack and install the helm plugin
installFile() {
HELM_TMP="/tmp/$PROJECT_NAME"
mkdir -p "$HELM_TMP"
tar xf "$PLUGIN_TMP_FILE" -C "$HELM_TMP"
HELM_TMP_BIN="$HELM_TMP/${PROJECT_NAME}/${PROJECT_BIN_NAME}"
echo "Preparing to install into ${HELM_PLUGIN_PATH}"
cp "$HELM_TMP_BIN" "$HELM_PLUGIN_PATH"
cp -r "$HELM_TMP" "$HELM_PLUGIN_PATH"
}

# fail_trap is executed if an error occurs.
# Executed if an error occurs.
fail_trap() {
result=$?
if [ "$result" != "0" ]; then
Expand All @@ -129,7 +122,7 @@ fail_trap() {
exit $result
}

# testVersion tests the installed client to make sure it is working.
# Use the installed plugin's binary to make sure it is working.
testVersion() {
set +e
echo "$PROJECT_NAME installed into $HELM_PLUGIN_PATH/$PROJECT_BIN_NAME"
Expand All @@ -144,7 +137,6 @@ trap "fail_trap" EXIT
set -e
initArch
initOS
verifySupported
getDownloadURL
downloadFile
installFile
Expand Down
2 changes: 1 addition & 1 deletion plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "local-chart-version"
version: "0.0.1"
usage: "local-chart-version [subcommand] LOCAL_CHART_DIRECTORY [flags]"
description: |-
Helm plugin for bumping/manually setting the version number of a local helm chart
Helm plugin for setting/bumping the version number of a local chart
Usage: "local-chart-version [subcommand] LOCAL_CHART_DIRECTORY [flags]"
command: "$HELM_PLUGIN_DIR/local-chart-version"
hooks:
Expand Down

0 comments on commit 0991e07

Please sign in to comment.