-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from mrc-ide/version-check
Add scripts and workflows to manage version number
- Loading branch information
Showing
4 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
- main | ||
|
||
name: Check Version | ||
|
||
jobs: | ||
all: | ||
runs-on: ubuntu-latest | ||
|
||
name: Check Version | ||
|
||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Check version format and availability | ||
run: ./scripts/check_version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: orderly2 | ||
Title: Orderly Next Generation | ||
Version: 1.99.21 | ||
Version: 1.99.22 | ||
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"), | ||
email = "[email protected]"), | ||
person("Robert", "Ashton", role = "aut"), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env bash | ||
set -eu | ||
|
||
ACTION="${1:-patch}" | ||
CURRENT_VERSION=$(grep '^Version' DESCRIPTION | sed 's/.*: *//') | ||
MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1) | ||
MINOR=$(echo $CURRENT_VERSION | cut -d. -f2) | ||
PATCH=$(echo $CURRENT_VERSION | cut -d. -f3) | ||
echo "Current version: ${CURRENT_VERSION}" | ||
|
||
if [ $# -gt 1 ]; then | ||
echo "Invalid args" | ||
exit 1 | ||
fi | ||
|
||
case $ACTION in | ||
reset) | ||
echo "Resetting version" | ||
LAST_VERSION=$(git show origin/main:DESCRIPTION | grep '^Version' | sed 's/.*: *//') | ||
MAJOR=$(echo $LAST_VERSION | cut -d. -f1) | ||
MINOR=$(echo $LAST_VERSION | cut -d. -f2) | ||
PATCH=$(echo $LAST_VERSION | cut -d. -f3) | ||
;; | ||
major) | ||
echo "Updating major version" | ||
MAJOR=$(($MAJOR + 1)) | ||
MINOR=0 | ||
PATCH=0 | ||
;; | ||
minor) | ||
echo "Updating minor version" | ||
MINOR=$(($MINOR + 1)) | ||
PATCH=0 | ||
;; | ||
patch) | ||
echo "Updating patch version" | ||
PATCH=$(($PATCH + 1)) | ||
;; | ||
*) | ||
if echo "$ACTION" | grep -Eq "[0-9]+[.][0-9]+[.][0-9]+"; then | ||
echo "Updating version directly" | ||
MAJOR=$(echo $VERSION | cut -d. -f1) | ||
MINOR=$(echo $VERSION | cut -d. -f2) | ||
PATCH=$(echo $VERSION | cut -d. -f3) | ||
else | ||
echo "[ERROR] Invalid format version number '$VERSION' must be in format 'x.y.z'" | ||
exit 1 | ||
fi | ||
;; | ||
esac | ||
|
||
NEXT_VERSION="${MAJOR}.${MINOR}.${PATCH}" | ||
echo "Updating to version: ${NEXT_VERSION}" | ||
|
||
sed -i "s/^Version: .*$/Version: ${NEXT_VERSION}/" DESCRIPTION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
# Usage: | ||
# check_version [<version>] | ||
# | ||
# If version is not given as a positional argument, then we'll read it | ||
# from the DESCRIPTION file. | ||
# | ||
# We assume that a version already exists as a tag. | ||
VERSION=${1:-$(grep '^Version' DESCRIPTION | sed 's/.*: *//')} | ||
TAG="v${VERSION}" | ||
|
||
echo "Proposed version number '$VERSION'" | ||
|
||
if echo "$VERSION" | grep -Eq "[0-9]+[.][0-9]+[.][0-9]+"; then | ||
echo "[OK] Version number in correct format" | ||
else | ||
echo "[ERROR] Invalid format version number '$VERSION' must be in format 'x.y.z'" | ||
exit 1 | ||
fi | ||
|
||
EXIT_CODE=0 | ||
|
||
LAST_VERSION=$(git show origin/main:DESCRIPTION | grep '^Version' | sed 's/.*: *//') | ||
|
||
echo "Last version was '$LAST_VERSION'" | ||
|
||
MAJOR=$(echo $VERSION | cut -d. -f1) | ||
MINOR=$(echo $VERSION | cut -d. -f2) | ||
PATCH=$(echo $VERSION | cut -d. -f3) | ||
|
||
LAST_VERSION=$(echo "$LAST_VERSION" | sed 's/^v//') | ||
LAST_MAJOR=$(echo $LAST_VERSION | cut -d. -f1) | ||
LAST_MINOR=$(echo $LAST_VERSION | cut -d. -f2) | ||
LAST_PATCH=$(echo $LAST_VERSION | cut -d. -f3) | ||
|
||
if (( $MAJOR > $LAST_MAJOR )); then | ||
echo "[OK] ${VERSION} increases MAJOR version over old version ${LAST_VERSION}" | ||
elif (( $MINOR > $LAST_MINOR )); then | ||
echo "[OK] ${VERSION} increases MINOR version over old version ${LAST_VERSION}" | ||
elif (( $PATCH > $LAST_PATCH )); then | ||
echo "[OK] ${VERSION} increases PATCH version over old version ${LAST_VERSION}" | ||
else | ||
echo "[ERROR] Version number has not increased relative to $LAST_VERSION" | ||
EXIT_CODE=1 | ||
fi | ||
|
||
exit $EXIT_CODE |