From b8d3ce4bdf067f682544a7f26ef4b5b65ecb4ec2 Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Wed, 1 Dec 2021 16:34:41 +0200 Subject: [PATCH] Automate release process a bit --- Makefile | 22 +++++--------- bump-version.sh | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 1 + 3 files changed, 89 insertions(+), 14 deletions(-) create mode 100755 bump-version.sh diff --git a/Makefile b/Makefile index 4cf54ea..03289a4 100644 --- a/Makefile +++ b/Makefile @@ -10,13 +10,17 @@ else MAGIC_DB := /usr/share/misc/magic.mgc endif +pistol: build + build: go build -ldflags "-X 'main.Version=$(VERSION)'" ./cmd/pistol + build-static: - @echo copying magic db for compilation from: - @echo " $(MAGIC_DB)" - @cp --no-preserve=mode,ownership -f $(MAGIC_DB) ./cmd/pistol/magic.mgc - go build -tags EMBED_MAGIC_DB -ldflags "-X 'main.Version=$(VERSION)'" ./cmd/pistol + nix build -L ".#pistol-static" + ldd ./result/bin/pistol 2>&1 | grep -q 'not a dynamic executable' + +release: + ./bump-version.sh # Manpage pistol.1: README.adoc @@ -78,14 +82,4 @@ test: pistol @echo ------------------- @./pistol --config tests/config tests/multi-extra A B -deps: - go get github.com/c4milo/github-release - go get github.com/mitchellh/gox - -changelog: - @latest_tag=$$(git describe --tags `git rev-list --tags --max-count=1`); \ - comparison="$$latest_tag..HEAD"; \ - if [ -z "$$latest_tag" ]; then comparison=""; fi; \ - git --no-pager log $$comparison --oneline --no-merges - .PHONY: build install changelog diff --git a/bump-version.sh b/bump-version.sh new file mode 100755 index 0000000..19ca171 --- /dev/null +++ b/bump-version.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash + +# Thanks goes to @pete-otaqui for the initial gist: +# https://gist.github.com/pete-otaqui/4188238 +# +# Original version modified by Marek Suscak +# +# works with a file called VERSION in the current directory, +# the contents of which should be a semantic version number +# such as "1.2.3" or even "1.2.3-beta+001.ab" + +# this script will display the current version, automatically +# suggest a "minor" version update, and ask for input to use +# the suggestion, or a newly entered value. + +# once the new version number is determined, the script will +# pull a list of changes from git history, prepend this to +# a file called CHANGELOG.md (under the title of the new version +# number), give user a chance to review and update the changelist +# manually if needed and create a GIT tag. + +set -eu + +NOW="$(date +'%B %d, %Y')" +RED="\033[1;31m" +GREEN="\033[0;32m" +YELLOW="\033[1;33m" +BLUE="\033[1;34m" +PURPLE="\033[1;35m" +CYAN="\033[1;36m" +WHITE="\033[1;37m" +RESET="\033[0m" + +QUESTION_FLAG="${GREEN}?" +WARNING_FLAG="${YELLOW}!" +NOTICE_FLAG="${CYAN}❯" + +ADJUSTMENTS_MSG="${QUESTION_FLAG} ${CYAN}Now you can make adjustments to ${WHITE}CHANGELOG.md${CYAN}. Then press enter to continue." +PUSHING_MSG="${NOTICE_FLAG} Pushing new version to the ${WHITE}origin${CYAN}..." + +if [ -f VERSION ]; then + BASE_STRING=`cat VERSION` + BASE_LIST=(`echo $BASE_STRING | tr '.' ' '`) + V_MAJOR=${BASE_LIST[0]} + V_MINOR=${BASE_LIST[1]} + V_PATCH=${BASE_LIST[2]} + echo -e "${NOTICE_FLAG} Current version: ${WHITE}$BASE_STRING" + SUGGESTED_VERSION="$V_MAJOR.$V_MINOR.$((V_PATCH + 1))" + echo -ne "${QUESTION_FLAG} ${CYAN}Enter a version number [${WHITE}$SUGGESTED_VERSION${CYAN}]: " + read INPUT_STRING + if [ "$INPUT_STRING" = "" ]; then + INPUT_STRING=$SUGGESTED_VERSION + fi + echo -e "${NOTICE_FLAG} Will set new version to be ${WHITE}$INPUT_STRING" + echo $INPUT_STRING > VERSION + git add VERSION + git commit -m "Bump version to ${INPUT_STRING}." + git tag -a -m "v$INPUT_STRING" "v$INPUT_STRING" + if git status --short | grep -q '*'; then + echo -e "${WARNING_FLAG} Git directory is dirty, refusing to compile pistol-static." >&2 + exit 2 + fi + nix build -L ".#pistol-static" + echo -e "${NOTICE_FLAG} Checking that the produced executable is not a dynamically linked" + ldd ./result/bin/pistol 2>&1 | grep 'not a dynamic executable' + echo -e "${NOTICE_FLAG} Checking that the produced executable has the version string compiled into it" + ./result/bin/pistol --version | grep $INPUT_STRING + # TODO: Support more executables once cross compilation works. + # https://cli.github.com/manual/gh_release_create + git log --pretty=format:" - %s" "v$INPUT_STRING"...HEAD | tee | gh release create v$INPUT_STRING \ + --notes-file - \ + './result/bin/pistol#pistol-x86_64' \ + ./result/share/man/man1/pistol.1.gz + git push origin --tags +else + echo -e "${WARNING_FLAG} Could not find a VERSION file." >&2 + exit 1 +fi + +echo -e "${NOTICE_FLAG} Finished." diff --git a/flake.nix b/flake.nix index 78836f0..36ca1b1 100644 --- a/flake.nix +++ b/flake.nix @@ -65,6 +65,7 @@ # Evaluated but not used for the build itself "gomod2nix.toml" "VERSION" + "bump-version.sh" # CI files "renovate.json5" # Git files