Merge pull request #500 from cdrage/sync-docs

Sync changes from master to gh-pages on each merge request
This commit is contained in:
Charlie Drage 2017-03-23 11:52:40 -04:00 committed by GitHub
commit e888ed4618
3 changed files with 76 additions and 4 deletions

View File

@ -7,10 +7,13 @@ language: go
# make this also work for forks
go_import_path: github.com/kubernetes-incubator/kompose
go:
- 1.6
- 1.7
- 1.8
matrix:
include:
- go: 1.6
# Only build docs once
env: BUILD_DOCS=yes
- go: 1.7
- go: 1.8
before_install:
- go get github.com/mattn/goveralls
@ -29,3 +32,5 @@ after_success:
# gover collects all .coverprofile files and saves it to one file gover.coverprofile
- gover
- goveralls -coverprofile=gover.coverprofile -service=travis-ci
# sync the docs only if everything else was successful
- ./script/sync-docs.sh

BIN
script/deploy_key.enc Normal file

Binary file not shown.

67
script/sync-docs.sh Executable file
View File

@ -0,0 +1,67 @@
#!/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-incubator/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
# 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
echo "Adding Jekyll file format to $filename"
jekyll="---
layout: default
permalink: /$filename/
---
"
echo -e "$jekyll\n$(cat $filename)" > $filename
fi
done
cd ..
# remove README.md from docs folder as it isn't relevant
rm docs/README.md
# 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-incubator/kompose/commit/$TRAVIS_COMMIT" ; then
git push
fi
# cd back to the original root folder
cd ..