Skip to content

Commit

Permalink
Get the next version
Browse files Browse the repository at this point in the history
  • Loading branch information
nwiltsie committed Jul 29, 2024
1 parent e255274 commit f25cbd6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .github/workflows/create-release-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
# sidecar scripts
- id: workflow-parsing
name: Get SHA of reusuable workflow
shell: bash
env:
REPO: ${{ github.repository }}
RUN_ID: ${{ github.run_id }}
Expand All @@ -53,6 +52,7 @@ jobs:
uses: actions/checkout@v4
with:
path: caller
fetch-tags: true

- name: Set up python
uses: actions/setup-python@v5
Expand All @@ -61,3 +61,9 @@ jobs:

# Install the semver package
- run: pip install semver==3.0.2

- run: python reusable/get_next_version.py
env:
REPO_DIR: caller
BUMP_TYPE: ${{ inputs.bump_type }}
EXACT_VERSION: ${{ inputs.exact_version }}
34 changes: 34 additions & 0 deletions get_next_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"Get the next tag version."

import os
import subprocess
from pathlib import Path

import semver


def get_next_tag():
"Return the next tag after the appropriate bump type."
repo_dir = os.environ["REPO_DIR"]
bump_type = os.environ["BUMP_TYPE"]
exact_version = os.environ["EXACT_VERSION"]
output_file = Path(os.environ["GITHUB_OUTPUT"])

if bump_type == "exact":
return exact_version

# Get the most recent ancestor tag
last_tag = subprocess.check_output(
["git", "describe", "--tags", "--abbrev=0"],
cwd=repo_dir
).decode("utf-8")

last_version = semver.Version.parse(last_tag)
next_version = last_version.next_version(part=bump_type)
print(f"{last_version} -> {bump_type} -> {next_version}")

with output_file.open(mode="w", encoding="utf-8") as outfile:
outfile.write(f"next_version={next_version}\n")

if __name__ == "__main__":
get_next_tag()

0 comments on commit f25cbd6

Please sign in to comment.