|
| 1 | +name: Sync Homebrew Formula |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - 'Formula/opencodex.rb' |
| 7 | + branches: [main] |
| 8 | + workflow_dispatch: # 允许手动触发 |
| 9 | + |
| 10 | +jobs: |
| 11 | + sync: |
| 12 | + name: Sync to homebrew-opencodex |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout main repo |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Check if formula changed |
| 22 | + id: check |
| 23 | + run: | |
| 24 | + # 检查 Formula/opencodex.rb 是否有更改 |
| 25 | + if git diff --name-only HEAD~1 HEAD | grep -q "Formula/opencodex.rb"; then |
| 26 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 27 | + echo "✅ Formula/opencodex.rb has changed" |
| 28 | + else |
| 29 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 30 | + echo "ℹ️ No changes to Formula/opencodex.rb" |
| 31 | + fi |
| 32 | +
|
| 33 | + - name: Setup Git |
| 34 | + if: steps.check.outputs.changed == 'true' |
| 35 | + run: | |
| 36 | + git config --global user.name "github-actions[bot]" |
| 37 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 38 | +
|
| 39 | + - name: Clone homebrew-opencodex repo |
| 40 | + if: steps.check.outputs.changed == 'true' |
| 41 | + env: |
| 42 | + GH_PAT: ${{ secrets.GH_PAT }} |
| 43 | + run: | |
| 44 | + git clone https://${GH_PAT}@github.com/3kaiu/homebrew-opencodex.git /tmp/homebrew-opencodex |
| 45 | +
|
| 46 | + - name: Copy formula and push |
| 47 | + if: steps.check.outputs.changed == 'true' |
| 48 | + env: |
| 49 | + GH_PAT: ${{ secrets.GH_PAT }} |
| 50 | + run: | |
| 51 | + # 复制 formula 文件 |
| 52 | + cp Formula/opencodex.rb /tmp/homebrew-opencodex/opencodex.rb |
| 53 | +
|
| 54 | + # 进入目标仓库 |
| 55 | + cd /tmp/homebrew-opencodex |
| 56 | +
|
| 57 | + # 检查是否有更改 |
| 58 | + if git diff --quiet opencodex.rb; then |
| 59 | + echo "ℹ️ No changes to sync" |
| 60 | + exit 0 |
| 61 | + fi |
| 62 | +
|
| 63 | + # 提交并推送 |
| 64 | + git add opencodex.rb |
| 65 | + git commit -m "chore: sync formula from opencode-x |
| 66 | +
|
| 67 | +Automatically synced from: https://github.com/3kaiu/opencode-x |
| 68 | +Commit: ${{ github.sha }}" |
| 69 | + |
| 70 | + git push origin main |
| 71 | + |
| 72 | + echo "✅ Successfully synced formula to homebrew-opencodex" |
| 73 | + |
| 74 | + - name: Skip sync (no changes) |
| 75 | + if: steps.check.outputs.changed == 'false' |
| 76 | + run: | |
| 77 | + echo "ℹ️ Skipping sync - no changes to formula" |
0 commit comments