forked from video-dev/hls.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
automatically publish new package and create release on tag
- Loading branch information
Tom Jenkinson
committed
Jun 17, 2018
1 parent
c1f254c
commit 9b7460e
Showing
4 changed files
with
78 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters