Skip to content

Commit 8b06bf1

Browse files
committed
Add version check scripts
1 parent 6b7965a commit 8b06bf1

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

.github/workflows/check-version.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
on:
2+
pull_request:
3+
branches:
4+
- master
5+
- main
6+
7+
name: Check Version
8+
9+
jobs:
10+
all:
11+
runs-on: ubuntu-latest
12+
13+
name: Check Version
14+
15+
env:
16+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Check version format and availability
24+
run: ./scripts/check_version

scripts/check_version

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
# Usage:
4+
# check_version [<version>]
5+
#
6+
# If version is not given as a positional argument, then we'll read it
7+
# from the DESCRIPTION file.
8+
#
9+
# We assume that a version already exists as a tag.
10+
VERSION=${1:-$(grep '^Version' DESCRIPTION | sed 's/.*: *//')}
11+
TAG="v${VERSION}"
12+
13+
echo "Proposed version number '$VERSION'"
14+
15+
if echo "$VERSION" | grep -Eq "[0-9]+[.][0-9]+[.][0-9]+"; then
16+
echo "[OK] Version number in correct format"
17+
else
18+
echo "[ERROR] Invalid format version number '$VERSION' must be in format 'x.y.z'"
19+
exit 1
20+
fi
21+
22+
EXIT_CODE=0
23+
24+
LAST_VERSION=$(git show origin/main:DESCRIPTION | grep '^Version' | sed 's/.*: *//')
25+
26+
echo "Last version was '$LAST_VERSION'"
27+
28+
MAJOR=$(echo $VERSION | cut -d. -f1)
29+
MINOR=$(echo $VERSION | cut -d. -f2)
30+
PATCH=$(echo $VERSION | cut -d. -f3)
31+
32+
LAST_VERSION=$(echo "$LAST_VERSION" | sed 's/^v//')
33+
LAST_MAJOR=$(echo $LAST_VERSION | cut -d. -f1)
34+
LAST_MINOR=$(echo $LAST_VERSION | cut -d. -f2)
35+
LAST_PATCH=$(echo $LAST_VERSION | cut -d. -f3)
36+
37+
if (( $MAJOR > $LAST_MAJOR )); then
38+
echo "[OK] ${VERSION} increases MAJOR version over old version ${LAST_VERSION}"
39+
elif (( $MINOR > $LAST_MINOR )); then
40+
echo "[OK] ${VERSION} increases MINOR version over old version ${LAST_VERSION}"
41+
elif (( $PATCH > $LAST_PATCH )); then
42+
echo "[OK] ${VERSION} increases PATCH version over old version ${LAST_VERSION}"
43+
else
44+
echo "[ERROR] Version number has not increased relative to $LAST_VERSION"
45+
EXIT_CODE=1
46+
fi
47+
48+
exit $EXIT_CODE

0 commit comments

Comments
 (0)