Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: fix error in publish-pr-review-site action #4242

Merged
merged 6 commits into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading