-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cd: create GH Actions workflow to prepare release on dispatch
- Loading branch information
1 parent
4a18372
commit 5e11378
Showing
2 changed files
with
108 additions
and
0 deletions.
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,67 @@ | ||
#!/usr/bin/python3 | ||
import re | ||
import subprocess | ||
import sys | ||
|
||
|
||
def get_first_arg() -> str: | ||
# First arg can/should be `MAJOR`, `MINOR` or `PATCH` | ||
return sys.argv[1] | ||
|
||
|
||
def get_current_version() -> str: | ||
current_version = subprocess.run( | ||
"mvn help:evaluate -Dexpression=project.version -q -DforceStdout", | ||
shell=True, capture_output=True, text=True) | ||
return current_version.stdout | ||
|
||
|
||
def get_new_version(release_type: str, current_version: str) -> str: | ||
major, minor, patch = dissect_version(current_version) | ||
|
||
match release_type: | ||
case "MAJOR": | ||
major, minor, patch = get_major_release(major) | ||
case "MINOR": | ||
major, minor, patch = get_minor_release(major, minor) | ||
case "PATCH": | ||
major, minor, patch = get_patch_release(major, minor, patch) | ||
|
||
return str(major) + "." + str(minor) + "." + str(patch) | ||
|
||
|
||
def dissect_version(current_version) -> (int, int, int): | ||
version_regex = re.compile( | ||
r'^(?P<major>[0-9]+)\.(?P<minor>[0-9+])\.(?P<patch>[0-9+])(-SNAPSHOT)*') | ||
regex_match = version_regex.search(current_version) | ||
major: int = int(regex_match.groupdict().get("major")) | ||
minor: int = int(regex_match.groupdict().get("minor")) | ||
patch: int = int(regex_match.groupdict().get("patch")) | ||
return major, minor, patch | ||
|
||
|
||
def get_major_release(major): | ||
major += 1 | ||
minor = 0 | ||
patch = 0 | ||
return major, minor, patch | ||
|
||
|
||
def get_minor_release(major, minor): | ||
minor += 1 | ||
patch = 0 | ||
return major, minor, patch | ||
|
||
|
||
def get_patch_release(major, minor, patch): | ||
patch += 1 | ||
return major, minor, patch | ||
|
||
|
||
if __name__ == "__main__": | ||
release_type = get_first_arg() | ||
|
||
current_version = get_current_version() | ||
new_version = get_new_version(release_type, current_version) | ||
|
||
print(new_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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: prepare-release | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
release: | ||
description: Type of release | ||
required: true | ||
type: choice | ||
options: | ||
- PATCH | ||
- MINOR | ||
- MAJOR | ||
default: PATCH | ||
|
||
jobs: | ||
prepare: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-java@v3 | ||
with: | ||
java-version: 11 | ||
distribution: corretto | ||
cache: maven | ||
|
||
- run: > | ||
pwd | ||
- run: > | ||
echo "The release type should be ${{ inputs.release }}" | ||
- run: ls | ||
- run: | | ||
echo $release_type | ||
env: | ||
release_type: ${{ inputs.release }} | ||
- run: | | ||
./.github/workflows/maven-version-determiner.py $release_type | ||
env: | ||
release_type: ${{ inputs.release }} |