Skip to content

Commit

Permalink
MOD:python script
Browse files Browse the repository at this point in the history
  • Loading branch information
wswenyue committed Mar 13, 2024
1 parent 328fcef commit fd59ec2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
35 changes: 26 additions & 9 deletions .github/build_new_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ def cmd_run(cmd: str) -> str:
return get_str(output)


def cmd_run_iter(cmd: str):
_cmd = str(cmd).split()
popen = subprocess.Popen(_cmd, stdout=subprocess.PIPE, universal_newlines=True)
for stdout_line in iter(popen.stdout.readline, ""):
yield get_str(stdout_line)
popen.stdout.close()
return_code = popen.wait()
if return_code:
raise subprocess.CalledProcessError(return_code, _cmd)


def is_empty(obj):
if obj is None:
return True
Expand Down Expand Up @@ -57,19 +68,25 @@ def is_not_empty(obj):
return not is_empty(obj)


def next_revision_num(version_pre: str) -> int:
_max = -1
for line in cmd_run_iter("git ls-remote --tags -q"):
if is_empty(line):
continue
if version_pre not in line:
continue
code = int(line.rsplit('.', 1)[-1])
print(f"code:{code}")
if _max < code:
_max = code
return _max + 1


v_prefix = os.getenv('VERSION_PREFIX')
v_major_minor = os.getenv('VERSION_MAJOR_MINOR')
print(f"v_prefix:{v_prefix}")
print(f"v_major_minor:{v_major_minor}")
# Get the path of the runner file
v_revision_old = cmd_run(
f"git tag --list '{v_prefix}{v_major_minor}.*' --sort=-version:refname | head -n 1 | grep -oE '[0-9]+$'")
v_revision = 0
if is_empty(v_revision_old):
print("v_revision_old empty!!!")
v_revision = 0
else:
v_revision = int(v_revision_old.strip()) + 1
v_revision = next_revision_num(f"{v_prefix}{v_major_minor}.")
new_tag = f"{v_prefix}{v_major_minor}.{v_revision}"
print(f"newTag:{new_tag}")
add_env("NEW_TAG", new_tag)
Expand Down
22 changes: 1 addition & 21 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,7 @@ jobs:
echo "VERSION_MAJOR_MINOR:${VERSION_MAJOR_MINOR}"
echo "VERSION_PREFIX=$VERSION_PREFIX" >> $GITHUB_ENV
echo "VERSION_MAJOR_MINOR=$VERSION_MAJOR_MINOR" >> $GITHUB_ENV
# - name: Generate Git Tag
# id: generate_tag
# uses: actions/setup-python@v5
# with:
# python-version: '3.9'
# run: |
#
# - name: Generate Git Tag
# id: generate_tag
# run: |
# echo "- :white_check_mark: checkout done." >> $GITHUB_STEP_SUMMARY
# VERSION_PATCH=$(git tag --list "${VERSION_PREFIX}${VERSION_MAJOR_MINOR}.*" --sort=-version:refname | head -n 1 | grep -oE '[0-9]+$')
# if [ -z "$VERSION_PATCH" ]; then
# VERSION_PATCH=0
# else
# VERSION_PATCH=$((VERSION_PATCH + 1))
# fi
# NEW_TAG="${VERSION_PREFIX}${VERSION_MAJOR_MINOR}.${VERSION_PATCH}"
# echo "Generated new tag: $NEW_TAG"
# echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV
# echo "- :white_check_mark: create new tag: ${NEW_TAG}" >> $GITHUB_STEP_SUMMARY
- name: generate git tag
id: gennerate_tag
run: python .github/build_new_tag.py
Expand Down

0 comments on commit fd59ec2

Please sign in to comment.