Enhance release scripts

This commit is contained in:
Khosrow Moossavi
2019-12-12 16:05:36 -05:00
parent b166b982ad
commit d03bfc94aa
4 changed files with 34 additions and 33 deletions

View File

@@ -92,8 +92,8 @@ build: clean ## Build binary for current OS/ARCH
$(GOBUILD) -o ./$(BUILD_DIR)/$(GOOS)-$(GOARCH)/$(NAME)
.PHONY: build-all
build-all: GOOS = linux darwin windows freebsd
build-all: GOARCH = amd64 arm
build-all: GOOS = linux darwin windows freebsd
build-all: GOARCH = amd64 arm
build-all: clean ## Build binary for all OS/ARCH
@ $(MAKE) --no-print-directory log-$@
@ ./scripts/build/build-all-osarch.sh "$(BUILD_DIR)" "$(NAME)" "$(VERSION)" "$(GOOS)" "$(GOARCH)" $(GOLDFLAGS)

View File

@@ -7,7 +7,8 @@ import (
"time"
)
const dev = "dev"
// current version
const dev = "v0.7.0-alpha"
// Provisioned by ldflags
var (

View File

@@ -30,7 +30,7 @@ CGO_ENABLED=0 gox \
-osarch="!darwin/arm" \
-output="${BUILD_DIR}/{{.OS}}-{{.Arch}}/{{.Dir}}" ${PWD}/../../
printf "\033[36m==> Compress binary\033[0m\n"
printf "\033[36m==> Finalize binary\033[0m\n"
for platform in $(find ${BUILD_DIR} -mindepth 1 -maxdepth 1 -type d); do
OSARCH=$(basename ${platform})
@@ -38,23 +38,13 @@ for platform in $(find ${BUILD_DIR} -mindepth 1 -maxdepth 1 -type d); do
case "${OSARCH}" in
"windows"*)
if ! command -v zip >/dev/null; then
echo "Error: cannot compress, 'zip' not found"
exit 1
fi
zip -q -j ${BUILD_DIR}/${FULLNAME}.zip ${platform}/${NAME}.exe
printf -- "--> %15s: bin/%s\n" "${OSARCH}" "${FULLNAME}.zip"
mv ${platform}/${NAME}.exe ${BUILD_DIR}/${FULLNAME}.exe
printf -- "--> %15s: bin/%s\n" "${OSARCH}" "${FULLNAME}.exe"
;;
*)
if ! command -v tar >/dev/null; then
echo "Error: cannot compress, 'tar' not found"
exit 1
fi
tar -czf ${BUILD_DIR}/${FULLNAME}.tar.gz --directory ${platform}/ ${NAME}
printf -- "--> %15s: bin/%s\n" "${OSARCH}" "${FULLNAME}.tar.gz"
mv ${platform}/${NAME} ${BUILD_DIR}/${FULLNAME}
printf -- "--> %15s: bin/%s\n" "${OSARCH}" "${FULLNAME}"
;;
esac

View File

@@ -3,6 +3,17 @@
set -o errexit
set -o pipefail
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ -z "${CURRENT_BRANCH}" -o "${CURRENT_BRANCH}" != "master" ]; then
echo "Error: The current branch is '${CURRENT_BRANCH}', switch to 'master' to do the release."
exit 1
fi
if [ -n "$(git status --short)" ]; then
echo "Error: There are untracked/modified changes, commit or discard them before the release."
exit 1
fi
RELEASE_VERSION=$1
CURRENT_VERSION=$2
FROM_MAKEFILE=$3
@@ -21,7 +32,12 @@ if [ -z "${CURRENT_VERSION}" ]; then
fi
if [ "v${RELEASE_VERSION}" = "${CURRENT_VERSION}" ]; then
echo "Error: provided version (v${version}) exists."
echo "Error: provided version (v${RELEASE_VERSION}) already exists."
exit 1
fi
if [ $(git describe --tags "v${RELEASE_VERSION}" 2>/dev/null) ]; then
echo "Error: provided version (v${RELEASE_VERSION}) already exists."
exit 1
fi
@@ -30,24 +46,18 @@ CLOSEST_VERSION=$(git describe --tags --abbrev=0)
# Bump the released version in README and version.go
sed -i -E 's|'${CLOSEST_VERSION}'|v'${RELEASE_VERSION}'|g' README.md
sed -i -E 's|'${CLOSEST_VERSION}'-alpha|v'${RELEASE_VERSION}'|g' cmd/rostamctl/version/version.go
sed -i -E 's|v'${RELEASE_VERSION}'-alpha|v'${RELEASE_VERSION}'|g' internal/pkg/version/version.go
# Commit changes
printf "\033[36m==> %s\033[0m\n" "Commit changes for release version v${RELEASE_VERSION}"
git add README.md cmd/rostamctl/version/version.go
git add README.md internal/pkg/version/version.go
git commit -m "Release version v${RELEASE_VERSION}"
printf "\033[36m==> %s\033[0m\n" "Push commits for v${RELEASE_VERSION}"
git push origin master
# Temporary tag the release to generate the changelog
git tag --annotate --message "v${RELEASE_VERSION} Release" "v${RELEASE_VERSION}"
# Generate Changelog
make --no-print-directory -f ${PWD}/../../Makefile changelog
# Delete the temporary tag and create it again to include the just generated changelog
git tag -d "v${RELEASE_VERSION}"
make --no-print-directory -f ${PWD}/../../Makefile changelog next="--next-tag v${RELEASE_VERSION}"
# Tag the release
printf "\033[36m==> %s\033[0m\n" "Tag release v${RELEASE_VERSION}"
@@ -58,12 +68,12 @@ git push origin v${RELEASE_VERSION}
# Bump the next version in version.go
NEXT_VERSION=$(echo "${RELEASE_VERSION}" | sed 's/^v//' | awk -F'[ .]' '{print $1"."$2+1".0"}')
sed -i -E 's|'${RELEASE_VERSION}'|'${NEXT_VERSION}'-alpha|g' cmd/rostamctl/version/version.go
sed -i -E 's|v'${RELEASE_VERSION}'|v'${NEXT_VERSION}'-alpha|g' internal/pkg/version/version.go
# Commit changes
printf "\033[36m==> %s\033[0m\n" "Bump version to ${NEXT_VERSION}-alpha"
git add cmd/rostamctl/version/version.go
git commit -m "Bump version to ${NEXT_VERSION}-alpha"
printf "\033[36m==> %s\033[0m\n" "Bump version to v${NEXT_VERSION}-alpha"
git add internal/pkg/version/version.go
git commit -m "Bump version to v${NEXT_VERSION}-alpha"
printf "\033[36m==> %s\033[0m\n" "Push commits for ${NEXT_VERSION}-alpha"
printf "\033[36m==> %s\033[0m\n" "Push commits for v${NEXT_VERSION}-alpha"
git push origin master