|
| 1 | +name: Backup Fork |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 0 * * 0' # 每週日午夜運行一次 |
| 6 | + workflow_dispatch: # 允許手動觸發 |
| 7 | + |
| 8 | +jobs: |
| 9 | + backup: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout repository |
| 13 | + uses: actions/checkout@v4 |
| 14 | + with: |
| 15 | + fetch-depth: 0 # 獲取所有歷史記錄和標籤 |
| 16 | + |
| 17 | + - name: List all branches |
| 18 | + id: list_branches |
| 19 | + run: | |
| 20 | + git fetch --all |
| 21 | + git branch -r | grep -v '\->' | grep 'upstream/' | sed 's/upstream\///' > branches.txt |
| 22 | + echo "branches=$(cat branches.txt | tr '\n' ' ')" >> $GITHUB_OUTPUT |
| 23 | +
|
| 24 | + - name: Add upstream repository |
| 25 | + run: | |
| 26 | + git remote add upstream https://github.com/wdzeng/shopee-coins-bot.git |
| 27 | + git fetch upstream |
| 28 | +
|
| 29 | + - name: Backup each branch |
| 30 | + run: | |
| 31 | + for branch in $(echo "${{ steps.list_branches.outputs.branches }}"); do |
| 32 | + git checkout $branch || git checkout -b $branch upstream/$branch |
| 33 | + git merge upstream/$branch || echo "No changes to merge or merge conflict" |
| 34 | + git push --tags backup $branch || echo "Failed to push $branch to backup repository" |
| 35 | + done |
| 36 | + env: |
| 37 | + GH_TOKEN: ${{ secrets.GH_TOKEN }} |
| 38 | + |
| 39 | + - name: Configure Git |
| 40 | + run: | |
| 41 | + git config --global user.name 'github-actions' |
| 42 | + git config --global user.email '[email protected]' |
| 43 | +
|
| 44 | + - name: Create version tag |
| 45 | + run: | |
| 46 | + TIMESTAMP=$(date +"%Y%m%d%H%M%S") |
| 47 | + git tag -a "backup-$TIMESTAMP" -m "Backup on $TIMESTAMP" |
| 48 | +
|
| 49 | + - name: Push changes and tags to backup |
| 50 | + env: |
| 51 | + GH_TOKEN: ${{ secrets.GH_TOKEN }} |
| 52 | + run: | |
| 53 | + git remote add backup https://[email protected]/LostSunset/shopee-coins-bot.git |
| 54 | + git push backup --tags || echo "Failed to push tags to backup repository" |
| 55 | +
|
| 56 | + - name: Check for errors |
| 57 | + if: failure() |
| 58 | + run: | |
| 59 | + echo "Workflow failed. Please check the logs for more information." |
0 commit comments