name: 同步模型价格数据 on: schedule: - cron: '*/10 * * * *' workflow_dispatch: {} jobs: sync-pricing: runs-on: ubuntu-latest permissions: contents: write steps: - name: 检出 price-mirror 分支 uses: actions/checkout@v4 with: ref: price-mirror fetch-depth: 0 - name: 下载上游价格文件 id: fetch run: | set -euo pipefail curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json \ -o model_prices_and_context_window.json.new NEW_HASH=$(sha256sum model_prices_and_context_window.json.new | awk '{print $1}') if [ -f model_prices_and_context_window.sha256 ]; then OLD_HASH=$(cat model_prices_and_context_window.sha256 | tr -d ' \n\r') else OLD_HASH="" fi if [ "$NEW_HASH" = "$OLD_HASH" ]; then echo "价格文件无变化,跳过提交" echo "changed=false" >> "$GITHUB_OUTPUT" rm -f model_prices_and_context_window.json.new exit 0 fi mv model_prices_and_context_window.json.new model_prices_and_context_window.json echo "$NEW_HASH" > model_prices_and_context_window.sha256 echo "changed=true" >> "$GITHUB_OUTPUT" echo "hash=$NEW_HASH" >> "$GITHUB_OUTPUT" - name: 提交并推送变更 if: steps.fetch.outputs.changed == 'true' env: NEW_HASH: ${{ steps.fetch.outputs.hash }} run: | set -euo pipefail git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git add model_prices_and_context_window.json model_prices_and_context_window.sha256 COMMIT_MSG="chore: 同步模型价格数据" if [ -n "${NEW_HASH}" ]; then COMMIT_MSG="$COMMIT_MSG (${NEW_HASH})" fi git commit -m "$COMMIT_MSG" git push origin price-mirror