Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust release-creation scripts to refer to uktena repo for python distribution creation #213

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions release_scripts/Jenkinsfile_branches
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ pipeline {
defaultValue: true
),
booleanParam(
name: "GENIE_PYTHON",
description: "Create release branch for Genie Python.",
name: "UKTENA",
description: "Create release branch for Uktena Python distribution.",
defaultValue: true
),
booleanParam(
Expand Down Expand Up @@ -106,8 +106,8 @@ pipeline {
build job: "EPICS_release", propagate: false, wait: false
build job: "EPICS_release32", propagate: false, wait: false
}
if (params.GENIE_PYTHON) {
build job: "genie_python_release_pipeline", propagate: false, wait: false
if (params.UKTENA) {
build job: "uktena_release_pipeline", propagate: false, wait: false
}
if (params.IBEX_GUI) {
build job: "ibex_gui_releases_pipeline", propagate: false, wait: false
Expand Down
51 changes: 22 additions & 29 deletions release_scripts/branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

EPICS_REPO_URL = "https://github.com/ISISComputingGroup/EPICS.git"
IBEX_REPO_URL = "https://github.com/ISISComputingGroup/ibex_gui.git"
GENIE_PYTHON_URL = "https://github.com/ISISComputingGroup/genie_python.git"
UKTENA_URL = "https://github.com/ISISComputingGroup/uktena.git"
JSON_BOURNE_URL = "https://github.com/ISISComputingGroup/JSON_bourne.git"

EPICS_DIR = "EPICS"
IBEX_DIR = "IBEX"
SCRIPT_GEN_DIR = "SCRIPT_GEN"
GENIE_PYTHON_DIR = "genie_python"
UKTENA_DIR = "UKTENA"
JSON_BOURNE_DIR = "JSON_bourne"

INSTETC_TEMPLATE_LOCAL_PATH = os.path.join(
Expand Down Expand Up @@ -45,11 +45,8 @@
)
SCRIPT_GENERATOR_POM_ABSOLUTE_PATH = os.path.join(SCRIPT_GEN_DIR, SCRIPT_GENERATOR_POM_LOCAL_PATH)

GENIE_PYTHON_VERSION_LOCAL_PATH = os.path.join("Lib", "site-packages", "genie_python", "version.py")
GENIE_PYTHON_VERSION_ABSOLUTE_PATH = os.path.join(GENIE_PYTHON_DIR, GENIE_PYTHON_VERSION_LOCAL_PATH)


def write_instetc_version(version: str):
def write_instetc_version(version: str) -> None:
logging.info(f"Writing version '{version}' to '{INSTETC_TEMPLATE_ABSOLUTE_PATH}'.")

with open(INSTETC_TEMPLATE_ABSOLUTE_PATH, "r") as file:
Expand All @@ -64,7 +61,7 @@ def write_instetc_version(version: str):
file.write(data)


def write_gui_version(manifest_path: str, pom_path: str, version: str):
def write_gui_version(manifest_path: str, pom_path: str, version: str) -> None:
# In Manifest file.
logging.info(f"Writing version '{version}' to '{manifest_path}'.")

Expand Down Expand Up @@ -97,25 +94,20 @@ def write_gui_version(manifest_path: str, pom_path: str, version: str):
tree.write(pom_path)


def write_genie_python_version(version: str):
logging.info(f"Writing version '{version}' to '{GENIE_PYTHON_VERSION_ABSOLUTE_PATH}'.")

with open(GENIE_PYTHON_VERSION_ABSOLUTE_PATH, "w") as file:
file.write(f'VERSION = "{version}"\n')


class ReleaseBranch:
"""Wrapper around a Repo object. Used to perform Git operations on a release branch."""

def __init__(self, repo: Repo = None):
def __init__(self, repo: Repo = None) -> None:
self.repo = repo

def create(self, url: str, dir: str, branch_name: str, submodules: bool = False):
def create(self, url: str, dir: str, branch_name: str, submodules: bool = False) -> None:
"""
Initializes a repository by using 'git clone'.
Creates a release branch for the main repository and, optionally, all submodules.

Uses an environment variable 'REMOTE' set in Jenkins to check if submodules should be updated with '--remote'.
Uses an environment variable 'REMOTE' set in Jenkins to check if submodules
should be updated with '--remote'.

Will fail the script if there are any new submodule commits. Defaults to true.

Uses an environment variable 'TAG' set in Jenkins as the source for the release branch.
Expand All @@ -133,7 +125,7 @@ def create(self, url: str, dir: str, branch_name: str, submodules: bool = False)
logging.info(f"Cloning '{url}' into '{dir}'.")
self.repo = git.Repo.clone_from(url=url, to_path=dir)
if branch_name in self.repo.references:
logging.error(f"Branch name '{branch_name}' already exists for repo '{url}'.")
logging.error(f"Branch name '{branch_name}' " f"already exists for repo '{url}'.")
sys.exit(1)

source = os.getenv("TAG")
Expand All @@ -160,7 +152,8 @@ def create(self, url: str, dir: str, branch_name: str, submodules: bool = False)
new_commits = False
for i in self.repo.index.diff(None).iter_change_type("M"):
logging.warning(
f"Submodule '{i.a_path}' in repo '{self.repo.remotes.origin.url}' has new commits."
f"Submodule '{i.a_path}' in repo "
f"'{self.repo.remotes.origin.url}' has new commits."
)
new_commits = True

Expand All @@ -178,7 +171,8 @@ def create(self, url: str, dir: str, branch_name: str, submodules: bool = False)
for submodule in self.repo.submodules:
if branch_name in submodule.module().references:
logging.error(
f"Branch name '{branch_name}' already exists for repo '{submodule.module().remote().url}'."
f"Branch name '{branch_name}' already "
f"exists for repo '{submodule.module().remote().url}'."
)
sys.exit(1)

Expand All @@ -188,7 +182,7 @@ def create(self, url: str, dir: str, branch_name: str, submodules: bool = False)
)
submodule.module().create_head(branch_name).checkout()

def commit(self, items: List[Any], msg: str):
def commit(self, items: List[Any], msg: str) -> None:
"""
Commits a list of items.

Expand All @@ -201,7 +195,7 @@ def commit(self, items: List[Any], msg: str):
self.repo.index.add(items)
self.repo.index.commit(msg)

def push(self, submodules: bool = False):
def push(self, submodules: bool = False) -> None:
"""
Pushes changes to remote.

Expand Down Expand Up @@ -238,7 +232,8 @@ def push(self, submodules: bool = False):
ioc_submodule = epics.repo.submodule("ioc/master")
ioc = ReleaseBranch(ioc_submodule.module())
ioc.commit([INSTETC_TEMPLATE_LOCAL_PATH], f"Update version to {args.version}.")
# Set submodule hash to created commit hash. This ensures we use the latest submodule commit.
# Set submodule hash to created commit hash.
# This ensures we use the latest submodule commit.
ioc_submodule.binsha = ioc.repo.head.commit.binsha

epics.commit([ioc_submodule], "Update submodule ioc.")
Expand Down Expand Up @@ -267,12 +262,10 @@ def push(self, submodules: bool = False):
)
script_gen.push()

if os.getenv("GENIE_PYTHON") == "true":
genie_python = ReleaseBranch()
genie_python.create(GENIE_PYTHON_URL, GENIE_PYTHON_DIR, f"Release_{args.version}")
write_genie_python_version(args.version)
genie_python.commit([GENIE_PYTHON_VERSION_LOCAL_PATH], f"Update version to {args.version}.")
genie_python.push()
if os.getenv("UKTENA") == "true":
uktena = ReleaseBranch()
uktena.create(UKTENA_URL, UKTENA_DIR, f"Release_{args.version}")
uktena.push()

if os.getenv("JSON_BOURNE") == "true":
json_bourne = ReleaseBranch()
Expand Down