Skip to content

Commit

Permalink
fixing checkout by trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadav Ben Ami authored and Nadav Ben Ami committed Oct 10, 2024
1 parent 68b692f commit 7c9206d
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions .github/workflows/test-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,35 @@ jobs:
# Check out the branch from the pull request, whether it's from a fork or not
- name: Checkout the pull request's branch
run: |
if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then
echo "PR from a fork detected. Checking out the fork's branch."
git remote add fork https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git
git fetch fork ${{ github.event.pull_request.head.ref }}
git checkout -B ci-testing-branch FETCH_HEAD
set -ex
# debug
echo "==== before"
git status
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then
echo "PR from a fork detected. Checking out the fork's branch."
git remote add fork https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git
git fetch fork ${{ github.event.pull_request.head.ref }}
git checkout -B ci-testing-branch FETCH_HEAD
else
echo "PR from the same repository detected. Checking out the branch."
git fetch origin ${{ github.event.pull_request.head.ref }}
git checkout ${{ github.event.pull_request.head.ref }}
fi
elif [[ "${{ github.event_name }}" == 'workflow_dispatch' ]]; then
# we belive that `actions/checkout` will checkout to the branch that you chose in the `dispatch` tab
# so we do nothing
echo "we're in the right branch. no need to checkout (dispatch)"
elif [[ "${{ github.event_name }}" == 'push' ]]; then
# we belive that `actions/checkout` will checkout to the branch that we push into (i.e. either `dev` or `main`)
echo "we're in the right branch. no need to checkout (push)"
else
echo "PR from the same repository detected. Checking out the branch."
git fetch origin ${{ github.event.pull_request.head.ref }}
git checkout ${{ github.event.pull_request.head.ref }}
echo "we're not it push/pull/dispatch. error."
exit 1
fi
# debug
echo "==== after"
git status
- name: Set up Python
uses: actions/setup-python@v5
Expand Down

0 comments on commit 7c9206d

Please sign in to comment.