Update backup.yml #9
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
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: 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 | |
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 | |
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" | |
git push origin backup | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Switch Back to Main Branch | |
run: git checkout main |