Skip to content

Commit

Permalink
Merge pull request #50 from mrc-ide/mrc-4863
Browse files Browse the repository at this point in the history
Add script to check version numbers
  • Loading branch information
weshinsley authored Jan 3, 2024
2 parents f91c29d + a90185d commit 49b8f6c
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/check-version.yml
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: hipercow
Title: High Performance Computing
Version: 0.1.0
Version: 0.2.0
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "[email protected]"),
person("Wes", "Hinsley", role = "aut"),
Expand Down
2 changes: 1 addition & 1 deletion drivers/windows/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: hipercow.windows
Title: DIDE HPC Support for Windows
Version: 0.1.0
Version: 0.2.0
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "[email protected]"),
person("Wes", "Hinsley", role = "aut"),
Expand Down
56 changes: 56 additions & 0 deletions scripts/check_version
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/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

WINDOWS_VERSION=$(grep '^Version' drivers/windows/DESCRIPTION | sed 's/.*: *//')
if [[ $WINDOWS_VERSION == $VERSION ]]; then
echo "[OK] windows driver version agrees"
else
echo "[ERROR] windows driver version (${WINDOWS_VERSION}) disagrees with this version (${VERSION})"
EXIT_CODE=1
fi

exit $EXIT_CODE

0 comments on commit 49b8f6c

Please sign in to comment.