Skip to content

Commit

Permalink
Merge pull request #436 from camptocamp/latest
Browse files Browse the repository at this point in the history
Fix latest on stabilisation branch
  • Loading branch information
sbrunner authored Feb 14, 2022
2 parents 5edd6cc + f962bcf commit 27e81fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
31 changes: 17 additions & 14 deletions c2cciutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ def merge(default_config: Any, config: Any) -> Any:
return config


def get_master_branch(repo: List[str]) -> Tuple[str, bool]:
"""Get the name of the master branch."""
master_branch = "master"
success = False
try:
default_branch_json = graphql(
"default_branch.graphql", {"name": repo[1], "owner": repo[0]}, default=False
)
success = default_branch_json is not False
master_branch = default_branch_json["repository"]["defaultBranchRef"]["name"] if success else "master"
except RuntimeError as runtime_error:
print(runtime_error)
print("Failback to master")
return master_branch, success


def get_config() -> c2cciutils.configuration.Configuration:
"""
Get the configuration, with project and autodetections.
Expand Down Expand Up @@ -109,19 +125,7 @@ def get_config() -> c2cciutils.configuration.Configuration:

repository = get_repository()
repo = repository.split("/")
master_branch = "master"
credentials = False
try:
default_branch_json = graphql(
"default_branch.graphql", {"name": repo[1], "owner": repo[0]}, default=False
)
credentials = default_branch_json is not False
master_branch = (
default_branch_json["repository"]["defaultBranchRef"]["name"] if credentials else "master"
)
except RuntimeError as runtime_error:
print(runtime_error)
print("Failback to master")
master_branch, credentials = get_master_branch(repo)

merge(
{
Expand Down Expand Up @@ -661,7 +665,6 @@ def get_based_on_master(
master_branch: The master branch name
config: The full configuration
"""

if os.environ.get("GITHUB_REF", "").startswith("refs/tags/"):
# The tags are never consider as based on master
return False
Expand Down
12 changes: 8 additions & 4 deletions c2cciutils/scripts/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,13 @@ def main() -> None:
)
if docker_config:
latest = False
if os.path.exists("SECURITY.md") and docker_config["latest"] is True:
with open("SECURITY.md", encoding="utf-8") as security_file:
security = c2cciutils.security.Security(security_file.read())
full_repo = c2cciutils.get_repository().split("/")
master_branch, _ = c2cciutils.get_master_branch(full_repo)
security_response = requests.get(
f"https://raw.githubusercontent.com/camptocamp/c2cciutils/{master_branch}/SECURITY.md"
)
if security_response.ok and docker_config["latest"] is True:
security = c2cciutils.security.Security(security_response.text)
version_index = security.headers.index("Version")
latest = security.data[-1][version_index] == version

Expand Down Expand Up @@ -223,7 +227,7 @@ def main() -> None:
with tarfile.open(fileobj=response.raw, mode="r:gz") as file:
file.extractall(path=os.path.expanduser("~/.local/bin"))

owner, repo = c2cciutils.get_repository().split("/")
owner, repo = full_repo
commit_sha = (
subprocess.run(["git", "rev-parse", "HEAD"], check=True, stdout=subprocess.PIPE)
.stdout.strip()
Expand Down

0 comments on commit 27e81fc

Please sign in to comment.