From d93d4539557ad9c1ff78bd0a1c357cd163e38d3c Mon Sep 17 00:00:00 2001 From: Tom Jenkinson Date: Sat, 26 Jan 2019 17:57:06 +0100 Subject: [PATCH 1/6] configure netlify for PR's this follows the same process that runs for canary releases --- netlify.toml | 14 ++++++ scripts/build-netlify.sh | 17 +++++++ ...ld-deploy-netlify.sh => deploy-netlify.sh} | 15 +------ scripts/travis.sh | 44 +++++++++++-------- 4 files changed, 57 insertions(+), 33 deletions(-) create mode 100644 netlify.toml create mode 100755 scripts/build-netlify.sh rename scripts/{build-deploy-netlify.sh => deploy-netlify.sh} (84%) diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 00000000000..4467e681793 --- /dev/null +++ b/netlify.toml @@ -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" diff --git a/scripts/build-netlify.sh b/scripts/build-netlify.sh new file mode 100755 index 00000000000..d409884c48f --- /dev/null +++ b/scripts/build-netlify.sh @@ -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." diff --git a/scripts/build-deploy-netlify.sh b/scripts/deploy-netlify.sh similarity index 84% rename from scripts/build-deploy-netlify.sh rename to scripts/deploy-netlify.sh index 22cfb7bff20..a5bf197f459 100755 --- a/scripts/build-deploy-netlify.sh +++ b/scripts/deploy-netlify.sh @@ -10,19 +10,6 @@ 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'." @@ -30,7 +17,7 @@ deploy () { 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') diff --git a/scripts/travis.sh b/scripts/travis.sh index c8d33a3f782..16cf51d5be3 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -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 From e5a3a78cc58c14728fc13fd2f494f589ceae4280 Mon Sep 17 00:00:00 2001 From: Tom Jenkinson Date: Sat, 26 Jan 2019 18:08:41 +0100 Subject: [PATCH 2/6] check if repo is shallow before fetching because on netlify it clones the whole thing --- scripts/travis.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/travis.sh b/scripts/travis.sh index 16cf51d5be3..a9358c1c722 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -32,8 +32,10 @@ elif [ "${TRAVIS_MODE}" = "funcTests" ]; then fi 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 + if [[ $(git rev-parse --is-shallow-repository) = "true" ]]; then + # make sure everything is fetched https://github.com/travis-ci/travis-ci/issues/3412 + git fetch --unshallow + fi node ./scripts/set-package-version.js npm run lint npm run build From 35c4553e8fbe1128b04da820b974cd2ad8c29332 Mon Sep 17 00:00:00 2001 From: Tom Jenkinson Date: Sat, 26 Jan 2019 18:27:06 +0100 Subject: [PATCH 3/6] handle 'netlifyPr' in set-package-version --- scripts/set-package-version.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/set-package-version.js b/scripts/set-package-version.js index 6eb8835a547..49f9a019a3d 100755 --- a/scripts/set-package-version.js +++ b/scripts/set-package-version.js @@ -17,7 +17,7 @@ try { } // remove v newVersion = tag.substring(1); - } else if (TRAVIS_MODE === 'releaseCanary') { + } else if (TRAVIS_MODE === 'releaseCanary' || TRAVIS_MODE === 'netlifyPr') { // bump patch in version from latest git tag let currentVersion = getLatestVersionTag(); if (!VALID_VERSION_REGEX.test(currentVersion)) { @@ -34,7 +34,7 @@ try { if (!matched) { throw new Error('Error calculating version.'); } - newVersion += '-canary.' + getCommitNum(); + newVersion += `-${TRAVIS_MODE === 'netlifyPr' ? 'pr' : 'canary'}.${getCommitNum()}`; } else { throw new Error('Unsupported travis mode: ' + TRAVIS_MODE); } From a8f99c4e0168f8cbe5816b609cf52e633297e6d0 Mon Sep 17 00:00:00 2001 From: Tom Jenkinson Date: Sat, 26 Jan 2019 18:28:24 +0100 Subject: [PATCH 4/6] tabs => spaces --- scripts/travis.sh | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/scripts/travis.sh b/scripts/travis.sh index a9358c1c722..c31942be9e6 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -11,25 +11,25 @@ if [ "${TRAVIS_MODE}" = "build" ]; then # see https://github.com/video-dev/hls.js/pull/1642 node -e 'require("./" + require("./package.json").main)' elif [ "${TRAVIS_MODE}" = "unitTests" ]; then - npm run test:unit + npm run test:unit elif [ "${TRAVIS_MODE}" = "funcTests" ]; then - npm run build - n=0 - maxRetries=1 - until [ $n -ge ${maxRetries} ] - do - if [ $n -gt 0 ]; then - echo "Retrying... Attempt: $((n+1))" - delay=$((n*60)) - echo "Waiting ${delay} seconds..." - sleep $delay - fi - npm run test:func && break - n=$[$n+1] - done - if [ ${n} = ${maxRetries} ]; then - exit 1 - fi + npm run build + n=0 + maxRetries=1 + until [ $n -ge ${maxRetries} ] + do + if [ $n -gt 0 ]; then + echo "Retrying... Attempt: $((n+1))" + delay=$((n*60)) + echo "Waiting ${delay} seconds..." + sleep $delay + fi + npm run test:func && break + n=$[$n+1] + done + if [ ${n} = ${maxRetries} ]; then + exit 1 + fi elif [ "${TRAVIS_MODE}" = "release" ] || [ "${TRAVIS_MODE}" = "releaseCanary" ] || [ "${TRAVIS_MODE}" = "netlifyPr" ]; then # update the version if [[ $(git rev-parse --is-shallow-repository) = "true" ]]; then @@ -67,6 +67,6 @@ elif [ "${TRAVIS_MODE}" = "release" ] || [ "${TRAVIS_MODE}" = "releaseCanary" ] ./scripts/deploy-netlify.sh fi else - echo "Unknown travis mode: ${TRAVIS_MODE}" 1>&2 - exit 1 + echo "Unknown travis mode: ${TRAVIS_MODE}" 1>&2 + exit 1 fi From f69bf3e473daa0943b60192ad3af0cf7808be867 Mon Sep 17 00:00:00 2001 From: Tom Jenkinson Date: Sun, 27 Jan 2019 00:08:49 +0100 Subject: [PATCH 5/6] add commit to version when PR --- scripts/set-package-version.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/set-package-version.js b/scripts/set-package-version.js index 49f9a019a3d..40b9a09cdb8 100755 --- a/scripts/set-package-version.js +++ b/scripts/set-package-version.js @@ -34,7 +34,11 @@ try { if (!matched) { throw new Error('Error calculating version.'); } - newVersion += `-${TRAVIS_MODE === 'netlifyPr' ? 'pr' : 'canary'}.${getCommitNum()}`; + if (TRAVIS_MODE === 'netlifyPr') { + newVersion += `-pr.${getCommitHash().substr(0, 8)}`; + } else { + newVersion += `-canary.${getCommitNum()}`; + } } else { throw new Error('Unsupported travis mode: ' + TRAVIS_MODE); } @@ -52,6 +56,10 @@ function getCommitNum() { return parseInt(require('child_process').execSync('git rev-list --count HEAD').toString(), 10); } +function getCommitHash() { + return require('child_process').execSync('git rev-parse HEAD').toString(); +} + function getLatestVersionTag() { return require('child_process').execSync('git describe --abbrev=0 --match="v*"').toString().trim(); } From e2e71c7128dd706082d16470b655240798a1fc6c Mon Sep 17 00:00:00 2001 From: Tom Jenkinson Date: Sun, 27 Jan 2019 11:13:18 +0100 Subject: [PATCH 6/6] always trim command output --- scripts/set-package-version.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/set-package-version.js b/scripts/set-package-version.js index 40b9a09cdb8..521ff28de30 100755 --- a/scripts/set-package-version.js +++ b/scripts/set-package-version.js @@ -53,13 +53,17 @@ try { process.exit(0); function getCommitNum() { - return parseInt(require('child_process').execSync('git rev-list --count HEAD').toString(), 10); + return parseInt(exec('git rev-list --count HEAD'), 10); } function getCommitHash() { - return require('child_process').execSync('git rev-parse HEAD').toString(); + return exec('git rev-parse HEAD'); } function getLatestVersionTag() { - return require('child_process').execSync('git describe --abbrev=0 --match="v*"').toString().trim(); + return exec('git describe --abbrev=0 --match="v*"'); +} + +function exec(cmd) { + return require('child_process').execSync(cmd).toString().trim(); }