Skip to content
Latchkey

同步模型价格数据 workflow (Wei-Shaw/claude-relay-service)

The 同步模型价格数据 workflow from Wei-Shaw/claude-relay-service, explained and optimized by Latchkey.

A

CI health: A - excellent

Point runs-on at Latchkey and get job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: Wei-Shaw/claude-relay-service.github/workflows/sync-model-pricing.ymlLicense MITView source

What it does

This is the 同步模型价格数据 workflow from the Wei-Shaw/claude-relay-service repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
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://github.com/Wei-Shaw/model-price-repo/raw/refs/heads/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

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: 同步模型价格数据
 
on:
  schedule:
    - cron: '*/10 * * * *'
  workflow_dispatch: {}
 
jobs:
  sync-pricing:
    timeout-minutes: 30
    runs-on: latchkey-small
    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://github.com/Wei-Shaw/model-price-repo/raw/refs/heads/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
 

What changed

What Latchkey heals here

This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:

This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow