Skip to content

Commit f25cbd6

Browse files
committed
Get the next version
1 parent e255274 commit f25cbd6

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

.github/workflows/create-release-pr.yaml

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ jobs:
3030
# sidecar scripts
3131
- id: workflow-parsing
3232
name: Get SHA of reusuable workflow
33-
shell: bash
3433
env:
3534
REPO: ${{ github.repository }}
3635
RUN_ID: ${{ github.run_id }}
@@ -53,6 +52,7 @@ jobs:
5352
uses: actions/checkout@v4
5453
with:
5554
path: caller
55+
fetch-tags: true
5656

5757
- name: Set up python
5858
uses: actions/setup-python@v5
@@ -61,3 +61,9 @@ jobs:
6161

6262
# Install the semver package
6363
- run: pip install semver==3.0.2
64+
65+
- run: python reusable/get_next_version.py
66+
env:
67+
REPO_DIR: caller
68+
BUMP_TYPE: ${{ inputs.bump_type }}
69+
EXACT_VERSION: ${{ inputs.exact_version }}

get_next_version.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"Get the next tag version."
2+
3+
import os
4+
import subprocess
5+
from pathlib import Path
6+
7+
import semver
8+
9+
10+
def get_next_tag():
11+
"Return the next tag after the appropriate bump type."
12+
repo_dir = os.environ["REPO_DIR"]
13+
bump_type = os.environ["BUMP_TYPE"]
14+
exact_version = os.environ["EXACT_VERSION"]
15+
output_file = Path(os.environ["GITHUB_OUTPUT"])
16+
17+
if bump_type == "exact":
18+
return exact_version
19+
20+
# Get the most recent ancestor tag
21+
last_tag = subprocess.check_output(
22+
["git", "describe", "--tags", "--abbrev=0"],
23+
cwd=repo_dir
24+
).decode("utf-8")
25+
26+
last_version = semver.Version.parse(last_tag)
27+
next_version = last_version.next_version(part=bump_type)
28+
print(f"{last_version} -> {bump_type} -> {next_version}")
29+
30+
with output_file.open(mode="w", encoding="utf-8") as outfile:
31+
outfile.write(f"next_version={next_version}\n")
32+
33+
if __name__ == "__main__":
34+
get_next_tag()

0 commit comments

Comments
 (0)