forked from thegrb93/StarfallEx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
97 lines (82 loc) · 2.87 KB
/
deploy.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
set -e # Exit with nonzero exit code if anything fails
SOURCE_BRANCH="master"
TARGET_BRANCH="gh-pages"
git config user.name "$(git log -1 $TRAVIS_COMMIT --pretty="%aN")"
git config user.email "$(git log -1 $TRAVIS_COMMIT --pretty="%cE")"
# Save some useful information
REPO=`git config remote.origin.url`
SSH_REPO=${REPO/https:\/\/github.com\//[email protected]:}
SHA=`git rev-parse --verify HEAD`
# Pull requests and commits to other branches shouldn't try to deploy, just build to verify
if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
echo "This is a pull request, won't deply to gh-pages"
if echo $TRAVIS_COMMIT_MESSAGE | grep -q "\[preview\]"; then
echo "Preview requested."
tar -cf doc-preview.tar doc/
echo "Uploading to transfer.sh"
curl -s --upload-file doc-preview.tar "https://transfer.sh/sf-doc-${SHA}.tar" > preview-link.txt
echo "Deploy finished, link: $(<preview-link.txt)"
fi
exit 0
fi
echo "Decrypting SSH key"
openssl aes-256-cbc -K $encrypted_0bb1b763922b_key -iv $encrypted_0bb1b763922b_iv -in deploy_key.enc -out deploy_key -d
echo "Adding the key"
eval `ssh-agent -s`
chmod 600 deploy_key
ssh-add deploy_key
echo "Key added"
# Clone the existing gh-pages for this repo into out/
# Create a new empty branch if gh-pages doesn't exist yet (should only happen on first deply)
git clone $REPO out
cd out
git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH
cd ..
# Get files that have to be pushed to gh-pages
echo "Moving doc files"
cp -rf doc/* out/
cd out
# If there are no changes to docs then just skip
if git diff --quiet --ignore-space-at-eol -b -w --ignore-blank-lines; then
echo "No changes to the output on this push; Skipping."
else
echo "Commiting"
git add -A .
git commit -m "Updating documentation: ${SHA}"
echo "Pushing gh-pages"
git push $SSH_REPO $TARGET_BRANCH
fi
cd ..
#Let's also check for doc.lua
local head_ref branch_ref
head_ref=$(git rev-parse HEAD)
if [[ $? -ne 0 || ! $head_ref ]]; then
echo "failed to get HEAD reference"
exit 1
fi
branch_ref=$(git rev-parse "$TRAVIS_BRANCH")
if [[ $? -ne 0 || ! $branch_ref ]]; then
echo "failed to get $TRAVIS_BRANCH reference"
exit 1
fi
if [[ $head_ref != $branch_ref ]]; then
echo "HEAD ref ($head_ref) does not match $TRAVIS_BRANCH ref ($branch_ref)"
echo "someone may have pushed new commits before this build cloned the repo"
exit 1
fi
if ! git checkout "$TRAVIS_BRANCH"; then
echo "failed to checkout $TRAVIS_BRANCH"
exit 1
fi
#Add only docs.lua
git add "lua/starfall/editor/docs.lua"
if git diff --quiet --staged --ignore-space-at-eol -b -w --ignore-blank-lines; then #checking if there is a diff for staged changes (so only doc)
echo "No changes to docs.lua, skipping."
else
echo "Commiting.."
git commit -m "Updating documentation: ${SHA} [ci skip]"
echo "Pushing.."
git push --quiet $SSH_REPO $TRAVIS_BRANCH
fi
echo "Done!"