forked from Moo-Salaah/Wiki-Action-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-wiki.sh
53 lines (41 loc) · 1.26 KB
/
update-wiki.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
#!/bin/sh
set -eu
WIKI_DIR='wiki'
TEMP_REPO_DIR="wiki_action_$GITHUB_REPOSITORY$GITHUB_SHA"
TEMP_WIKI_DIR="wiki_action_$GITHUB_REPOSITORY$WIKI_DIR$GITHUB_SHA"
if [ -z "$GH_TOKEN" ]; then
echo "Token is not specified"
exit 1
fi
if !(which node > /dev/null); then
echo "node is not installed"
exit 1
fi
#Clone repo
echo "Cloning repo https://github.com/$GITHUB_REPOSITORY"
git clone "https://$GITHUB_ACTOR:[email protected]/$GITHUB_REPOSITORY" "$TEMP_REPO_DIR"
cd "$TEMP_REPO_DIR"
#Clone wiki repo
echo "Cloning wiki repo https://github.com/$GITHUB_REPOSITORY.wiki.git"
git clone "https://$GITHUB_ACTOR:[email protected]/$GITHUB_REPOSITORY.wiki.git" "temp_$WIKI_DIR"
#build Wiki
npm ci
npm run docs
npm run html2md
#Get commit details
author=`git log -1 --format="%an"`
email=`git log -1 --format="%ae"`
message=`git log -1 --format="%s"`
echo "Copying edited wiki"
cp -R "temp_$WIKI_DIR/.git" "$WIKI_DIR/"
echo "Checking if wiki has changes"
cd "$WIKI_DIR"
git config --local user.email "$email"
git config --local user.name "$author"
git add .
if git diff-index --quiet HEAD; then
echo "Nothing changed"
exit 0
fi
echo "Pushing changes to wiki"
git commit -m "$message" && git push "https://$GITHUB_ACTOR:[email protected]/$GITHUB_REPOSITORY.wiki.git"