Skip to content

Commit e2ad569

Browse files
committed
Fixes release script
1 parent 65f4495 commit e2ad569

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

.github/workflows/release.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_dispatch:
55
inputs:
66
release-type:
7-
description: 'Release type'
7+
description: "Release type"
88
required: true
99
default: patch
1010
type: choice
@@ -20,20 +20,14 @@ jobs:
2020
steps:
2121
- name: Checkout
2222
uses: actions/checkout@v4
23-
- name: Get latest release tag
24-
uses: dragonish/get-latest-release-tag@v1
25-
id: latest
26-
with:
27-
token: ${{ secrets.GITHUB_TOKEN }}
28-
repository: 'dragonish/get-latest-release-tag'
29-
pre-release: false
30-
- name: Install python dependency
23+
- name: Install python dependencies
3124
run: |
3225
pip install GitPython
26+
pip install PyGithub
3327
- name: Configure git
3428
run: |
3529
git config --global user.email "[email protected]"
3630
git config --global user.name "Github Actions"
37-
- name: Create new version tag and push it
31+
- name: Create new version tag and push it
3832
run: |
39-
python ./ci/release-tag.py "${{ steps.latest.outputs.tag }}" "${{ github.event.inputs.release-type }}"
33+
python ./ci/release-tag.py ${{ secrets.GITHUB_TOKEN }} "${{ github.event.inputs.release-type }}"

ci/release-tag.py

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
11
import sys
2-
from git import Repo
2+
from git import Repo, TagReference
3+
from github import Github
4+
from github import Auth
35

4-
current_tag = sys.argv[1]
5-
version_kind = sys.argv[2]
6+
7+
def get_next_version(current_version: str) -> str:
8+
version_parts = current_version.split(".")
9+
10+
if version_kind == "major":
11+
version_parts[0] = str(int(version_parts[0]) + 1)
12+
elif version_kind == "minor":
13+
version_parts[1] = str(int(version_parts[1]) + 1)
14+
elif version_kind == "patch":
15+
version_parts[2] = str(int(version_parts[2]) + 1)
16+
return ".".join(version_parts)
17+
18+
19+
def get_current_version(github_token: str) -> str:
20+
auth = Auth.Token(github_token)
21+
github = Github(auth=auth)
22+
repo = github.get_repo("ombrelin/plex-rich-presence")
23+
return repo.get_latest_release().name
24+
25+
26+
github_token: str = sys.argv[1]
27+
version_kind: str = sys.argv[2]
628

729
print("Issuing release...")
8-
print("Current tag : " + current_tag)
9-
print("Version tag : " + version_kind)
10-
11-
version_parts = current_tag.split('.')
12-
13-
if version_kind == "major":
14-
version_parts[0] = str(int(version_parts[0]) + 1)
15-
elif version_kind == "minor":
16-
version_parts[1] = str(int(version_parts[1]) + 1)
17-
elif version_kind == "patch":
18-
version_parts[2]= str(int(version_parts[2]) + 1)
19-
20-
new_version = ".".join(version_parts)
21-
print("Next version tag : " + new_version)
22-
repo = Repo(".")
23-
new_tag = repo.create_tag(new_version, message='Version "{0}"'.format(new_version))
24-
repo.remotes.origin.push(new_tag)
30+
print("Version kind : " + version_kind)
31+
32+
current_version: str = get_current_version(github_token)
33+
print("Current version : " + current_version)
34+
new_version: str = get_next_version(current_version)
35+
print("Next version : " + new_version)
36+
37+
repo: Repo = Repo(".")
38+
new_tag: TagReference = repo.create_tag(
39+
new_version, message='Version "{0}"'.format(new_version)
40+
)
41+
_ = repo.remotes.origin.push(new_tag.name)

0 commit comments

Comments
 (0)