更新本地包日期 #272
This file contains hidden or 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: 更新本地包日期 | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 */2 * * *' | |
| permissions: | |
| contents: write | |
| jobs: | |
| update: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 拉取仓库 | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 1 | |
| - name: 获取远程最新名称 | |
| id: get-remote | |
| run: | | |
| URL="http://rihou.cc:88/json/market.json" | |
| JSON=$(curl -fsSL --max-time 15 "$URL") | |
| REMOTE_NAME=$(echo "$JSON" | jq -r '.[] | select(.name=="本地包") | .list[0].name') | |
| if [ -z "$REMOTE_NAME" ] || [ "$REMOTE_NAME" = "null" ]; then | |
| echo "❌ remote not found" | |
| exit 1 | |
| fi | |
| echo "remote_name=$REMOTE_NAME" >> $GITHUB_OUTPUT | |
| - name: 读取本地名称 | |
| id: get-local | |
| run: | | |
| LOCAL_NAME=$(jq -r '.[0].list[] | select(.url | contains("vox本地包.zip")) | .name' app.json) | |
| if [ -z "$LOCAL_NAME" ] || [ "$LOCAL_NAME" = "null" ]; then | |
| echo "❌ local not found" | |
| exit 1 | |
| fi | |
| echo "local_name=$LOCAL_NAME" >> $GITHUB_OUTPUT | |
| - name: 对比是否需要更新 | |
| id: compare | |
| run: | | |
| if [ "${{ steps.get-remote.outputs.remote_name }}" = "${{ steps.get-local.outputs.local_name }}" ]; then | |
| echo "need_update=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "need_update=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: 仅替换目标name,完全保留原JSON格式 | |
| if: steps.compare.outputs.need_update == 'true' | |
| run: | | |
| NEW_NAME="${{ steps.get-remote.outputs.remote_name }}" | |
| LOCAL_NAME="${{ steps.get-local.outputs.local_name }}" | |
| FILE="app.json" | |
| # 找到包含 vox本地包.zip 的区块,取出对应的name行,用sed原地替换 | |
| sed -i.bak \ | |
| "/\"url\":.*vox本地包.zip/,/}/{s|\"name\": \"$LOCAL_NAME\"|\"name\": \"$NEW_NAME\"|}" \ | |
| "$FILE" | |
| # 删除sed生成的备份文件 | |
| rm -f "${FILE}.bak" | |
| - name: 提交并推送修改 | |
| if: steps.compare.outputs.need_update == 'true' | |
| run: | | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git config user.name "github-actions[bot]" | |
| git add app.json | |
| if git diff --cached --quiet; then | |
| echo "无实际变更,跳过提交" | |
| exit 0 | |
| fi | |
| git commit -m "update local package name" | |
| git push origin HEAD |