Skip to content

Commit 727e9cc

Browse files
authored
feat: Enable pre-release versioning (#212)
1 parent 9edac63 commit 727e9cc

File tree

7 files changed

+124
-18
lines changed

7 files changed

+124
-18
lines changed

.github/workflows/check-deploy-test-project.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ jobs:
3131
- name: Setup runner
3232
uses: ./actions/common-prerequisites
3333

34-
- name: Increment the release version using Conventional Commits
34+
- name: Increment the pre-release version using Conventional Commits
35+
uses: ./actions/increment-version
36+
with:
37+
pre-release-type: alpha
38+
39+
- name: Increment the stable version using Conventional Commits
3540
id: versioning
3641
uses: ./actions/increment-version
3742

actions/common-prerequisites/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ runs:
1616
cache: gradle
1717

1818
- name: Install Cocogitto
19-
uses: cocogitto/cocogitto-action@c7a74f5406bab86da17da0f0e460a69f8219a68c # v3.11
19+
uses: cocogitto/cocogitto-action@9a9fe03b31c47444290c0d7f9b1ee1b44ee13f20 # v4.1.0
2020
with:
21-
check: false
21+
command: help # A no-op command
2222

2323
- name: Set up Homebrew
2424
id: set-up-homebrew
Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,65 @@
11
name: 'Increment version'
2-
description: 'Increment the release version using Conventional Commits'
2+
description: |
3+
Increment the release version based on Conventional Commits.
4+
5+
If there are releasable changes (e.g. fix or feature commits) since the
6+
previous release then this action will tag a new version.
7+
8+
If there are no releasable changes (e.g. only ci or docs commits) since the
9+
previous release, this action does nothing.
10+
inputs:
11+
pre-release-type:
12+
type: string
13+
required: false
14+
description: |
15+
The pre-release version type, for example "alpha".
16+
17+
A numeric identifier will be appended and incremented automatically.
318
419
outputs:
520
current_version:
6-
description: 'current semantic version'
21+
description: |
22+
The semantic version, prior to the version increment.
23+
24+
If a pre-release version is supplied to the action, and the latest
25+
version was a pre-release, this will be a pre-release.
726
value: ${{ steps.versioning.outputs.current_version }}
827
new_version:
9-
description: 'new semantic version'
28+
description: |
29+
If this action bumped the version, this is the new version.
30+
31+
If this action didn't bump the version, this will be the same as the
32+
current version.
33+
34+
If a pre-release version is supplied to the action, this may be a
35+
new pre-release.
1036
value: ${{ steps.versioning.outputs.new_version }}
1137

1238
runs:
1339
using: "composite"
1440
steps:
15-
- name: Increment the release version using Conventional Commits
16-
id: versioning
41+
- name: Configure Git user
1742
run: |
1843
git config user.name github-actions
1944
git config user.email github-actions@github.com
45+
shell: bash
2046

21-
current_version=$(cog -v get-version)
22-
echo "current_version=$current_version" >> $GITHUB_OUTPUT
47+
- name: Set Github Action path
48+
run: echo "$GITHUB_ACTION_PATH" >> $GITHUB_PATH
49+
shell: bash
50+
env:
51+
GITHUB_ACTION_PATH: ${{ github.action_path }}
2352

24-
cog bump --auto
53+
- name: Calculate the pre-release version
54+
id: pre-release
55+
if: ${{ inputs.pre-release-type != '' }}
56+
run: calculate_prerelease.bash "$PRE_RELEASE_TYPE" >> $GITHUB_OUTPUT
57+
shell: bash
58+
env:
59+
PRE_RELEASE_TYPE: ${{ inputs.pre-release-type }}
2560

26-
new_version=$(cog -v get-version)
27-
echo "new_version=$new_version" >> $GITHUB_OUTPUT
28-
shell: bash
61+
- name: Increment the release version using Conventional Commits
62+
run: increment_version.bash "$PRE_RELEASE" >> $GITHUB_OUTPUT
63+
shell: bash
64+
env:
65+
PRE_RELEASE: ${{ steps.pre-release.outputs.version }}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
if [ $# -ne 1 ]; then
4+
echo "Usage: calculate_prerelease.bash <PRE_RELEASE_TYPE>" >&2
5+
echo "Example: calculate_prerelease.bash alpha" >&2
6+
exit 1
7+
fi
8+
9+
prerelease_type="$1"
10+
11+
echo "Calculating the next pre-release version" >&2
12+
13+
# Only increment the pre-release if there are changes to release
14+
next_stable_version=$(cog bump --auto --dry-run --skip-untracked)
15+
if [ "$next_stable_version" == "" ]; then
16+
echo "There's nothing to release" >&2
17+
exit 0
18+
fi
19+
echo "Next stable version would be $next_stable_version" >&2
20+
21+
# Get the latest pre-release (if any)
22+
cur_prerelease_version=$(
23+
cog -v get-version --tag --include-prereleases |
24+
grep "$prerelease_type"
25+
)
26+
echo "Latest pre-release version: ${cur_prerelease_version:-none}" >&2
27+
28+
# Start or increment the pre-release number
29+
if [[ "$cur_prerelease_version" =~ ${prerelease_type}\.([0-9]+) ]]; then
30+
cur_prerelease_number=${BASH_REMATCH[1]}
31+
next_prerelease_number=$((cur_prerelease_number + 1))
32+
echo "Incrementing $prerelease_type: $cur_prerelease_number -> $next_prerelease_number" >&2
33+
else
34+
echo "Starting a new $prerelease_type sequence" >&2
35+
next_prerelease_number=1
36+
fi
37+
38+
# Output is formatted for Github Actions step output
39+
# E.g. version=alpha.123
40+
echo "version=$prerelease_type.$next_prerelease_number"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
pre_release=$1
4+
5+
if [[ -n "${pre_release:-}" ]]; then
6+
echo "This is a pre-release: $pre_release" >&2
7+
cog_get_version_flags=(--include-prereleases)
8+
cog_bump_flags=(--auto --pre "$pre_release" --skip-untracked)
9+
else
10+
echo "This is a not a pre-release" >&2
11+
cog_get_version_flags=()
12+
cog_bump_flags=(--auto --skip-untracked)
13+
fi
14+
15+
echo "cog_get_version_flags=${cog_get_version_flags[*]}" >&2
16+
echo "cog_bump_flags=${cog_bump_flags[*]}" >&2
17+
18+
current_version=$(cog -v get-version "${cog_get_version_flags[@]}")
19+
cog bump "${cog_bump_flags[@]}"
20+
new_version=$(cog -v get-version "${cog_get_version_flags[@]}")
21+
22+
# Output is formatted for Github Actions step output
23+
echo "current_version=$current_version"
24+
echo "new_version=$new_version"

actions/setup-runner/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ runs:
4242
shell: bash
4343

4444
- name: Install cocogitto
45-
uses: cocogitto/cocogitto-action@c7a74f5406bab86da17da0f0e460a69f8219a68c # v3.11
45+
uses: cocogitto/cocogitto-action@9a9fe03b31c47444290c0d7f9b1ee1b44ee13f20 # v4.1.0
4646
with:
47-
check: false
47+
command: help # A no-op command
4848

4949
- name: Install KVM hardware acceleration Dependencies
5050
# see docs: https://help.ubuntu.com/community/KVM/Installation

actions/verify-conventional-commit/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ runs:
55
using: "composite"
66
steps:
77
- name: Install Cocogitto
8-
uses: cocogitto/cocogitto-action@c7a74f5406bab86da17da0f0e460a69f8219a68c # v3.11
8+
uses: cocogitto/cocogitto-action@9a9fe03b31c47444290c0d7f9b1ee1b44ee13f20 # v4.1.0
99
with:
10-
check: false
10+
command: help # A no-op command
1111

1212
- name: Verify Conventional commit standards against latest git tag
1313
run: cog check -l

0 commit comments

Comments
 (0)