Skip to content

Update backup.yml

Update backup.yml #5

Workflow file for this run

name: Backup Main Branch
on:
push:
branches: [ main ]
jobs:
backup:
name: Backup Main Branch
runs-on: ubuntu-latest
steps:
- name: Checkout Main Branch
uses: actions/checkout@v2
with:
ref: main
- name: Archive Main Branch Code
run: |
datetime=$(date '+%Y-%m-%d_%H-%M-%S')
git archive --format=tar.gz --output=main_backup_$datetime.tar.gz HEAD
- name: Configure Git
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
- name: Add Backup Branch
run: |
git checkout -b backup || git checkout backup
mkdir -p backups
mv ../main_backup_$datetime.tar.gz backups/
git add -A
git commit -m "Auto backup main branch code"
git push origin backup
- name: Switch Back to Main Branch
run: git checkout main