Skip to content

Commit

Permalink
configure netlify for PR's
Browse files Browse the repository at this point in the history
this follows the same process that runs for canary releases
  • Loading branch information
Tom Jenkinson committed Jan 26, 2019
1 parent 86b4e15 commit d93d453
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 33 deletions.
14 changes: 14 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# https://www.netlify.com/docs/netlify-toml-reference/

# Settings in the [build] context are global and are applied to all contexts
# unless otherwise overridden by more specific contexts.
[build]
# Directory (relative to root of your repo) that contains the deploy-ready
# HTML files and assets generated by the build. If a base directory has
# been specified, include it in the publish directory path.
publish = "netlify"

# Deploy Preview context: all deploys resulting from a pull/merge request will
# inherit these settings.
[context.deploy-preview]
command = "TRAVIS_MODE=netlifyPr ./scripts/travis.sh"
17 changes: 17 additions & 0 deletions scripts/build-netlify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

root="./netlify"

rm -rf "$root"
mkdir "$root"

echo "Building netlify..."

# redirect / to /demo
echo "/ /demo" > "$root/_redirects"
cp -r "./dist" "$root/dist"
cp -r "./demo" "$root/demo"
cp -r "./api-docs" "$root/api-docs"

echo "Built netlify."
15 changes: 1 addition & 14 deletions scripts/build-deploy-netlify.sh → scripts/deploy-netlify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,14 @@ idShort="$(echo "$id" | cut -c 1-8) ($version)"
latestSiteId="642d9ad4-f002-4104-9309-40ed9cd81a1f"
stableSiteId="deef7ecf-4c3e-4de0-b6bb-676b02e1c20e"

rm -rf "$root"
mkdir "$root"

echo "Building netlify for $id"

# redirect / to /demo
echo "/ /demo" > "$root/_redirects"
cp -r "./dist" "$root/dist"
cp -r "./demo" "$root/demo"
cp -r "./api-docs" "$root/api-docs"

echo "Built netlify."

deploy () {
siteId=$1
echo "Deploying netlify to '$siteId'."
./node_modules/.bin/netlify deploy -d "$root" -m "deploy for $id" -s "$siteId" --prod -a "$NETLIFY_ACCESS_TOKEN"
echo "Deployed netlify to '$siteId'."
}

echo "Creating site for current commit."
echo "Creating site for current commit ($id)."
uuid=$(uuidgen)
commitSiteName="hls-js-$uuid"
commitSiteId=$(curl --fail -d "{\"name\":\"$commitSiteName\"}" -H "Content-Type: application/json" -X POST "https://api.netlify.com/api/v1/sites?access_token=$NETLIFY_ACCESS_TOKEN" | jq -r '.site_id')
Expand Down
44 changes: 25 additions & 19 deletions scripts/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,40 @@ elif [ "${TRAVIS_MODE}" = "funcTests" ]; then
if [ ${n} = ${maxRetries} ]; then
exit 1
fi
elif [ "${TRAVIS_MODE}" = "release" ] || [ "${TRAVIS_MODE}" = "releaseCanary" ]; then
elif [ "${TRAVIS_MODE}" = "release" ] || [ "${TRAVIS_MODE}" = "releaseCanary" ] || [ "${TRAVIS_MODE}" = "netlifyPr" ]; then
# update the version
# make sure everything is fetched https://github.com/travis-ci/travis-ci/issues/3412
git fetch --unshallow
node ./scripts/set-package-version.js
npm run lint
npm run build
npm run test:unit
if [[ $(node ./scripts/check-already-published.js) = "not published" ]]; then
# write the token to config
# see https://docs.npmjs.com/private-modules/ci-server-config
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
if [ "${TRAVIS_MODE}" = "releaseCanary" ]; then
npm publish --tag canary
echo "Published canary."
curl https://purge.jsdelivr.net/npm/hls.js@canary
curl https://purge.jsdelivr.net/npm/hls.js@canary/dist/hls-demo.js
echo "Cleared jsdelivr cache."
elif [ "${TRAVIS_MODE}" = "release" ]; then
npm publish
curl https://purge.jsdelivr.net/npm/hls.js@latest
echo "Published."
if [ "${TRAVIS_MODE}" != "netlifyPr" ]; then
npm run test:unit
if [[ $(node ./scripts/check-already-published.js) = "not published" ]]; then
# write the token to config
# see https://docs.npmjs.com/private-modules/ci-server-config
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
if [ "${TRAVIS_MODE}" = "releaseCanary" ]; then
npm publish --tag canary
echo "Published canary."
curl https://purge.jsdelivr.net/npm/hls.js@canary
curl https://purge.jsdelivr.net/npm/hls.js@canary/dist/hls-demo.js
echo "Cleared jsdelivr cache."
elif [ "${TRAVIS_MODE}" = "release" ]; then
npm publish
curl https://purge.jsdelivr.net/npm/hls.js@latest
echo "Published."
fi
else
echo "Already published."
fi
else
echo "Already published."
fi
npm run docs
./scripts/build-deploy-netlify.sh

./scripts/build-netlify.sh
if [ "${TRAVIS_MODE}" != "netlifyPr" ]; then
./scripts/deploy-netlify.sh
fi
else
echo "Unknown travis mode: ${TRAVIS_MODE}" 1>&2
exit 1
Expand Down

0 comments on commit d93d453

Please sign in to comment.