Skip to content

Commit

Permalink
patch: Checkout FETCH_HEAD instead of ref (#21)
Browse files Browse the repository at this point in the history
`git checkout` doesn't work with a ref (e.g. `refs/heads/main` or
`refs/pull/160/merge`)

Fixes CI error
(https://github.com/canonical/mysql-operator/actions/runs/4502832674/jobs/7925213084?pr=160)
caused by dfee76d
  • Loading branch information
carlcsaposs-canonical authored Mar 23, 2023
1 parent dfee76d commit 7de3f1c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/_get_workflow_version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ jobs:
"""
# Separate ref (e.g. "refs/heads/my_branch", "1.0", "my_branch")
path, ref = caller_workflow_ref_path.split("@")
ref = ref.removeprefix("refs/heads/")
# Separate repository name (e.g. "octocat/hello-world")
repository_name = "/".join(path.split("/")[:2])
path = path.split("/")[2:]
Expand All @@ -88,13 +87,17 @@ jobs:
try:
os.makedirs(repository_name)
except FileExistsError:
commands = [f"git checkout {ref}"]
commands = [
f"git fetch origin {ref}",
"git checkout FETCH_HEAD",
]
else:
commands = [
"git init",
"git sparse-checkout set --sparse-index .github/workflows/",
f"git remote add --fetch origin https://github.com/{repository_name}.git",
f"git checkout {ref}",
f"git fetch origin {ref}",
"git checkout FETCH_HEAD",
]
for command in commands:
subprocess.check_output(command.split(" "), cwd=repository_name)
Expand Down

0 comments on commit 7de3f1c

Please sign in to comment.