Skip to content

Commit

Permalink
Update backup.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
mgz0227 authored May 3, 2024
1 parent 8493a75 commit c56f075
Showing 1 changed file with 26 additions and 31 deletions.
57 changes: 26 additions & 31 deletions .github/workflows/backup.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,40 @@
name: Backup Main Branch
name: Backup main branch

on:
push:
branches: [ main ]
branches: [main]

jobs:
backup:
name: Backup Main Branch
backup_main_branch:
name: Backup main branch
runs-on: ubuntu-latest
steps:
- name: Checkout Main Branch
- name: Checkout main branch
uses: actions/checkout@v2
with:
ref: main

- name: Get Current Datetime
id: datetime
run: echo "::set-output name=datetime::$(date '+%Y-%m-%d_%H-%M-%S')"

- name: Archive Main Branch Code
run: |
BACKUP_DATETIME=$(echo "${{ steps.datetime.outputs.datetime }}")
git archive --format=tar.gz --output=main_backup_${BACKUP_DATETIME}.tar.gz HEAD
- name: Configure Git
- name: Backup main branch as tar.gz
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git archive --format=tar.gz --output=main_backup_$(date +"%Y%m%d%H%M%S").tar.gz main
mkdir -p backups
mv main_backup_*.tar.gz backups/
shell: bash

- name: Add Backup Branch
- name: Push main branch backup to backup branch
run: |
git checkout -b backup || git checkout backup
mkdir -p backups
BACKUP_DATETIME=$(echo "${{ steps.datetime.outputs.datetime }}")
mv main_backup_${BACKUP_DATETIME}.tar.gz backups/
git add -A
git commit -m "Auto backup main branch code"
- name: GitHub Push Backup Branch
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.HARMONY_BACKUP }}
branch: backup
force: true
git config --local user.email "[email protected]"
git config --local user.name "mgz0227"
git remote add backup_origin https://github.com/mgz0227/legado-Harmony.git
git fetch backup_origin
git checkout -b backup_branch backup_origin/backup || git checkout -b backup_branch
mv backups/main_backup_*.tar.gz ./
git add main_backup_*.tar.gz
git commit -m "Backup main branch at $(date)"
git push backup_origin backup_branch
git checkout main
shell: bash

0 comments on commit c56f075

Please sign in to comment.