Skip to content

Commit

Permalink
chore: Pull gh-pages building to deploy script (pull #445)
Browse files Browse the repository at this point in the history
Move the logic for doing the manual gh-pages deployment to the built-in
Travis-CI “script” deployment.
This allows all branches to be built and tested, but only the master
branch to be deployed.
  • Loading branch information
nschonni authored and mcking65 committed Aug 15, 2018
1 parent 66229af commit 458beba
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 33 deletions.
40 changes: 7 additions & 33 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,14 @@ language: node_js
node_js:
- "node"

env:
global:
- GH_REF: github.com/w3c/aria-practices.git

addons:
apt:
packages:
- oracle-java8-installer
- oracle-java8-set-default

git:
depth: 3

branches:
only:
master

install:
- npm install && npm test

before_script:
- git config --global user.email "[email protected]"
- git config --global user.name "michael-n-cooper"

script:
- cd ../..
- mkdir gh-pages
- cd gh-pages
- git clone --depth=1 --branch=gh-pages https://github.com/w3c/aria-practices.git
- cd aria-practices
- curl "https://labs.w3.org/spec-generator/?type=respec&url=https://rawgit.com/w3c/aria-practices/master/aria-practices.html" -o index.html -f --retry 3
- cp -r ../../w3c/aria-practices/examples .
before_deploy: scripts/travis-before_deploy.sh

after_success:
- git add .
- git commit -m "Generated by TRAVIS-CI"
- git push "https://${GH_TOKEN}@${GH_REF}" gh-pages > /dev/null 2>&1
deploy:
provider: script
skip_cleanup: true
script: /tmp/deploy/travis-deploy.sh
on:
branch: master
24 changes: 24 additions & 0 deletions scripts/travis-before_deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Stash the latest examples
mkdir /tmp/aria-practices
cp -R common /tmp/aria-practices
cp -R examples /tmp/aria-practices
cp -R img /tmp/aria-practices
cp .gitignore /tmp/aria-practices
cp .editorconfig /tmp/aria-practices
cp README.md /tmp/aria-practices

mkdir /tmp/deploy
cp scripts/travis-deploy.sh /tmp/deploy/

# Grab the gh-pages branch
git fetch --depth=1 origin gh-pages:gh-pages
git checkout gh-pages
curl "https://labs.w3.org/spec-generator/?type=respec&url=https://rawgit.com/${TRAVIS_REPO_SLUG}/master/aria-practices.html" -o index.html -f --retry 3

# Clean and update the examples
rm -rf common/
rm -rf examples/
rm -rf img/
cp -R /tmp/aria-practices/ ..
13 changes: 13 additions & 0 deletions scripts/travis-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

if [ -z "$GH_TOKEN" ]; then
echo "To deploy to your gh-pages branch, the GH_TOKEN needs to be defined by following https://docs.travis-ci.com/user/environment-variables/#Defining-Variables-in-Repository-Settings"
exit 1
fi

echo 'Pushing built changes'
git config --global user.email "[email protected]"
git config --global user.name "michael-n-cooper"
git config remote.origin.url "https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git"
git commit -am "Generated by TRAVIS-CI ${TRAVIS_COMMIT}" -m "${TRAVIS_COMMIT_MESSAGE}"
git push --set-upstream origin gh-pages > /dev/null 2>&1

0 comments on commit 458beba

Please sign in to comment.