Skip to content

Commit

Permalink
fix:version_file_path (#7)
Browse files Browse the repository at this point in the history
now an argument to the script
  • Loading branch information
JarbasAl authored Sep 6, 2024
1 parent 6994810 commit f788967
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/publish_alpha.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This workflow will generate a ALPHA release distribution and upload it to PyPI

# This workflow will generate an ALPHA release distribution and upload it to PyPI
name: Publish Alpha Build
on:
push:
Expand All @@ -25,19 +24,25 @@ jobs:
- uses: actions/checkout@v2
with:
ref: dev
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
fetch-depth: 0 # to avoid errors pushing refs to the destination repository

- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.8

- name: Install Build Tools
run: |
python -m pip install build wheel
- name: Determine version bump
id: version_bump
run: |
LABELS=$(echo "${{ github.event.pull_request.labels[*].name }}" | tr ' ' '\n')
LABELS=""
if [ "${{ github.event_name }}" == "pull_request" ]; then
LABELS=$(echo "${{ github.event.pull_request.labels[*].name }}" | tr ' ' '\n')
fi
MAJOR=0
MINOR=0
BUILD=0
Expand All @@ -64,22 +69,25 @@ jobs:
- name: Update version in version.py
run: |
python scripts/update_version.py ${{ steps.version_bump.outputs.part }}
python scripts/update_version.py ${{ steps.version_bump.outputs.part }} --version-file $GITHUB_WORKSPACE/tutubo/version.py
- name: "Generate release changelog"
uses: heinrichreimer/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
maxIssues: 50
id: changelog

- name: Commit to dev
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Increment Version
branch: dev

- name: version
run: echo "::set-output name=version::$(python setup.py --version)"
id: version

- name: Create Release
id: create_release
uses: actions/create-release@v1
Expand All @@ -94,9 +102,11 @@ jobs:
draft: false
prerelease: true
commitish: dev

- name: Build Distribution Packages
run: |
python setup.py sdist bdist_wheel
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand Down
26 changes: 14 additions & 12 deletions scripts/update_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@
"""

import sys
import re
from os.path import dirname
import argparse
from os.path import abspath

# TODO - read from env var to allow script to be reused
VERSION_FILE = f"{dirname(dirname(__file__))}/tutubo/version.py"

def read_version():
def read_version(version_file):
VERSION_MAJOR = 0
VERSION_MINOR = 0
VERSION_BUILD = 0
VERSION_ALPHA = 0

with open(VERSION_FILE, 'r') as file:
with open(version_file, 'r') as file:
content = file.read()
for l in content.split("\n"):
l = l.strip()
Expand All @@ -32,8 +29,8 @@ def read_version():
return VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_ALPHA


def update_version(part):
VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_ALPHA = read_version()
def update_version(part, version_file):
VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_ALPHA = read_version(version_file)

if part == 'major':
VERSION_MAJOR += 1
Expand All @@ -50,7 +47,7 @@ def update_version(part):
elif part == 'alpha':
VERSION_ALPHA += 1

with open(VERSION_FILE, 'w') as file:
with open(version_file, 'w') as file:
file.write(f"""# START_VERSION_BLOCK
VERSION_MAJOR = {VERSION_MAJOR}
VERSION_MINOR = {VERSION_MINOR}
Expand All @@ -60,5 +57,10 @@ def update_version(part):


if __name__ == "__main__":
part = sys.argv[1]
update_version(part)
parser = argparse.ArgumentParser(description='Update the version based on the specified part (major, minor, build, alpha)')
parser.add_argument('part', help='Part of the version to update (major, minor, build, alpha)')
parser.add_argument('--version-file', help='Path to the version.py file', required=True)

args = parser.parse_args()

update_version(args.part, abspath(args.version_file))

0 comments on commit f788967

Please sign in to comment.