-
Notifications
You must be signed in to change notification settings - Fork 210
42 lines (35 loc) · 1.19 KB
/
backup.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
- name: Switch Back to Main Branch
run: git checkout main