Extended yarn ship: more automation

no issue

- added gulp task to extend casper release automation
- will draft the release for you
- will get the user facing commits from changelog
- runs after `yarn ship` (postship)
- full automation with env variables is possible
This commit is contained in:
kirrg001
2019-03-14 17:31:28 +01:00
committed by Katharina Irrgang
parent 406ef78109
commit 8729dafcf5
5 changed files with 244 additions and 8 deletions

View File

@ -78,3 +78,122 @@ const dev = series(build, serve, watcher);
exports.build = build;
exports.zip = series(build, zipper);
exports.default = dev;
// release imports
const path = require('path');
const releaseUtils = require('@tryghost/release-utils');
let config;
try {
config = require('./config');
} catch (err) {
config = null;
}
const REPO = 'TryGhost/Casper';
const USER_AGENT = 'Casper';
const CHANGELOG_PATH = path.join(process.cwd(), '.', 'changelog.md');
const changelog = ({previousVersion}) => {
const changelog = new releaseUtils.Changelog({
changelogPath: CHANGELOG_PATH,
folder: path.join(process.cwd(), '.')
});
changelog
.write({
githubRepoPath: `https://github.com/${REPO}`,
lastVersion: previousVersion
})
.sort()
.clean();
};
const previousRelease = () => {
return releaseUtils
.releases
.get({
userAgent: USER_AGENT,
uri: `https://api.github.com/repos/${REPO}/releases`
})
.then((response) => {
if (!response || !response.length) {
console.log('No releases found. Skipping');
return;
}
console.log(`Previous version ${response[0].name}`);
return response[0].name;
});
};
/**
*
* `yarn ship` will trigger `postship` task.
*
* [optional] For full automation
*
* `GHOST=2.10.1,2.10.0 yarn ship`
* First value: Ships with Ghost
* Second value: Compatible with Ghost/GScan
*
* You can manually run in case the task has thrown an error.
*
* `npm_package_version=0.5.0 gulp release`
*/
const release = () => {
// @NOTE: https://yarnpkg.com/lang/en/docs/cli/version/
const newVersion = process.env.npm_package_version;
let shipsWithGhost = '{version}';
let compatibleWithGhost = '2.10.0';
const ghostEnvValues = process.env.GHOST || null;
if (ghostEnvValues) {
shipsWithGhost = ghostEnvValues.split(',')[0];
compatibleWithGhost = ghostEnvValues.split(',')[1];
if (!compatibleWithGhost) {
compatibleWithGhost = '2.10.0';
}
}
if (!newVersion || newVersion === '') {
console.log('Invalid version.');
return;
}
console.log(`\nDraft release for ${newVersion}.`);
if (!config || !config.github || !config.github.username || !config.github.token) {
console.log('Please copy config.example.json and configure Github token.');
return;
}
return previousRelease()
.then((previousVersion)=> {
changelog({previousVersion});
return releaseUtils
.releases
.create({
draft: true,
preRelease: false,
tagName: newVersion,
releaseName: newVersion,
userAgent: USER_AGENT,
uri: `https://api.github.com/repos/${REPO}/releases`,
github: {
username: config.github.username,
token: config.github.token
},
content: [`**Ships with Ghost ${shipsWithGhost} Compatible with Ghost >= ${compatibleWithGhost}**\n\n`],
changelogPath: CHANGELOG_PATH
})
.then((response)=> {
console.log(`\nRelease draft generated: ${response.releaseUrl}\n`);
});
});
};
exports.release = release;