Skip to content

Commit

Permalink
Automate release process a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
doronbehar committed Dec 1, 2021
1 parent 006631e commit b8d3ce4
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 14 deletions.
22 changes: 8 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
80 changes: 80 additions & 0 deletions bump-version.sh
Original file line number Diff line number Diff line change
@@ -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."
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
# Evaluated but not used for the build itself
"gomod2nix.toml"
"VERSION"
"bump-version.sh"
# CI files
"renovate.json5"
# Git files
Expand Down

0 comments on commit b8d3ce4

Please sign in to comment.