-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[create-pull-request] automated change
- Loading branch information
nektos/act
authored
Dec 6, 2024
1 parent
b9b6191
commit fafe3a6
Showing
3 changed files
with
799 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
name: Update Model Prices | ||
|
||
on: | ||
schedule: | ||
- cron: '0 8 * * *' | ||
workflow_dispatch: | ||
|
||
env: | ||
BRANCH_PREFIX: update | ||
BOT_NAME: github-actions[bot] | ||
BOT_EMAIL: github-actions[bot]@users.noreply.github.com | ||
|
||
jobs: | ||
update-prices: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
|
||
steps: | ||
- uses: actions/[email protected] | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Cache Python dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.x' | ||
cache: 'pip' | ||
|
||
- name: Get current date | ||
id: date | ||
run: echo "date=$(date +'%d-%m-%Y')" >> $GITHUB_OUTPUT | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install ".[dev]" | ||
- name: Configure Git | ||
run: | | ||
git config --global user.name '${{ env.BOT_NAME }}' | ||
git config --global user.email '${{ env.BOT_EMAIL }}' | ||
- name: Run update script and check changes | ||
id: check_changes | ||
timeout-minutes: 2 | ||
run: | | ||
set -x # Enable debug mode | ||
# Run the update script first | ||
python update_prices.py | ||
# Check for changes in specific files | ||
if [[ -n "$(git status --porcelain pricing_table.md tokencost/model_prices.json)" ]]; then | ||
echo "Changes detected in price files" | ||
echo "changes=true" >> $GITHUB_OUTPUT | ||
git diff pricing_table.md tokencost/model_prices.json > changes.diff | ||
else | ||
echo "No changes detected in price files" | ||
echo "changes=false" >> $GITHUB_OUTPUT | ||
exit 0 # Exit early if no changes | ||
fi | ||
- name: Create branch and commit changes | ||
if: steps.check_changes.outputs.changes == 'true' | ||
timeout-minutes: 5 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
set -x | ||
# Configure Git with authentication | ||
git config --global url."https://${{ secrets.GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/" | ||
# Fetch latest main and create new branch | ||
git fetch origin main | ||
git checkout -b "${{ env.BRANCH_PREFIX }}/${{ steps.date.outputs.date }}" origin/main | ||
# Run the update script again on the new branch | ||
python update_prices.py | ||
# Stage and commit only price-related files | ||
git add pricing_table.md tokencost/model_prices.json | ||
git commit -m "Update model prices for ${{ steps.date.outputs.date }}" | ||
# Push to the branch | ||
git push origin "${{ env.BRANCH_PREFIX }}/${{ steps.date.outputs.date }}" | ||
- name: Generate PR description | ||
if: steps.check_changes.outputs.changes == 'true' | ||
run: | | ||
echo "## Model Price Updates for ${{ steps.date.outputs.date }}" > pr_body.md | ||
echo "" >> pr_body.md | ||
echo "### Changes Summary" >> pr_body.md | ||
echo '```diff' >> pr_body.md | ||
cat changes.diff >> pr_body.md | ||
echo '```' >> pr_body.md | ||
- name: Create Pull Request | ||
if: steps.check_changes.outputs.changes == 'true' | ||
uses: peter-evans/create-pull-request@v5 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
title: "Update model prices for ${{ steps.date.outputs.date }}" | ||
body-path: pr_body.md | ||
branch: ${{ env.BRANCH_PREFIX }}/${{ steps.date.outputs.date }} | ||
base: main | ||
labels: automated-pr, price-update |
Oops, something went wrong.