WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Merged
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
apt-get update
apt-get install -y git
git config --global --add safe.directory '*'
git clone "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" .
git clone $(awk -v a=${{github.event.pull_request.head.repo.clone_url}} -v b=${{github.repositoryUrl}} 'BEGIN { if (a == "") { print b } else { print a } }') .
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a comment?

Looking at the line, maybe 30-40 lines? Just to understand what is happening here.

Copy link
Member Author

@dey4ss dey4ss Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's really not nice and I don't really like it either.

The problem is that the repository referenced by the environment variables and contexts Github provides are always the one where the PR/push happens. In the case of forks, that's still our repo and not the forked one that gets cloned. Then, the branch providing the changes cannot be found there.

github.event.pull_request.head.repo.clone_url is the URL of the repo referenced by the HEAD if the event that triggers the action is a PR. That's unset/empty if the event is not a PR, but a push to master (or another branch where we want to run the action). Thus, we check if we have that and if not, we simply clone from the "regular" repo Github gives us. I tried that with PRs from a fork and within our repo (where it worked), but I also want to test it with pushing to a branch in our repo.

I have no idea how to tell this in a nice way, but I guess it should also feature some links with information about these contexts, i.e., https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#default-environment-variables and https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#github-context.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should now work for both scenarios: https://github.com/hyrise/sql-parser/actions/workflows/ci.yml

image

The first line is a PR within the base repository, the second one is a PR from a fork, and the third line is a push to a branch within the base repo (which was added to the branches where updates trigger action runs for this test).

git checkout $GITHUB_HEAD_REF

- name: Setup (macOS)
Expand Down