Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve and fix Travis integration #278

Merged
merged 4 commits into from Dec 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 31 additions & 41 deletions deploy.sh
Expand Up @@ -10,20 +10,20 @@ echo "[TRACE] TRAVIS_PULL_REQUEST: $TRAVIS_PULL_REQUEST"
SOURCE_BRANCH="$TRAVIS_PULL_REQUEST_BRANCH"
TARGET_BRANCH="$TRAVIS_PULL_REQUEST_BRANCH-build"

if [ "$TRAVIS_PULL_REQUEST" = "false" -a "$TRAVIS_BRANCH" != "master" ]; then
echo "[ABORT] We're in a push build (not in master nor in a pull request), so exiting. "
exit 0
fi

if [ "$TRAVIS_PULL_REQUEST" != "false" -a "$TRAVIS_PULL_REQUEST_BRANCH" = "master" ]; then
echo "[ERROR] We're in a pull request but we're in the master branch?!?!"
echo " This shouldn't happen..."
exit 1
fi

if [ "$TRAVIS_PULL_REQUEST" = "false" -a "$SOURCE_BRANCH" = "master" ]; then
if [ "$TRAVIS_PULL_REQUEST" = "false" -a "$TRAVIS_BRANCH" = "master" ]; then
SOURCE_BRANCH="master"
TARGET_BRANCH="gh-pages"
fi

if [ "$TRAVIS_PULL_REQUEST" = "false" -a "$TRAVIS_BRANCH" != "master" ]; then
echo "[ABORT] We're in a push build (not in master nor in a pull request), so exiting. "
exit 0
fi

echo "[TRACE] SOURCE_BRANCH: $SOURCE_BRANCH"
Expand All @@ -34,43 +34,37 @@ REPO=`git config remote.origin.url`
SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
SHA=`git rev-parse --verify HEAD`

# Clone the existing gh-pages for this repo into out/
# Create a new empty branch if the target branch 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 ..
#define repo paths

# Clean out existing contents
rm -rf out/**/* || exit 0
TTML1_BUILD_DIR="$TRAVIS_BUILD_DIR/spec/build"
TTML1_SPEC_DIR="$TRAVIS_BUILD_DIR/spec"

# Copy content from build into existing contents
# build the specification

echo -e "\n[TRACE] Building the specification"
cd spec
cd $TTML1_SPEC_DIR
ant build

# Make sure we're in the right directory
# create the build directory, and checkout or create the target branch

echo -e "\n[TRACE] Copying the specification and cleaning out"
cd $TTML1_BUILD_DIR

cp -R build/* ../out/
git init
git remote add origin $REPO
git symbolic-ref HEAD refs/heads/$TARGET_BRANCH
git fetch origin $TARGET_BRANCH && git reset origin/$TARGET_BRANCH

cd ../out
# setup the user information for the repo

rm -f .travis.yml
rm -f w3c.json
rm -f CODE_OF_CONDUCT.md
rm -f CONTRIBUTING.md
rm -f LICENSE.md
rm -rf spec
rm -rf .gitfilters
rm -rf .gitattributes
rm -rf .gitignore
git config user.name "Travis CI"
git config user.email "$COMMIT_AUTHOR_EMAIL"

# Useful additional information for PR branches

if [ "$SOURCE_BRANCH" != "master" ]; then
echo -e "\n[TRACE] Adding build information"


if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
echo "[![Build Status](https://travis-ci.org/w3c/ttml1.svg?branch=$SOURCE_BRANCH)](https://travis-ci.org/w3c/ttml1)" >README.md
echo -e "\n\n# Specification TTML 1\n" >>README.md
echo -e "\nNote:\n" >>README.md
Expand All @@ -91,16 +85,12 @@ if [ "$SOURCE_BRANCH" != "master" ]; then
echo -e "\n\n" >>README.md
fi

# Now let's go have some fun with the cloned repo
cd ../out
git config user.name "Travis CI"
git config user.email "$COMMIT_AUTHOR_EMAIL"

# If there are no changes to the compiled out (e.g. this is a README update) then just bail.
if git diff --quiet; then
echo "No changes to the output on this push; exiting."
exit 0
fi
#if git diff --quiet; then
# echo "No changes to the output on this push; exiting."
# exit 0
#fi

# Commit the "changes", i.e. the new version.
# The delta will show diffs between new and old versions.
Expand All @@ -112,10 +102,10 @@ ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -in ../deploy_key.enc -out ../deploy_key -d
chmod 600 ../deploy_key
openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -in $TRAVIS_BUILD_DIR/deploy_key.enc -out $TRAVIS_BUILD_DIR/deploy_key -d
chmod 600 $TRAVIS_BUILD_DIR/deploy_key
eval `ssh-agent -s`
ssh-add ../deploy_key
ssh-add $TRAVIS_BUILD_DIR/deploy_key

# Now that we're all set up, we can push.
echo "Ready to push"
Expand Down