Skip to content

Commit

Permalink
Merge pull request #36 from lsst-sqre/tickets/DM-31908
Browse files Browse the repository at this point in the history
DM-31908: Fix uploads from PR-triggered workflows
  • Loading branch information
jonathansick authored Sep 27, 2021
2 parents b95b987 + eb5db0f commit 713cdd3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Change log
##########

0.8.1 (2021-09-27)
==================

Fix parsing of the ``GITHUB_HEAD_REF`` environment variable in GitHub Actions.

0.8.0 (2021-09-15)
==================

Expand Down
21 changes: 17 additions & 4 deletions src/ltdconveyor/cli/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,23 @@ def _get_travis_git_refs() -> List[str]:

def _get_gh_actions_git_refs() -> List[str]:
if os.getenv("GITHUB_EVENT_NAME") == "pull_request":
ref_env_var = "GITHUB_HEAD_REF"
return [_match_pr_head_ref()]
else:
ref_env_var = "GITHUB_REF"
github_ref = os.getenv(ref_env_var, "")
return [_match_github_ref()]


def _match_pr_head_ref() -> str:
github_ref = os.getenv("GITHUB_HEAD_REF", "")
if github_ref == "":
raise click.UsageError(
"Using --gh but the GITHUB_HEAD_REF environment variable is "
"not detected."
)
return github_ref


def _match_github_ref() -> str:
github_ref = os.getenv("GITHUB_REF", "")
if github_ref == "":
raise click.UsageError(
"Using --gh but the GITHUB_REF environment variable is "
Expand All @@ -242,4 +255,4 @@ def _get_gh_actions_git_refs() -> List[str]:
)
)
ref = match.group("ref")
return [ref]
return ref

0 comments on commit 713cdd3

Please sign in to comment.