From d248eed29bccb75c31ef99516318194ab45248aa Mon Sep 17 00:00:00 2001 From: Alex Gyoshev Date: Wed, 10 May 2017 16:17:10 +0300 Subject: [PATCH] feat: enable release channels --- .travis.yml | 2 +- build/sr-analyzeCommits.js | 25 +++++++++++++++++++++++++ build/sr-verifyConditions.js | 19 +++++++++++++++++++ build/sr-verifyRelease.js | 15 +++++++++++++++ package.json | 11 +++++++++++ 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 build/sr-analyzeCommits.js create mode 100644 build/sr-verifyConditions.js create mode 100644 build/sr-verifyRelease.js diff --git a/.travis.yml b/.travis.yml index 8603944..459ef54 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,4 +28,4 @@ after_success: - npm run semantic-release branches: except: - - "/^v\\d+\\.\\d+\\.\\d+$/" + - "/^v\\d+\\.\\d+\\.\\d+(\\-.*)?$/" diff --git a/build/sr-analyzeCommits.js b/build/sr-analyzeCommits.js new file mode 100644 index 0000000..e9e7efa --- /dev/null +++ b/build/sr-analyzeCommits.js @@ -0,0 +1,25 @@ +const analyzeCommits = require('@semantic-release/commit-analyzer') + +module.exports = function (pluginConfig, config, cb) { + // run standard commit analysis + return analyzeCommits(pluginConfig, config, function(error, type) { + const branch = config.env.TRAVIS_BRANCH; + const distTag = config.options.branchTags[branch]; + let releaseType = type; + + // if branch publishes a dist-tag + if (type && distTag) { + // map all types of releases to prereleases + releaseType = { + 'major': 'premajor', + 'minor': 'preminor', + 'patch': 'prepatch' + }[type] || type; + + console.log("Publishing a " + releaseType + " release."); + } + + cb(error, releaseType); + }); +}; + diff --git a/build/sr-verifyConditions.js b/build/sr-verifyConditions.js new file mode 100644 index 0000000..d9d54a1 --- /dev/null +++ b/build/sr-verifyConditions.js @@ -0,0 +1,19 @@ +const conditionTravis = require('@semantic-release/condition-travis'); + +module.exports = function (pluginConfig, config, cb) { + const branch = config.env.TRAVIS_BRANCH; + const distTag = config.options.branchTags[branch]; + + // update semantic-release configuration to publish: + // - from this branch + // - with the specified dist tag + if (distTag) { + console.log(`Enable prerelease on dist-tag '${distTag}'.`); + + config.options.branch = branch; + config.npm.tag = distTag; + } + + // run default travis checks with the new configuration + return conditionTravis(pluginConfig, config, cb); +}; diff --git a/build/sr-verifyRelease.js b/build/sr-verifyRelease.js new file mode 100644 index 0000000..6d95fb9 --- /dev/null +++ b/build/sr-verifyRelease.js @@ -0,0 +1,15 @@ +module.exports = function (pluginConfig, config, cb) { + if (config.nextRelease) { + // change version suffix of pre-releases from '-number' to '-tag.timestamp' + const now = new Date(); + const timestamp = now.toISOString().replace(/[\-T\:]/g, "").slice(0,12); + const suffix = `-${config.npm.tag}.${timestamp}`; + const release = config.nextRelease; + + release.version = release.version.replace(/\-.+$/, suffix); + + console.log(`Ready for release v${release.version}`); + } + + cb(null); +}; diff --git a/package.json b/package.json index d45d85c..ffa0d9e 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,17 @@ "publishConfig": { "registry": "https://registry.npm.telerik.com" }, + "release": { + "branchTags": { + "develop": "dev" + }, + "fallbackTags": { + "dev": "latest" + }, + "verifyConditions": "./build/sr-verifyConditions", + "analyzeCommits": "./build/sr-analyzeCommits", + "verifyRelease": "./build/sr-verifyRelease" + }, "scripts": { "lint": "sass-lint -v -c ./sass-lint.yml", "api": "sassdoc ./scss/",