Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Add common deploy script #41

Merged
merged 4 commits into from
Jan 24, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions build/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Build resources

The resources in this folder are used for building WHATWG specifications.
The resources in this folder are used for building WHATWG standards.

## `deploy.sh`

The `deploy.sh` script is used by most WHATWG specifications and is meant to run either on Travis CI, or locally with the `--local` command-line flag for preview purposes. It performs the following steps:
The `deploy.sh` script is used by most WHATWG standards and is meant to run either on Travis CI, or locally for preview purposes. It performs the following steps:

- Running [Bikeshed](https://github.com/tabatkins/bikeshed), through its [web API](https://api.csswg.org/bikeshed/), to produce:
- If on master, the built living standard, as well as a commit snapshot
- Otherwise, a branch snapshot of the specification
- If on master, the built Living Standard, as well as a commit snapshot
- Otherwise, a branch snapshot of the standard
- Running the [Nu HTML checker](http://checker.html5.org/) on the build results
- Deploying the build results to the WHATWG web server

Expand Down Expand Up @@ -40,5 +40,7 @@ notifications:
Similarly, a local deploy can be performed with

```bash
curl --remote-name --fail https://resources.whatwg.org/build/deploy.sh && bash ./deploy.sh --local
curl --remote-name --fail https://resources.whatwg.org/build/deploy.sh && bash ./deploy.sh
```

Whether the script is running a local vs. Travis deploy is determined by checking [the `$TRAVIS` environment variable](https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables).
24 changes: 11 additions & 13 deletions build/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ BRANCHES_DIR="branch-snapshots"
SERVER="75.119.197.251"
SERVER_PUBLIC_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDM6WJlvCc/+Zy2wrdzfKMv0Mb2Pmf9INvJPOH/zFrG5TbrKWY2LbNB6m3kkYTDQJzc0EuxCytuDsGhTuzTgc3drHwe2dys7cUQyQzS0iue50r6nBMfr1x2h6WhV3OZHkzFgqS17vlVdlLcGHCCwYgm19TGlrqY5RDnE+jTEAC/9AN7YFbbyfZV5fzToXwA2sFyj9TtwKfu/EeZAInPBpaLumu/glhr+rFXwhQQdNFh7hth8b4flG5mOqODju94wtbuDa4Utw1+S/zCeFIU55R7JHa29Pz3rL6Rpiiin9SpenjkD3UpP+y8WC1OaMImEh1XNUuomQa+6qxXEjxQAW1r"

if [ "$1" != "--local" -a "$DEPLOY_USER" == "" ]; then
echo "No deploy credentials present; skipping deploy"
if [ "$TRAVIS" == "true" -a "$TRAVIS_PULL_REQUEST" == "true" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that in https://travis-ci.org/whatwg/whatwg.org/builds/194915312 it echoes "1" for TRAVIS_PULL_REQUEST. I do get "false" in https://travis-ci.org/whatwg/whatwg.org/builds/194915320. But maybe those are just all weird?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow.

TRAVIS_PULL_REQUEST: The pull request number if the current job is a pull request, “false” if it’s not a pull request.

from https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables

So the only applicable test is vs. "false"

echo "Skipping deploy for a pull request; the branch build will suffice"
exit 0
fi

if [ "$1" == "--local" ]; then
if [ "$TRAVIS" == "true" -a "$DEPLOY_USER" == "" ]; then
echo "No deploy credentials present; deploy cannot continue"
exit 1
fi

if [ "$TRAVIS" != "true" ]; then
echo "Running a local deploy into $WEB_ROOT directory"
echo ""
fi

SHA="`git rev-parse HEAD`"
BRANCH="`git rev-parse --abbrev-ref HEAD`"
if [ "$BRANCH" == "HEAD" ]; then # Travis does this for some reason
if [ "$TRAVIS" == "true" ]; then # For some reason the above does not work on Travis
BRANCH=$TRAVIS_BRANCH
fi

if [ "$BRANCH" == "master" -a "$TRAVIS_PULL_REQUEST" != "false" -a "$TRAVIS_PULL_REQUEST" != "" ]; then
echo "Skipping deploy for a pull request; the branch build will suffice"
exit 0
fi

BACK_TO_LS_LINK="<a href=\"/\" id=\"commit-snapshot-link\">Go to the living standard</a>"
SNAPSHOT_LINK="<a href=\"/commit-snapshots/$SHA/\" id=\"commit-snapshot-link\">Snapshot as of this commit</a>"

Expand Down Expand Up @@ -73,21 +73,18 @@ else
curl https://api.csswg.org/bikeshed/ -f -F file=@$INPUT_FILE \
-F md-Text-Macro="SNAPSHOT-LINK $SNAPSHOT_LINK" \
> $WEB_ROOT/index.html
cp .htaccess $WEB_ROOT/.htaccess 2>/dev/null || :
echo "Living standard output to $WEB_ROOT"
fi

echo ""
find $WEB_ROOT -type f -print
echo ""

# Run the HTML checker when building on Travis
if [ "$TRAVIS" == "true" ]; then
# Run the HTML checker only when building on Travis
curl -O https://sideshowbarker.net/nightlies/jar/vnu.jar
/usr/lib/jvm/java-8-oracle/jre/bin/java -jar vnu.jar --skip-non-html $WEB_ROOT
fi

if [ "$1" != "--local" ]; then
# Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc
ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
Expand All @@ -98,6 +95,7 @@ if [ "$1" != "--local" ]; then
eval `ssh-agent -s`
ssh-add deploy_key

# scp to the WHATWG server
echo "$SERVER $SERVER_PUBLIC_KEY" > known_hosts
scp -r -o UserKnownHostsFile=known_hosts $WEB_ROOT $DEPLOY_USER@$SERVER:
fi