Update Token Prices #9
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
name: Update Token Prices | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 0 * * *' | |
jobs: | |
update-prices: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 2 | |
- name: Set up Python | |
uses: actions/setup-python@v3 | |
with: | |
python-version: '3.x' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -e ".[dev]" | |
- name: Get current date | |
id: date | |
run: | | |
echo "DATE=$(date +'%d-%m-%Y')" >> $GITHUB_ENV | |
- name: Create branch | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git checkout -b update/${{ env.DATE }} | |
- name: Run update script | |
run: python update_prices.py | |
- name: Generate PR body | |
id: pr-body | |
run: | | |
body="## Changes ${{ env.DATE }}\n\n" | |
# Get git diff of model_prices.json | |
diff_output=$(git diff --unified=0 model_prices.json) | |
if [ -n "$diff_output" ]; then | |
body+="### Updated Models\n" | |
# Extract changed model names using grep and sed | |
changed_models=$(echo "$diff_output" | grep '^[+-] "' | sed 's/^[+-] "\(.*\)".*/\1/' | sort -u) | |
if [ -n "$changed_models" ]; then | |
while IFS= read -r model; do | |
body+="- $model\n" | |
done <<< "$changed_models" | |
else | |
body+="- No models updated\n" | |
fi | |
else | |
body+="### No Changes\n" | |
body+="- No changes detected in model prices\n" | |
fi | |
echo "body<<EOF" >> $GITHUB_ENV | |
echo "$body" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
- name: Commit changes | |
run: | | |
git add . | |
git commit -m "Updated prices as on ${{ env.DATE }}" | |
git push origin update/${{ env.DATE }} | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
title: "Updated prices as on ${{ env.DATE }}" | |
body: ${{ env.body }} | |
branch: update/${{ env.DATE }} | |
base: main | |
delete-branch: true |