Skip to content

Commit

Permalink
automatically publish new package and create release on tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Jenkinson committed Jun 17, 2018
1 parent c1f254c commit 9b7460e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 35 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ jobs:
# env: TRAVIS_MODE=funcTests UA=firefox OS="OS X 10.11"
- stage: optional
env: TRAVIS_MODE=funcTests UA=safari OS="OS X 10.11" UA_VERSION="9.0"
deploy:
provider: releases
api_key: "TODO: GITHUB OAUTH TOKEN"
env: TRAVIS_MODE=release
file_glob: true
file: dist/*
draft: true
skip_cleanup: true
on:
tags: true
addons:
sauce_connect: true
jwt:
Expand Down
28 changes: 0 additions & 28 deletions scripts/set-canary-version.js

This file was deleted.

56 changes: 56 additions & 0 deletions scripts/set-package-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const fs = require('fs');
const package = require('../package.json');

const VALID_VERSION_REGEX = /^v\d+\.\d+\.\d+$/;

const TRAVIS_MODE = process.env.TRAVIS_MODE;
let newVersion = '';

try {
if (TRAVIS_MODE === 'release') {
// write the version field in the package json to the version in the git tag
const tag = process.env.TRAVIS_TAG;
if (!tag.test(VALID_VERSION_REGEX)) {
throw new Error('Unsuported tag for release: ' + tag);
}
// remove v
newVersion = tag.substring(1);
} else if (TRAVIS_MODE === 'releaseCanary') {
// bump patch in version from latest git tag
let currentVersion = getLatestVersionTag();
if (!currentVersion.test(VALID_VERSION_REGEX)) {
throw new Error('Latest version tag invalid: ' + tag);
}
// remove v
currentVersion = currentVersion.substring(1);

let matched = false;
newVersion = currentVersion.replace(/^(\d+)\.(\d+)\.(\d+).*$/, function(_, major, minor, patch) {
matched = true;
return major + '.' + minor + '.' + (parseInt(patch, 10) + 1);
});
if (!matched) {
throw new Error('Error calculating version.');
}
newVersion += '-canary.' + getCommitNum();
} else {
throw new Error('Unsupported travis mode: ' + TRAVIS_MODE);
}

package.version = newVersion;
fs.writeFileSync('./package.json', JSON.stringify(package));
console.log('Set version: ' + newVersion);
} catch(e) {
console.error(e);
process.exit(1);
}
process.exit(0);


function getCommitNum() {
return parseInt(require('child_process').execSync('git rev-list --count HEAD').toString(), 10);
}

function getLatestVersionTag() {
return parseInt(require('child_process').execSync('git describe origin/master --match="v*"').toString(), 10);
}
19 changes: 12 additions & 7 deletions scripts/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,29 @@ elif [ "${TRAVIS_MODE}" = "funcTests" ]; then
if [ ${n} = ${maxRetries} ]; then
exit 1
fi
elif [ "${TRAVIS_MODE}" = "releaseCanary" ]; then
elif [ "${TRAVIS_MODE}" = "release" ] || [ "${TRAVIS_MODE}" = "releaseCanary" ]; then
# update the version
# make sure everything is fetched https://github.com/travis-ci/travis-ci/issues/3412
git fetch --unshallow
node ./scripts/set-canary-version.js
node ./scripts/set-package-version.js
if [[ $(node ./scripts/check-already-published.js) = "not published" ]]; then
npm run lint
npm run build
npm run test:unit
# write the token to config
# see https://docs.npmjs.com/private-modules/ci-server-config
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
npm publish --tag canary
echo "Published canary."
curl https://purge.jsdelivr.net/npm/hls.js@canary
echo "Cleared jsdelivr cache."
if [ "${TRAVIS_MODE}" = "releaseCanary" ]; then
npm publish --tag canary
echo "Published canary."
curl https://purge.jsdelivr.net/npm/hls.js@canary
echo "Cleared jsdelivr cache."
elif [ "${TRAVIS_MODE}" = "release" ]; then
npm publish
echo "Published."
fi
else
echo "Canary already published."
echo "Already published."
fi
else
echo "Unknown travis mode: ${TRAVIS_MODE}" 1>&2
Expand Down

0 comments on commit 9b7460e

Please sign in to comment.