forked from SwiftDocOrg/github-wiki-publish-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
68 lines (54 loc) · 1.6 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
#!/bin/bash
function debug() {
echo "::debug file=${BASH_SOURCE[0]},line=${BASH_LINENO[0]}::$1"
}
function warning() {
echo "::warning file=${BASH_SOURCE[0]},line=${BASH_LINENO[0]}::$1"
}
function error() {
echo "::error file=${BASH_SOURCE[0]},line=${BASH_LINENO[0]}::$1"
}
function add_mask() {
echo "::add-mask::$1"
}
if [ -z "$GITHUB_ACTOR" ]; then
error "GITHUB_ACTOR environment variable is not set"
exit 1
fi
if [ -z "$GITHUB_REPOSITORY" ]; then
error "GITHUB_REPOSITORY environment variable is not set"
exit 1
fi
if [ -z "$GH_PERSONAL_ACCESS_TOKEN" ]; then
error "GH_PERSONAL_ACCESS_TOKEN environment variable is not set"
exit 1
fi
add_mask "${GH_PERSONAL_ACCESS_TOKEN}"
if [ -z "${WIKI_COMMIT_MESSAGE:-}" ]; then
debug "WIKI_COMMIT_MESSAGE not set, using default"
WIKI_COMMIT_MESSAGE='Automatically publish wiki'
fi
GIT_REPOSITORY_URL="https://${GH_PERSONAL_ACCESS_TOKEN}@github.com/$GITHUB_REPOSITORY.wiki.git"
debug "Checking out wiki repository"
tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX)
(
cd "$tmp_dir" || exit 1
git init
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
git pull "$GIT_REPOSITORY_URL"
)
debug "Enumerating contents of $1"
for file in $(find $1 -maxdepth 1 -type f -name '*.md' -execdir basename '{}' ';'); do
debug "Copying $file"
cp "$1/$file" "$tmp_dir"
done
debug "Committing and pushing changes"
(
cd "$tmp_dir" || exit 1
git add .
git commit -m "$WIKI_COMMIT_MESSAGE"
git push --set-upstream "$GIT_REPOSITORY_URL" master
)
rm -rf "$tmp_dir"
exit 0