From 58759e3e8d4257a6d2265a6b98ed8d0b622b6966 Mon Sep 17 00:00:00 2001 From: Rajan Paneru Date: Fri, 7 Jun 2024 01:36:19 +0930 Subject: [PATCH] Fix the workflow to update the price * Made sure it checks the file has change * Fix the github config error * Run once a day * If rerun, override the exiting branch with the same name --- .../auto_update_price_and_context_window.yml | 47 +++++++++++++++---- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/.github/workflows/auto_update_price_and_context_window.yml b/.github/workflows/auto_update_price_and_context_window.yml index e7d65242c1..fb35a49af5 100644 --- a/.github/workflows/auto_update_price_and_context_window.yml +++ b/.github/workflows/auto_update_price_and_context_window.yml @@ -2,27 +2,56 @@ name: Updates model_prices_and_context_window.json and Create Pull Request on: schedule: - - cron: "0 0 * * 0" # Run every Sundays at midnight - #- cron: "0 0 * * *" # Run daily at midnight + - cron: "0 0 * * *" # Run daily at midnight jobs: auto_update_price_and_context_window: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - name: Checkout repository + uses: actions/checkout@v3 + - name: Install Dependencies - run: | - pip install aiohttp + run: pip install aiohttp + - name: Update JSON Data + run: python ".github/workflows/auto_update_price_and_context_window_file.py" + + - name: Configure Git run: | - python ".github/workflows/auto_update_price_and_context_window_file.py" + git config user.email "github-actions[bot]@users.noreply.github.com" + git config user.name "github-actions[bot]" + + - name: Check for Changes in JSON File + id: check_changes + run: | + if git diff --exit-code model_prices_and_context_window.json; then + echo "has_changes=false" >> $GITHUB_ENV + else + echo "has_changes=true" >> $GITHUB_ENV + fi + + - name: Commit Changes + if: env.has_changes == 'true' + run: | + git checkout -b auto-update-price-and-context-window-$(date +'%Y-%m-%d') + 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 -f origin auto-update-price-and-context-window-$(date +'%Y-%m-%d') + env: + GH_TOKEN: ${{ secrets.GH_TOKEN }} + - name: Create Pull Request + if: env.has_changes == 'true' run: | - git add model_prices_and_context_window.json - git commit -m "Update model_prices_and_context_window.json file: $(date +'%Y-%m-%d')" + gh auth login --with-token <<< "${{ secrets.GH_TOKEN }}" gh pr create --title "Update model_prices_and_context_window.json file" \ --body "Automated update for model_prices_and_context_window.json" \ --head auto-update-price-and-context-window-$(date +'%Y-%m-%d') \ --base main env: - GH_TOKEN: ${{ secrets.GH_TOKEN }} \ No newline at end of file + GH_TOKEN: ${{ secrets.GH_TOKEN }} + + - name: No Changes Detected + if: env.has_changes == 'false' + run: echo "No changes found in model_prices_and_context_window.json, no pull request created."