-
Notifications
You must be signed in to change notification settings - Fork 20
/
entrypoint.sh
77 lines (65 loc) · 1.75 KB
/
entrypoint.sh
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
#!/bin/bash
TEMP_CLONE_FOLDER="temp_wiki"
if [ -z "$ACTION_MAIL" ]; then
echo "ACTION_MAIL ENV is missing"
exit 1
fi
if [ -z "$ACTION_NAME" ]; then
echo "ACTION_NAME ENV is missing"
exit 1
fi
if [ -z "$OWNER" ]; then
echo "OWNER ENV is missing. Cannot proceed"
exit 1
fi
if [ -z "$REPO_NAME" ]; then
echo "REPO_NAME ENV is missing. Cannot proceed"
exit 1
fi
if [ -z "$MD_FOLDER" ]; then
echo "MD_FOLDER ENV is missing, using the default one"
MD_FOLDER='.'
fi
if [ ! -z "$SKIP_MD" ]; then
DOC_TO_SKIP=(`echo $SKIP_MD | sed s/,/\ /g`)
else
DOC_TO_SKIP=
fi
if [ -z "$WIKI_PUSH_MESSAGE" ]; then
echo "WIKI_PUSH_MESSAGE ENV is missing, using the default one"
WIKI_PUSH_MESSAGE='Auto Publish new pages'
fi
if [ -z "$TRANSLATE_UNDERSCORE_TO_SPACE" ]; then
echo "Don't translate '_' to space in Markdown's names"
TRANSLATE=0
else
echo "Enable translation of '_' to spaces in Markdown's names"
TRANSLATE=1
fi
mkdir $TEMP_CLONE_FOLDER
cd $TEMP_CLONE_FOLDER
git init
git config user.name $ACTION_NAME
git config user.email $ACTION_MAIL
git pull https://${GH_PAT}@github.com/$OWNER/$REPO_NAME.wiki.git
cd ..
FILES=$(find $MD_FOLDER -maxdepth 1 -type f -name '*.md' -execdir basename '{}' ';')
for i in $FILES; do
realFileName=${i}
if [[ $TRANSLATE -ne 0 ]]; then
realFileName=${i//_/ }
echo "$i -> $realFileName"
else
echo $realFileName
fi
if [[ ! " ${DOC_TO_SKIP[@]} " =~ " ${i} " ]]; then
cp "$MD_FOLDER/$i" "$TEMP_CLONE_FOLDER/${realFileName}"
else
echo "Skip $i as it matches the $SKIP_MD rule"
fi
done
echo "Pushing new pages"
cd $TEMP_CLONE_FOLDER
git add .
git commit -m "$WIKI_PUSH_MESSAGE"
git push --set-upstream https://${GH_PAT}@github.com/$OWNER/$REPO_NAME.wiki.git master