-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish-to-gh-pages
executable file
·75 lines (63 loc) · 1.79 KB
/
publish-to-gh-pages
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
#!/bin/bash
set -e
set -o pipefail
# Some of the code here was borrowed from Jess's example action:
# https://github.com/jessfraz/branch-cleanup-action
# This one is populated by GitHub for free :)
if [[ -z "$GITHUB_REPOSITORY" ]]; then
echo "Set the GITHUB_REPOSITORY env variable."
exit 1
fi
# Custom Required Environment Variables
if [[ -z "$PUBLISH_DIRECTORY" ]]; then
echo "Set the GITHUB_ACTOR env variable."
exit 1
fi
if [[ -z "$GIT_PERSONAL_ACCESS_TOKEN" ]]; then
echo "Set the GIT_PERSONAL_ACCESS_TOKEN env variable."
exit 1
fi
if [[ -z "$GIT_USER" ]]; then
echo "Set the GIT_USER env variable."
exit 1
fi
if [[ -z "$GIT_EMAIL" ]]; then
echo "Set the GIT_EMAIL env variable."
exit 1
fi
main(){
repo="repo/"
repo_url="https://$GIT_USER:$GIT_PERSONAL_ACCESS_TOKEN@github.com/$GITHUB_REPOSITORY.git"
build_files="../$PUBLISH_DIRECTORY/*"
git clone $repo_url $repo
cd $repo
# Set the commit user details
git config user.name "$GIT_USER"
git config user.email "$GIT_EMAIL"
git config remote.origin.url $repo_url
# Get the repository's gh-pages branch
git fetch origin gh-pages
git checkout gh-pages
# Remove the current files
git rm --ignore-unmatch -rf .
echo "Copy over files from $build_files"
cp -r $build_files .
ls -al
git status
# Check to see if the number of changes is 0
changes=$(git status --short | wc -l)
if [[ "$changes" -eq "0" ]]; then
# Don't commit a change if no changes to be made
echo "No changes from current published build, exiting."
else
# Commit the current changes and push
git add .
git commit -m "Published via Github Action."
git status
git push -u origin gh-pages
fi
# Clean up
cd ..
rm -rf $repo
}
main "$@"