Skip to content

Commit

Permalink
New packager workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
kikootwo committed Feb 26, 2024
1 parent 22108d8 commit 8877794
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
35 changes: 35 additions & 0 deletions .github/scripts/calculate_new_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import sys

def parse_version(tag):
"""Parse the semantic version from a git tag."""
major, minor, patch = map(int, tag.split('.'))
return major, minor, patch

def calculate_new_version(last_tag, version_type):
"""Calculate the new version number based on the last tag and version bump type."""
major, minor, patch = parse_version(last_tag)

if version_type == 'major':
major += 1
minor = 0
patch = 0
elif version_type == 'minor':
minor += 1
patch = 0
elif version_type == 'patch':
patch += 1
else:
raise ValueError("Unknown version type. Expected one of: major, minor, patch.")

return f"{major}.{minor}.{patch}"

if __name__ == "__main__":
if len(sys.argv) < 3:
print("Usage: python calculate_new_version.py <last_tag> <version_type>")
sys.exit(1)

last_tag = sys.argv[1]
version_type = sys.argv[2]

new_version = calculate_new_version(last_tag, version_type)
print(new_version)
37 changes: 34 additions & 3 deletions .github/workflows/packager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,51 @@ name: Package and Deploy Addon

on:
workflow_dispatch:
inputs:
versionType:
description: 'Version bump type (major, minor, patch)'
required: true
default: 'minor'
type: choice
options:
- major
- minor
- patch
pull_request:
types: [closed]
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
if: >
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'pull_request' && github.event.pull_request.merged == true)
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
ref: 'main'
fetch-depth: 0 # Fetches all history for all tags and branches

- name: Fetch all tags
run: git fetch --prune --tags
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Calculate new version and create tag
id: new_version
run: |
VERSION_TYPE=${{ github.event.inputs.versionType || 'minor' }}
LATEST_TAG=$(git describe --tags --abbrev=0)
NEW_VERSION=$(python .github/scripts/calculate_new_version.py "$LATEST_TAG" "$VERSION_TYPE")
echo "New Version: $NEW_VERSION"
git tag "$NEW_VERSION"
git push origin "$NEW_VERSION"
echo "::set-output name=NEW_VERSION::$NEW_VERSION"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create and deploy packages
uses: BigWigsMods/packager@v2
Expand Down

0 comments on commit 8877794

Please sign in to comment.