Fix branch checkout

This commit is contained in:
2025-05-03 16:31:34 +02:00
parent a54d72de9e
commit 57e920e264

View File

@@ -22,14 +22,35 @@ jobs:
- name: Create or Checkout Branch - name: Create or Checkout Branch
id: branch id: branch
run: | run: |
BRANCH_NAME="emojis-autoupdate-$(date +%s)" # Create a new branch name with timestamp
EXISTING_BRANCH=$(git branch -r | grep "origin/emojis-autoupdate-") NEW_BRANCH_NAME="emojis-autoupdate-$(date +%s)"
# Check for existing branches
git fetch origin
EXISTING_BRANCH=$(git branch -r | grep "origin/emojis-autoupdate-" || true)
if [ -z "$EXISTING_BRANCH" ]; then if [ -z "$EXISTING_BRANCH" ]; then
git checkout -b $BRANCH_NAME # No existing branch, create a new one
echo "Creating new branch: $NEW_BRANCH_NAME"
git checkout -b $NEW_BRANCH_NAME
BRANCH_NAME=$NEW_BRANCH_NAME
else else
BRANCH_NAME=$(echo $EXISTING_BRANCH | sed 's|origin/||') # Found existing branch, extract name without "origin/"
git checkout $BRANCH_NAME BRANCH_NAME=$(echo $EXISTING_BRANCH | sed 's|origin/||' | tr -d '[:space:]')
echo "Found existing branch: $BRANCH_NAME"
# Create a local tracking branch
git checkout -b $BRANCH_NAME --track origin/$BRANCH_NAME || git checkout -b $BRANCH_NAME
# If that fails, fall back to new branch
if [ $? -ne 0 ]; then
echo "Failed to checkout existing branch, creating new: $NEW_BRANCH_NAME"
git checkout -b $NEW_BRANCH_NAME
BRANCH_NAME=$NEW_BRANCH_NAME
fi fi
fi
echo "Using branch: $BRANCH_NAME"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV
- name: Run UV Python Script - name: Run UV Python Script