From 51085ef157337a27da9d4b95f28e27a6ca512e46 Mon Sep 17 00:00:00 2001 From: Alan Tsai Date: Fri, 12 Jul 2024 11:03:05 +0800 Subject: [PATCH] chore: update the order when checkout branch happen before script will be updating at main branch cause a conflict when latter try to update the data/* branch so checkout/create branch first --- .../fetch-copilot-usage-metrics-data.yaml | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/fetch-copilot-usage-metrics-data.yaml b/.github/workflows/fetch-copilot-usage-metrics-data.yaml index 889cac1..cf9d8b1 100644 --- a/.github/workflows/fetch-copilot-usage-metrics-data.yaml +++ b/.github/workflows/fetch-copilot-usage-metrics-data.yaml @@ -19,6 +19,19 @@ jobs: fi - name: Checkout repository uses: actions/checkout@v2 + - name: Fetch and Switch Branch + run: | + echo "Ensuring git fetch to update the local reference..." + git fetch + + echo "Checking if branch exists..." + if git show-ref --verify --quiet refs/heads/${{ env.BRANCH_NAME }} || git show-ref --verify --quiet refs/remotes/origin/${{ env.BRANCH_NAME }}; then + echo "Branch exists, switching to it" + git checkout ${{ env.BRANCH_NAME }} + else + echo "Branch does not exist, creating and switching to it" + git checkout -b ${{ env.BRANCH_NAME }} + fi - name: Set up CURL command base and Fetch data run: | if [ "${{ env.AREA }}" == "org" ]; then @@ -58,19 +71,7 @@ jobs: echo "Uncommitted changes detected, stashing..." git stash push -m "Stashing changes before switching branches" fi - - echo "Ensuring git fetch to update the local reference..." - git fetch - - echo "Checking if branch exists..." - if git show-ref --verify --quiet refs/heads/${{ env.BRANCH_NAME }} || git show-ref --verify --quiet refs/remotes/origin/${{ env.BRANCH_NAME }}; then - echo "Branch exists, switching to it" - git checkout ${{ env.BRANCH_NAME }} - else - echo "Branch does not exist, creating and switching to it" - git checkout -b ${{ env.BRANCH_NAME }} - fi - + echo "Configuring Git..." git config --global user.email "bot@githubaction.com" git config --global user.name "GitHub Action Bot" @@ -84,4 +85,4 @@ jobs: if ! git push origin ${{ env.BRANCH_NAME }}; then echo "Failed to push changes, checking for issues..." # Handle specific push failures here, e.g., pull and merge before retrying - fi \ No newline at end of file + fi