-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
26 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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
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 |