From 370365a7ae7b6102dd31eec19f4bccd32eed690a Mon Sep 17 00:00:00 2001 From: Miikka Koskinen Date: Tue, 5 May 2020 19:31:20 +0300 Subject: [PATCH] Add a script for making releases --- docs/11_developer_guide.md | 17 ++++++++++ project.clj | 3 +- scripts/release.sh | 69 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 docs/11_developer_guide.md create mode 100755 scripts/release.sh diff --git a/docs/11_developer_guide.md b/docs/11_developer_guide.md new file mode 100644 index 00000000..02e4b9b3 --- /dev/null +++ b/docs/11_developer_guide.md @@ -0,0 +1,17 @@ +# Developer guide + +## Running tests + +```sh +./scripts/test.sh clj +./scripts/test.sh cljs +``` + + +## Creating a release + +1. Update `CHANGELOG.md` +2. Set the appropriate version in `project.clj` and commit and push. +3. Run `./scripts/release.sh` + +The actual building of the release artifact is done by the CI service. diff --git a/project.clj b/project.clj index bd74dad0..f3fc6a06 100644 --- a/project.clj +++ b/project.clj @@ -25,7 +25,8 @@ [lein-doo "0.1.11"] [lein-cljsbuild "1.1.7"] [lein-cloverage "1.1.1"] - [lein-codox "0.10.7"]] + [lein-codox "0.10.7"] + [lein-pprint "1.3.2"]] :jvm-opts ^:replace ["-server"] ;:global-vars {*warn-on-reflection* true} :dependencies [[org.clojure/clojure "1.10.0"] diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 00000000..b2b043a1 --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +# Release a new version + +set -euo pipefail + +if ! hub version > /dev/null; then + echo "The hub tool is needed. If you're on macOS, you can install it with \`brew install hub\`" + exit 1 +fi + +BRANCH=$(git rev-parse --abbrev-ref HEAD) + +if [[ "$BRANCH" != "master" ]]; then + echo "This script only works in the master branch." + exit 1 +fi + +if ! git diff-index --quiet HEAD -- project.clj; then + echo "project.clj contains uncommited changes. Commit them first." + exit 1 +fi + +if ! git merge-base --is-ancestor "master@{u}" master; then + echo "The master branch has not been pushed. Please git push." + exit 1 +fi + +VERSION=$(lein pprint --no-pretty -- :version) + +echo "Version in project.clj: $VERSION" + +case "$VERSION" in + *-SNAPSHOT) + echo "" + echo "SNAPSHOT releases are not supported. You can \`lein deploy\` them yourself." + exit 1 + ;; +esac + +echo "Going to release version $VERSION... is this correct? [y/n]" + +read -r answer +case "$answer" in + y | Y | yes | YES) + ;; + *) + echo "Exiting" + exit 1 + ;; +esac + +if hub release show "$VERSION" 2>/dev/null; then + echo + echo "Release $VERSION already exists" + exit 1 +else + echo "* Release $VERSION does not yet exist" +fi + +# Let's just check if the chanelog contains an appropriate title +if ! grep -q -F "# $VERSION " CHANGELOG.md; then + echo + echo "Please update CHANGELOG to contain the release $VERSION" + exit 1 +else + echo "* Changelog has been updated" +fi + +hub release create -m "$VERSION" "$VERSION"