Skip to content

Commit

Permalink
Merge pull request video-dev#2284 from video-dev/support-beta-tags
Browse files Browse the repository at this point in the history
support preprelease publishes from git tag
  • Loading branch information
tjenkinson authored Jun 27, 2019
2 parents f723c06 + e9bedc1 commit b13c460
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 14 deletions.
16 changes: 11 additions & 5 deletions docs/release-process.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Performing A Release
Releases are performed automatically with travis.

1. `git tag -a v<major>.<minor>.<patch>` _('v' required)_
2. `git push --tag`
3. Wait for travis to create a new draft GitHub release with the build attached. At this point the new npm package should have been published.
4. Add the release notes to the new draft GitHub release.
5. Publish the GitHub release.
1. `git tag -a v<major>.<minor>.<patch>` or `git tag -a v<major>.<minor>.<patch>-<prerelease>` _('v' required)_ where anything before the first `.` in `<prerelease>` will be become the [npm dist-tag](https://docs.npmjs.com/cli/dist-tag).
1. `git push`
1. `git push --tag`
1. Wait for travis to create a new draft GitHub release with the build attached. At this point the new npm package should have been published.
1. Add the release notes to the new draft GitHub release.
1. Publish the GitHub release.

## Examples
- `git tag -a v1.2.3` will result in `1.2.3` being published with the `latest` npm tag.
- `git tag -a v1.2.3-beta` will result in `1.2.3-beta` being published with the `beta` npm tag.
- `git tag -a v1.2.3-beta.1` will result in `1.2.3-beta.1` being published with the `beta` npm tag.
6 changes: 6 additions & 0 deletions scripts/get-version-tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

const versionParser = require('./version-parser.js');
const packageJson = require('../package.json');

console.log(versionParser.getVersionTag('v' + packageJson.version));
21 changes: 14 additions & 7 deletions scripts/set-package-version.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
'use strict';

const fs = require('fs');
const versionParser = require('./version-parser.js');
const packageJson = 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 (!VALID_VERSION_REGEX.test(tag)) {
if (!versionParser.isValidVersion(tag)) {
throw new Error('Unsuported tag for release: ' + tag);
}
// remove v
newVersion = tag.substring(1);
} 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)) {
throw new Error('Latest version tag invalid: ' + currentVersion);
}
// remove v
currentVersion = currentVersion.substring(1);

Expand Down Expand Up @@ -61,7 +57,18 @@ function getCommitHash() {
}

function getLatestVersionTag() {
return exec('git describe --abbrev=0 --match="v*"');
let commitish = '';
while(true) {
const tag = exec('git describe --abbrev=0 --match="v*" ' + commitish);
if (!tag) {
throw new Error('Could not find tag.');
}
if (versionParser.isValidStableVersion(tag)) {
return tag;
}
// next time search older tags than this one
commitish = tag + '~1';
}
}

function exec(cmd) {
Expand Down
11 changes: 9 additions & 2 deletions scripts/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,15 @@ elif [ "${TRAVIS_MODE}" = "release" ] || [ "${TRAVIS_MODE}" = "releaseCanary" ]
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
tag=$(node ./scripts/get-version-tag.js)
if [ "${tag}" = "canary" ]; then
# canary is blacklisted because this is handled separately on every commit
echo "canary not supported as explicit tag"
exit 1
fi
echo "Publishing tag: ${tag}"
npm publish --tag "${tag}"
curl "https://purge.jsdelivr.net/npm/hls.js@${tag}"
echo "Published."
fi
else
Expand Down
25 changes: 25 additions & 0 deletions scripts/version-parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

const VALID_VERSION_REGEX = /^v\d+\.\d+\.\d+(?:-([a-zA-Z][0-9a-zA-Z-]*))?/;
const STABLE_VERSION_REGEX = /^v\d+\.\d+\.\d+$/;

module.exports = {
isValidVersion: function(version) {
return VALID_VERSION_REGEX.test(version);
},
isValidStableVersion: function(version) {
return STABLE_VERSION_REGEX.test(version);
},
// extract what we should use as the npm dist-tag (https://docs.npmjs.com/cli/dist-tag)
// e.g
// v1.2.3-beta => beta
// v1.2.3-beta.1 => beta
// v1.2.3 => latest
getVersionTag: function(version) {
const match = VALID_VERSION_REGEX.exec(version);
if (!match) {
throw new Error('Invalid version.');
}
return match[1] || 'latest';
}
}

0 comments on commit b13c460

Please sign in to comment.