-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Ackuq/feature/jar-release
Create release workflow and versioning utilities
- Loading branch information
Showing
5 changed files
with
185 additions
and
9 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
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,68 @@ | ||
name: Publish new version | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
bump_type: | ||
description: The type of version bump | ||
required: true | ||
default: patch | ||
type: choice | ||
options: | ||
- major | ||
- minor | ||
- patch | ||
|
||
|
||
jobs: | ||
publish-scala: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup JDK | ||
uses: actions/setup-java@v2 | ||
with: | ||
distribution: temurin | ||
# TODO: Support more versions? | ||
java-version: 11 | ||
|
||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.10.1" | ||
|
||
- name: Cache SBT | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/.ivy2/cache | ||
~/.sbt | ||
key: ${{ runner.os }}-sbt-${{ hashFiles('**/build.sbt') }} | ||
|
||
- name: Set the new version number | ||
run: | | ||
python scripts/bump_version.py -t ${{ github.event.inputs.bump_type }} | ||
- name: Get the new version number | ||
id: version | ||
run: | | ||
echo "::set-output name=jar_version::$(cat scala/VERSION)" | ||
- name: Build artifact | ||
run: | | ||
sbt package | ||
working-directory: scala | ||
|
||
- name: Create tag | ||
uses: actions-ecosystem/action-push-tag@v1 | ||
with: | ||
tag: v${{ steps.version.outputs.jar_version }} | ||
|
||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
tag_name: v${{ steps.version.outputs.jar_version }} | ||
files: | | ||
LICENSE | ||
scala/target/scala-2.12/spark-pit_2.12-${{ steps.version.outputs.jar_version }}.jar |
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 @@ | ||
0.0.0 |
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
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,79 @@ | ||
import argparse | ||
import re | ||
from argparse import ArgumentParser | ||
from enum import Enum | ||
from typing import TypedDict | ||
import sys | ||
|
||
VERSION_FILE_NAME = "scala/VERSION" | ||
|
||
|
||
class VersionDict(TypedDict): | ||
major: int | ||
minor: int | ||
patch: int | ||
|
||
|
||
class BumpType(Enum): | ||
MAJOR = "major" | ||
MINOR = "minor" | ||
PATCH = "patch" | ||
|
||
def __str__(self) -> str: | ||
return self.value | ||
|
||
|
||
VERSION_REGEX = r"^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)$" | ||
|
||
|
||
def validate_version(s: str) -> VersionDict: | ||
try: | ||
match = re.match(VERSION_REGEX, s) | ||
if match is None: | ||
raise Exception | ||
group_dict = match.groupdict() | ||
return { | ||
"major": int(group_dict["major"]), | ||
"minor": int(group_dict["minor"]), | ||
"patch": int(group_dict["patch"]), | ||
} | ||
except: | ||
msg = "not a valid version: {}".format(s) | ||
raise argparse.ArgumentTypeError(msg) | ||
|
||
|
||
if __name__ == "__main__": | ||
argument_parser = ArgumentParser(description="Bump version") | ||
|
||
argument_parser.add_argument( | ||
"--bump-type", | ||
"-t", | ||
type=BumpType, | ||
choices=list(BumpType), | ||
required=True, | ||
help="Type of bump", | ||
) | ||
|
||
args = argument_parser.parse_args() | ||
|
||
# Get the old version | ||
version_file = open(VERSION_FILE_NAME, "r+") | ||
version: VersionDict = validate_version(version_file.readline()) | ||
bump_type: BumpType = args.bump_type | ||
|
||
if bump_type is BumpType.MAJOR: | ||
version["major"] += 1 | ||
elif bump_type is BumpType.MINOR: | ||
version["minor"] += 1 | ||
elif bump_type is BumpType.PATCH: | ||
version["patch"] += 1 | ||
|
||
new_version_string = "{}.{}.{}".format(*version.values()) | ||
|
||
# Check if the new version is valid | ||
validate_version(new_version_string) | ||
|
||
# Overwrite the file with new version | ||
version_file.seek(0) | ||
version_file.write(new_version_string) | ||
version_file.truncate() |