From 8f5c12366015d36aec0e8a3646e4b39f56764a15 Mon Sep 17 00:00:00 2001 From: oskar <53711292+oskarkocol@users.noreply.github.com> Date: Mon, 13 Jul 2026 19:11:01 +0700 Subject: [PATCH] safely check for existing branch --- .../auto_update_price_and_context_window.yml | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/.github/workflows/auto_update_price_and_context_window.yml b/.github/workflows/auto_update_price_and_context_window.yml index 185643fd0e5..d16ac269199 100644 --- a/.github/workflows/auto_update_price_and_context_window.yml +++ b/.github/workflows/auto_update_price_and_context_window.yml @@ -17,34 +17,33 @@ jobs: steps: - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 with: - fetch-depth: 0 persist-credentials: false - name: Set up uv uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7 with: version: "0.10.9" - - name: Create and push updated branch + - name: Update JSON Data + run: | + uv run --frozen --with 'aiohttp==3.13.3' python ".github/workflows/auto_update_price_and_context_window_file.py" + - name: Create Pull Request env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - set -euo pipefail - - BRANCH_NAME="auto-update-price-and-context-window-$(date +'%Y-%m-%d')" - echo "Creating branch: ${BRANCH_NAME}" - git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - - git fetch origin main "${BRANCH_NAME}" || true - + BRANCH_NAME="auto-update-price-and-context-window-$(date +'%Y-%m-%d')" + BASE_BRANCH="${{ github.event.repository.default_branch }}" + git fetch origin "${BRANCH_NAME}" || true if git show-ref --verify --quiet "refs/remotes/origin/${BRANCH_NAME}"; then - echo "Branch ${BRANCH_NAME} already exists. Skipping creation." - exit 0 + git checkout -B "${BRANCH_NAME}" "origin/${BRANCH_NAME}" + else + git checkout -b "${BRANCH_NAME}" fi - - git checkout -b "${BRANCH_NAME}" origin/main - uv run --frozen --with 'aiohttp==3.13.3' python ".github/workflows/auto_update_price_and_context_window_file.py" git add model_prices_and_context_window.json git commit -m "Update model_prices_and_context_window.json file: $(date +'%Y-%m-%d')" git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "${BRANCH_NAME}" - echo "Successfully created and pushed branch: ${BRANCH_NAME}" + gh pr create --title "Update model_prices_and_context_window.json file" \ + --body "Automated update for model_prices_and_context_window.json" \ + --head "${BRANCH_NAME}" \ + --base "${BASE_BRANCH}"