forked from kubernetes/kompose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync-docs.sh
executable file
·89 lines (75 loc) · 2.33 KB
/
sync-docs.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
#!/usr/bin/env bash
# Ensures that we run on Travis
if [ "$TRAVIS_BRANCH" != "master" ] || [ "$BUILD_DOCS" != "yes" ] || [ "$TRAVIS_SECURE_ENV_VARS" == "false" ] || [ "$TRAVIS_PULL_REQUEST" != "false" ] ; then
echo "Must be: a merged pr on the master branch, BUILD_DOCS=yes, TRAVIS_SECURE_ENV_VARS=false"
exit 0
fi
DOCS_REPO_NAME="kompose"
DOCS_REPO_URL="git@github.com:kubernetes/kompose.git"
DOCS_KEY="script/deploy_key"
DOCS_USER="komposebot"
DOCS_EMAIL="cdrage+kompose@redhat.com"
DOCS_BRANCH="gh-pages"
DOCS_FOLDER="docs"
# decrypt the private key
openssl aes-256-cbc -K $encrypted_b1c51b116939_key -iv $encrypted_b1c51b116939_iv -in "$DOCS_KEY.enc" -out "$DOCS_KEY" -d
chmod 600 "$DOCS_KEY"
eval `ssh-agent -s`
ssh-add "$DOCS_KEY"
# clone the repo
git clone "$DOCS_REPO_URL" "$DOCS_REPO_NAME"
# change to that directory (to prevent accidental pushing to master, etc.)
cd "$DOCS_REPO_NAME"
# switch to gh-pages and grab the docs folder from master
git checkout gh-pages
git checkout master docs
# Remove README.md from docs folder as it isn't relevant
rm docs/README.md
# Use quickstart.md instead as the main index page
mv docs/quickstart.md index.md
# Check that index.md has the appropriate Jekyll format
index="index.md"
if cat $index | head -n 1 | grep "\-\-\-";
then
echo "index.md already contains Jekyll format"
else
# Remove ".md" from the name
name=${index::-3}
echo "Adding Jekyll file format to $index"
jekyll="---
layout: default
---
"
echo -e "$jekyll\n$(cat $index)" > $index
fi
# clean-up the docs and convert to jekyll-friendly docs
cd docs
for filename in *.md; do
if cat $filename | head -n 1 | grep "\-\-\-";
then
echo "$filename already contains Jekyll format"
else
# Remove ".md" from the name
name=${filename::-3}
echo "Adding Jekyll file format to $filename"
jekyll="---
layout: default
permalink: /$name/
redirect_from: \"/docs/$name.md\"
---
"
echo -e "$jekyll\n$(cat $filename)" > $filename
fi
done
cd ..
# add relevant user information
git config user.name "$DOCS_USER"
# email assigned to @komposebot
git config user.email "$DOCS_EMAIL"
git add --all
# Check if anything changed, and if it's the case, push to origin/master.
if git commit -m 'Update docs' -m "Commit: https://github.com/kubernetes/kompose/commit/$TRAVIS_COMMIT" ; then
git push
fi
# cd back to the original root folder
cd ..