Skip to content

Commit

Permalink
cd: create GH Actions workflow to prepare release on dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-seifert committed Jan 2, 2024
1 parent 4a18372 commit e2c55e4
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/maven-version-determiner.py
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)
27 changes: 27 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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:
- run: >
pwd
- run: >
echo "The release type should be ${{ inputs.release }}"
- run: |
new_version=./.github/workflows/maven-version-determiner release_type
echo $new_version
env: ${{ inputs.release }}

0 comments on commit e2c55e4

Please sign in to comment.