Skip to content

Commit

Permalink
Create script to automatically bump the version in .version (#147)
Browse files Browse the repository at this point in the history
Initialize the `script/` directory dedicated to scripts used during
development. The only script currently present automates the process of
updating the `.version` file for a release based on the argument that is
provided ('major', 'minor', or 'patch'). The Release Guidelines have
been updated to prefer the use of this script when creating a release,
maintaining the manual instructions in case the script doesn't work.

The script is intentionally given the MIT-0 (aka 'no attribution')
license identifier as the intent is for it to be easier to re-use, that
is without requiring attribution upon re-use. The intend is that all
homegrown scripts will use this less restrictive license.
  • Loading branch information
ericcornelissen authored Nov 19, 2023
1 parent ed686a6 commit 74adf96
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
/lib/**
!/lib/*.sh

## Script
!/script/
/script/**
!/script/*.sh

## Test
!/spec/
/spec/**
Expand Down
2 changes: 1 addition & 1 deletion .shellspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

## kcov (coverage)
--covdir _coverage/
--kcov-options "--exclude-pattern=/_coverage/,/_report/,/spec/,/.shellcheckrc,/.shellspec"
--kcov-options "--exclude-pattern=/_coverage/,/_report/,/script/,/spec/,/.shellcheckrc,/.shellspec"
--kcov-options "--include-path=. --path-strip-level=1"
--kcov-options "--include-pattern=.sh"
9 changes: 7 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ found in this file (using v0.1.2 as an example):
git clone git@github.com:ericcornelissen/tool-versions-update-action.git
```

1. Update the version number in the `.version` file following [Semantic
Versioning]:
1. Update the version number following [Semantic Versioning]:

```shell
./script/version-bump.sh [major|minor|patch]
```

Or edit the `.version` file manually:

```diff
- 0.1.1
Expand Down
34 changes: 34 additions & 0 deletions script/version-bump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# SPDX-License-Identifier: MIT-0

# --- Setup ------------------------------------------------------------------ #

set -eo pipefail

type="$1"

version=$(grep -o '[^-]*$' <.version)
major=$(echo "${version}" | cut -d. -f1)
minor=$(echo "${version}" | cut -d. -f2)
patch=$(echo "${version}" | cut -d. -f3)

# --- Script ----------------------------------------------------------------- #

if [[ "${type}" == "patch" ]]; then
patch=$((patch + 1))
elif [[ "${type}" == "minor" ]]; then
minor=$((minor + 1))
patch=0
elif [[ "${type}" == "major" ]]; then
major=$((major + 1))
minor=0
patch=0
elif [[ -z "${type}" ]]; then
echo "Provide an update type, one of 'major', 'minor', or 'patch'"
exit 1
else
echo "Unknown update type '${type}'"
exit 1
fi

echo "${major}.${minor}.${patch}" >.version

0 comments on commit 74adf96

Please sign in to comment.