Skip to content

Commit

Permalink
Revert c496e4b
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell committed Mar 17, 2024
1 parent 0ba1044 commit c24cb69
Showing 1 changed file with 13 additions and 79 deletions.
92 changes: 13 additions & 79 deletions scripts/fetch_nightly_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,64 +48,14 @@ def get_latest_commit(

return commit


def get_default_branch(
name,
repoinfo,
# for now supporting only gitlab.cern.ch
gitlab=False,
date=None,
):
"""Helper function for adding a package versioned at the latest commit to a spack environment.
The authentication is optional, but note that the api might be rate-limited for unauthenticated access.
:param name: spack name of the package, p.ex: "edm4hep"
:param repoinfo: description of the owner and repository names, p.ex: "key4hep/edm4hep"
"""

if not gitlab:
giturl = "https://api.github.com/repos/%s"
else:
giturl = "https://gitlab.cern.ch/api/v4/projects/%s"

if gitlab:
repoinfo = repoinfo.replace("/", "%2F")

# Apparently this is also fine for gitlab
headers = {"Accept": "application/vnd.github+json"}

# gitlab doesn't seem to need a token, maybe there is some rate limiting without one
token = os.environ.get("GITHUB_TOKEN" if not gitlab else "CERN_GITLAB_TOKEN", None)
if token:
headers["Authorization" if not gitlab else "PRIVATE-TOKEN"] = f"token {token}"

# not tested for gitlab
search_params = {}
if date:
search_params = {
"until": f"{date}",
}

response = requests.get(giturl % repoinfo, params=search_params, headers=headers)

default_branch = response.json()[
"default_branch" if not gitlab else "default_branch"
]

return default_branch


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Add latest commits to a spack environment"
)
parser.add_argument(
"--path",
help="path to a yaml file with spack packages",
)
parser.add_argument(
"--extra-path",
help="path to a yaml file with spack packages",
"path",
help="path to the current environment",
default="/key4hep-spack",
)
parser.add_argument(
"date",
Expand All @@ -116,19 +66,12 @@ def get_default_branch(
date = args.date

try:
with open(args.path, "r") as recipe:
with open(os.path.join(args.path, "packages.yaml"), "r") as recipe:
text = yaml.safe_load(recipe)
except FileNotFoundError:
print("Please run this script from the key4hep-spack repository.")
raise

try:
with open(args.extra_path, "r") as recipe:
text_extra = yaml.safe_load(recipe)
except FileNotFoundError:
print("Please run this script from the key4hep-spack repository.")
raise

for package, location in [
("aidatt", "aidasoft/aidatt"),
("ced", "ilcsoft/ced"),
Expand Down Expand Up @@ -188,24 +131,15 @@ def get_default_branch(
gitlab = False
if package in ["opendatadetector"]:
gitlab = True
commit = get_default_branch(package, location, gitlab=gitlab, date=date)
line = f"@{commit} "
# if package not in ["cepcsw"]:
# line += "=develop"
original = " "
if package in text["packages"] and "require" in text["packages"][package]:
original = text["packages"][package]["require"]
text["packages"][package]["require"] = line + original
elif (
package in text_extra["packages"]
and "require" in text_extra["packages"][package]
):
original = text_extra["packages"][package]["require"]
text_extra["packages"][package]["require"] = line + original
commit = get_latest_commit(package, location, date=date, gitlab=gitlab)
line = f"@{commit}"
if package not in ["cepcsw"]:
line += "=develop"
if not text["packages"][package]:
print(f"Adding {package}@{commit} to the key4hep-stack package.py")
else:
text_extra["packages"][package]["require"] = line
print(f"Updating {package}@{commit} in the key4hep-stack package.py")
text["packages"][package]["require"] = line

with open(args.path, "w") as recipe:
with open(os.path.join(args.path, "packages.yaml"), "w") as recipe:
yaml.dump(text, recipe)
with open(args.extra_path, "w") as recipe:
yaml.dump(text_extra, recipe)

0 comments on commit c24cb69

Please sign in to comment.