Skip to content

Commit

Permalink
Run CI on forked repos when no tags are fetched (#1589)
Browse files Browse the repository at this point in the history
* Update helper file to allow to run task package ci even when no tags are available

* Revert "Update helper file to allow to run task package ci even when no tags are available"

This reverts commit c8b8212.

* Allow to run CI when no tags are fetched

* Update to use a function instead for getting tags

* Add signature to functions

---------

Co-authored-by: Sorin Sbarnea <[email protected]>
  • Loading branch information
audgirka and ssbarnea authored Oct 22, 2024
1 parent 57c0126 commit a585cac
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 36 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ builtin = "clear,rare,code"
check-filenames = true
check-hidden = true
ignore-words = ".config/dictionary.txt"
skip = "out,node_modules,site,codicon.css,yarn.lock,package-lock.json,.vscode-test,.git,.yarn,dictionary.txt,settings.md"
skip = "out,node_modules,.mypy_cache,.ruff_cache,site,codicon.css,yarn.lock,package-lock.json,.vscode-test,.git,.yarn,dictionary.txt,settings.md"

# We have no python tests in this project, but we keep this config to prevent
# vscode python extension from showing errors while trying to collect tests.
Expand Down
89 changes: 54 additions & 35 deletions tools/helper
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,38 @@ import glob
import subprocess
import logging
import sys
from datetime import datetime


def run(cmd: str):
def run(cmd: str) -> subprocess.CompletedProcess[bytes]:
"""Helper to easy calling subprocess."""
return subprocess.run(cmd, shell=True, check=True)


def cli():
def get_tags(cmd: str) -> subprocess.CompletedProcess[str]:
"""Get tags for the user using git commands."""
try:
result = subprocess.run(
cmd,
shell=True,
capture_output=True,
check=True,
text=True,
)
except subprocess.CalledProcessError as e:
logging.warning("This repository is missing tags. Fetch tags from upstream repository.")
logging.error(e)
logging.error(e.output)
result = subprocess.CompletedProcess(
"",
0,
f"v{datetime.now().strftime('%y')}.{datetime.now().month}.1-1-no_tags",
None,
)
return result


def cli() -> None:
"""Main."""
parser = argparse.ArgumentParser(prog="helper", description="Build process helper")
parser.add_argument(
Expand All @@ -33,28 +57,17 @@ def cli():
logging.basicConfig(level=logging.INFO, format="%(message)s")

pre_release = False
result = subprocess.run(
'git describe --dirty --tags --long --match "v*.*"',
shell=True,
capture_output=True,
check=True,
text=True,
)
result = get_tags('git describe --dirty --tags --long --match "v*.*"')
git_tag = result.stdout.rstrip()
logging.debug('git describe (with --match "v*.*") returned: %s', git_tag)
tag, commits_since, suffix = git_tag.split("-", 2)
version = tag[1:]
version_info = [int(x) for x in version.split(".")]
if "-dirty" in suffix or commits_since != "0":
pre_release = True
# If pre_release = True, we need to calculate the time difference from the first stable release of the month with a "*.0" tag
result = subprocess.run(
'git describe --dirty --tags --long --match "v*.*.0"',
shell=True,
capture_output=True,
check=True,
text=True,
)
# If pre_release = True, we need to calculate the time difference from the
# first stable release of the month with a "*.0" tag
result = get_tags('git describe --dirty --tags --long --match "v*.*.0"')
git_tag = result.stdout.rstrip()
logging.debug('git describe (with --match "v*.*.0") returned: %s', git_tag)
tag, commits_since, suffix = git_tag.split("-", 2)
Expand Down Expand Up @@ -86,24 +99,30 @@ def cli():
logging.error(msg)
sys.exit(2)
# determine the PATCH value, which is the time passed between last tag and last commit
last_tag_timestamp = int(
subprocess.run(
f"git -P log -1 --format=%ct {tag}",
shell=True,
capture_output=True,
check=True,
text=True,
).stdout.rstrip()
)
last_commit_timestamp = int(
subprocess.run(
"git -P show --no-patch --format=%ct HEAD",
shell=True,
capture_output=True,
check=True,
text=True,
).stdout.rstrip()
)
try:
last_tag_timestamp = int(
subprocess.run(
f"git -P log -1 --format=%ct {tag}",
shell=True,
capture_output=True,
check=True,
text=True,
).stdout.rstrip()
)
last_commit_timestamp = int(
subprocess.run(
"git -P show --no-patch --format=%ct HEAD",
shell=True,
capture_output=True,
check=True,
text=True,
).stdout.rstrip()
)
except subprocess.CalledProcessError as e:
logging.error(e)
logging.error(e.output)
last_tag_timestamp = 1721335286
last_commit_timestamp = 1722605520
version_info[2] = last_commit_timestamp - last_tag_timestamp
version = ".".join([str(x) for x in version_info])
logging.info(
Expand Down

0 comments on commit a585cac

Please sign in to comment.