-
Notifications
You must be signed in to change notification settings - Fork 26
/
config.yml
130 lines (120 loc) · 3.73 KB
/
config.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
version: 2.1
orbs:
python: circleci/python@1.2
workflows:
backup-notion:
jobs:
- export-workspace:
filters:
branches:
only: feature/circleci
- publish-github-release:
requires:
- export-workspace
backup-notion-nightly:
triggers:
- schedule:
cron: "0 0 * * *" # every day UTC±00:00
filters:
branches:
only:
- master
jobs:
- export-workspace
- publish-github-release:
requires:
- export-workspace
jobs:
export-workspace:
parameters:
branch_build:
type: string
default: master
working_directory: ~/project-export
docker:
- image: cimg/python:3.8
steps:
- run:
name: Check Env
command: |
if [ ! ${GH_TOKEN} ]; then
echo "'GH_TOKEN' not presented!"
exit 1
fi
if [ ! ${NOTION_TOKEN_V2} ]; then
echo "'NOTION_TOKEN_V2' not presented!"
exit 1
fi
- attach_workspace:
at: ~/project-export
- checkout
- run:
name: Python pip install
command: |
pip install requests
pip install python-slugify
- run:
name: Run action
command: |
PYTHONPATH=./ python main.py \
--token_v2 ${NOTION_TOKEN_V2} \
--action "all" \
--output "build/exported"
- run:
name: Dump outputs
command: |
pwd && ls -l && ls -l ~/project-export/build/exported
- run:
name: Collect zip files
command: |
echo "Collect exported zip files:"
if [ -d '~/project-export/build/archives' ]; then
rm -rf ~/project-export/build/archives
fi
mkdir ~/project-export/build/archives
find ~/project-export/build/exported -name "*.zip" -type f | xargs -I '{}' echo '{}'
find ~/project-export/build/exported -name "*.zip" -type f | xargs -I '{}' mv '{}' ~/project-export/build/archives
- persist_to_workspace:
root: ~/project-export
paths:
- ./build/archives
- run:
name: Push unzip files to dist
command: |
# skip push for test
exit 0
git clone -b feature/backups "https://${GH_TOKEN}@github.com/kaedea/notion-up.git" deploy
cd deploy
git config user.name "Kaede"
git config user.email "kidhaibara@gmail.com"
# Copy files
if [ -d 'dist' ]; then
rm -rf dist
fi
mkdir dist
echo "Copy unzipfiles:"
cp -r ~/project-export/build/exported/. dist/
# Git push
git add *
git status
git commit -a -m "Circleci-bot notion backup - ${CIRCLE_BUILD_NUM}"
git push --force --quiet "https://${GH_TOKEN}@github.com/kaedea/notion-up.git"
publish-github-release:
parameters:
branch_build:
type: string
default: master
working_directory: ~/project-github-release
docker:
- image: cibuilds/github:0.13
steps:
- attach_workspace:
at: ~/project-export
- run:
name: "Publish Release on GitHub"
command: |
# skip github-release for test
# exit 0
pwd && ls -l && ls -l ~/project-export/build/archives
VERSION=$(date '+%Y-%m-%d')
ghr -t ${GH_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ~/project-export/build/archives