Skip to content

Commit 98a2626

Browse files
committed
added CI action to release new version
1 parent 832af13 commit 98a2626

2 files changed

Lines changed: 181 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: 🚀 Create Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
bump_minor:
7+
description: 'Bump minor version'
8+
required: false
9+
type: boolean
10+
default: false
11+
version:
12+
description: 'Release version (optional, if not provided will use version from develop without -dev)'
13+
required: false
14+
type: string
15+
16+
jobs:
17+
release:
18+
runs-on: ubuntu-latest
19+
if: github.ref == 'refs/heads/develop'
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
token: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: '3.9'
30+
31+
- name: Configure Git
32+
run: |
33+
git config --global user.name "${{ secrets.CI_USER }}"
34+
git config --global user.email "${{ secrets.CI_EMAIL }}"
35+
36+
- name: Get release version
37+
id: get_version
38+
run: |
39+
if [ -n "${{ github.event.inputs.version }}" ]; then
40+
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
41+
else
42+
ARGS=""
43+
if [ "${{ github.event.inputs.bump_minor }}" = "true" ]; then
44+
ARGS="--bump-minor"
45+
fi
46+
VERSION=$(python manage_version.py get-release-version $ARGS)
47+
echo "version=$VERSION" >> $GITHUB_OUTPUT
48+
fi
49+
50+
- name: Update version for release
51+
run: |
52+
python manage_version.py update --version ${{ steps.get_version.outputs.version }}
53+
54+
- name: Commit release version
55+
run: |
56+
git add ayon_api/version.py pyproject.toml
57+
git commit -m "Release version ${{ steps.get_version.outputs.version }}"
58+
git push origin develop
59+
60+
- name: Rebase main on develop
61+
run: |
62+
git checkout main
63+
git rebase develop
64+
git push origin main
65+
66+
- name: Create and push tag
67+
run: |
68+
git tag ${{ steps.get_version.outputs.version }}
69+
git push origin ${{ steps.get_version.outputs.version }}
70+
71+
- name: Bump version on develop
72+
run: |
73+
git checkout develop
74+
NEW_VERSION=$(python manage_version.py get-dev-version)
75+
python manage_version.py update --version $NEW_VERSION
76+
git add ayon_api/version.py pyproject.toml
77+
git commit -m "Bump version to $NEW_VERSION"
78+
git push origin develop

manage_version.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import re
2+
import sys
3+
import argparse
4+
from pathlib import Path
5+
6+
SEMVER_REGEX = re.compile(
7+
"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)"
8+
"(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?"
9+
"(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
10+
)
11+
12+
13+
def get_current_version(version_file: Path) -> str:
14+
content = version_file.read_text(encoding="utf-8")
15+
match = re.search(r'__version__\s*=\s*"(.*)"', content)
16+
if match:
17+
return match.group(1)
18+
raise ValueError(f"Version not found in {version_file}")
19+
20+
21+
def update_version_in_src(
22+
version_file: Path,
23+
pyproject_file: Path,
24+
new_version: str,
25+
):
26+
content = version_file.read_text(encoding="utf-8")
27+
new_content = re.sub(
28+
r'(__version__\s*=\s*").*(")',
29+
rf'\g<1>{new_version}\g<2>',
30+
content
31+
)
32+
version_file.write_text(new_content, encoding="utf-8")
33+
34+
# Update pyproject.toml
35+
content = pyproject_file.read_text(encoding="utf-8")
36+
new_lines = []
37+
for line in content.splitlines():
38+
if line.startswith("version"):
39+
line = f"version = \"{new_version}\""
40+
new_lines.append(line)
41+
42+
pyproject_file.write_text("\n".join(new_lines), encoding="utf-8")
43+
44+
45+
def bump_to_dev_version(version: str) -> str:
46+
version_parts = SEMVER_REGEX.match(version).groups()
47+
major, minor, patch = version_parts[0:3]
48+
patch = str(int(patch) + 1)
49+
return f"{major}.{minor}.{patch}-dev"
50+
51+
52+
def bump_to_release_version(version: str, bump_minor: bool = False) -> str:
53+
version_parts = SEMVER_REGEX.match(version).groups()
54+
major, minor, patch = version_parts[0:3]
55+
if bump_minor:
56+
minor = str(int(minor) + 1)
57+
patch = "0"
58+
return f"{major}.{minor}.{patch}"
59+
60+
61+
def main():
62+
parser = argparse.ArgumentParser()
63+
parser.add_argument(
64+
"command",
65+
choices=["get-release-version", "update", "get-dev-version"]
66+
)
67+
parser.add_argument(
68+
"--version",
69+
help="Version to set for update command",
70+
)
71+
parser.add_argument(
72+
"--bump-minor",
73+
action="store_true",
74+
help="Bump minor version for get-release-version command",
75+
)
76+
args = parser.parse_args()
77+
78+
repo_root = Path(__file__).parent
79+
version_file = repo_root / "ayon_api" / "version.py"
80+
pyproject_file = repo_root / "pyproject.toml"
81+
82+
current_version = get_current_version(version_file)
83+
84+
if args.command == "get-release-version":
85+
if current_version:
86+
print(bump_to_release_version(current_version, args.bump_minor))
87+
else:
88+
sys.exit(1)
89+
elif args.command == "get-dev-version":
90+
if current_version:
91+
print(bump_to_dev_version(current_version))
92+
else:
93+
sys.exit(1)
94+
elif args.command == "update":
95+
if not args.version:
96+
print("Error: --version is required for update command")
97+
sys.exit(1)
98+
update_version_in_src(version_file, pyproject_file, args.version)
99+
print(f"Updated version to {args.version}")
100+
101+
102+
if __name__ == "__main__":
103+
main()

0 commit comments

Comments
 (0)