Skip to content

Commit

Permalink
ci: fix error in publish-pr-review-site action (#4242)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexprudhomme authored Aug 5, 2024
1 parent 99bbef1 commit 1db110c
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions .github/actions/publish-pr-review-site/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,29 @@ runs:
token: ${{inputs.token}}
- name: 'Setup branch'
run: |
if [[ -z $(git ls-remote --heads origin refs/heads/${{github.event.pull_request.number}} | tr -s '[:blank:]') ]]; then
git switch -c "${{github.event.pull_request.number}}"
BRANCH_NAME="${{ github.event.pull_request.number }}"
git fetch origin
# Check if the branch exists on the remote
if git show-ref --verify --quiet "refs/remotes/origin/$BRANCH_NAME"; then
echo "Branch $BRANCH_NAME exists remotely. Checking out..."
# If the branch exists locally, switch to it; otherwise, create a tracking branch
if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then
git switch "$BRANCH_NAME"
else
git switch --track "origin/$BRANCH_NAME"
fi
# Reset the branch to match the latest commit from the main branch
git reset --hard origin/main
else
git fetch origin "refs/heads/${{github.event.pull_request.number}}"
git switch "${{github.event.pull_request.number}}"
git reset --hard main
echo "Branch $BRANCH_NAME does not exist remotely. Creating a new branch..."
# Create a new branch locally and push it to the remote
git switch -c "$BRANCH_NAME"
git push -u origin "$BRANCH_NAME"
fi
working-directory: prs
shell: bash
Expand Down

0 comments on commit 1db110c

Please sign in to comment.