-
Notifications
You must be signed in to change notification settings - Fork 2
94 lines (71 loc) · 3.52 KB
/
contentful_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: contentful automic backup
on:
workflow_dispatch:
schedule:
# 在每周五的 20:00 UTC 运行
- cron: '0 20 * * 5'
jobs:
export:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- id: setup
uses: actions/[email protected]
- id: install
run: npm install -g contentful-cli
- id: export
run: |
export_date=`date +%Y-%m-%d`
echo "export_date=${export_date}" >> $GITHUB_ENV
mkdir contentful/${export_date}
contentful space export --config contentful/export-config.json --export-dir contentful/${export_date}/ --error-log-file contentful/${export_date}/error.json --mt ${{ secrets.Contentful_Export_Token }}
- id: push
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "push the contenful backup file"
- id: conclusion
if: ${{ always() }}
run: |
echo "setup=${{steps.setup.conclusion}}" >> $GITHUB_ENV
echo "install=${{steps.install.conclusion}}" >> $GITHUB_ENV
echo "export=${{steps.export.conclusion}}" >> $GITHUB_ENV
echo "push=${{steps.push.conclusion}}" >> $GITHUB_ENV
[ -f contentful/${{env.export_date}}/error.json ] && echo "backup=failure" >> $GITHUB_ENV || echo "backup=success" >> $GITHUB_ENV
- name: edit the email content out of the export job output
if: ${{ always() }}
run: |
echo ${{env.export}}
if [ ${{env.setup}} == faliure ];then
echo "email_subject=[FAIL]Contentful backup inform" >> $GITHUB_ENV
echo "email_body=setup node.js environment failure" >> $GITHUB_ENV
elif [ ${{env.install}} == faliure ];then
echo "email_subject=[FAIL]Contentful backup inform" >> $GITHUB_ENV
echo "email_body=install contentful cli fail" >> $GITHUB_ENV
elif [ ${{env.export}} == faliure ];then
echo "email_subject=[FAIL]Contentful backup inform" >> $GITHUB_ENV
echo "email_body=export data fail" >> $GITHUB_ENV
elif [ ${{env.push}} == faliure];then
echo "email_subject=[FAIL]Contentful backup inform" >> $GITHUB_ENV
echo "email_body=push data fail" >> $GITHUB_ENV
elif [ ${{env.backup}} == faliure ];then
echo "email_subject=[FAIL]Contentful backup inform" >> $GITHUB_ENV
echo "email_body=contentful data backup fail,here is the log attached" >> $GITHUB_ENV
echo "email_attachments=contentful/${env.export_date}/error.json" >> $GITHUB_ENV
else
echo "email_subject=[SUCCESS]Contentful backup inform" >> $GITHUB_ENV
echo "email_body=successfully backup the contentful data!here is the data attached" >> $GITHUB_ENV
echo "email_attachments=contentful/${{env.export_date}}/export.json" >> $GITHUB_ENV
fi
# - name: Send inform mail
# if: ${{ always() }}
# uses: dawidd6/action-send-mail@master
# with:
# server_address: smtp.163.com
# server_port: 25
# username: ${{ secrets.MAIL_USERNAME }}
# password: ${{ secrets.MAIL_PASSWORD }}
# subject: ${{env.email_subject}}
# to: [email protected]
# from: GitHub Actions
# body: ${{env.email_body}}
# attachments: ${{env.email_attachments}}