Removed the need for config.json when releasing

no issue

- we previously needed a config.json to provide the GitHub token for
  publishing new Casper releases
- this commit removes the need for this file by pulling the token from
  the environment variable, which everyone in the Core team has set up
This commit is contained in:
Daniel Lockyer 2021-03-03 13:20:58 +00:00
parent 44e33120cb
commit f12ce05454
No known key found for this signature in database
GPG Key ID: FFBC6FA2A6F6ABC1

View File

@ -96,10 +96,10 @@ exports.build = build;
exports.zip = series(build, zipper); exports.zip = series(build, zipper);
exports.default = series(build, serve, watcher); exports.default = series(build, serve, watcher);
exports.release = () => { exports.release = async () => {
// @NOTE: https://yarnpkg.com/lang/en/docs/cli/version/ // @NOTE: https://yarnpkg.com/lang/en/docs/cli/version/
// require(./package.json) can run into caching issues, this re-reads from file everytime on release // require(./package.json) can run into caching issues, this re-reads from file everytime on release
var packageJSON = JSON.parse(fs.readFileSync('./package.json')); let packageJSON = JSON.parse(fs.readFileSync('./package.json'));
const newVersion = packageJSON.version; const newVersion = packageJSON.version;
if (!newVersion || newVersion === '') { if (!newVersion || newVersion === '') {
@ -109,45 +109,36 @@ exports.release = () => {
console.log(`\nCreating release for ${newVersion}...`); console.log(`\nCreating release for ${newVersion}...`);
let config; const githubToken = process.env.GST_TOKEN;
try {
config = require('./config');
} catch (err) {
config = null;
}
if (!config || !config.github || !config.github.token) { if (githubToken) {
console.log('Please copy config.example.json and configure Github token.'); console.log('Please configure your environment with a Github token located in GST_TOKEN');
return; return;
} }
let compatibleWithGhost; try {
const result = await inquirer.prompt([{
return inquirer.prompt([{
type: 'input', type: 'input',
name: 'compatibleWithGhost', name: 'compatibleWithGhost',
message: 'Which version of Ghost is it compatible with?', message: 'Which version of Ghost is it compatible with?',
default: '3.0.0' default: '3.0.0'
}]) }]);
.then(result => {
compatibleWithGhost = result.compatibleWithGhost; const compatibleWithGhost = result.compatibleWithGhost;
return Promise.resolve();
}) const releasesResponse = await releaseUtils.releases.get({
.then(() => releaseUtils.releases.get({
userAgent: 'Casper', userAgent: 'Casper',
uri: `https://api.github.com/repos/${REPO_READONLY}/releases` uri: `https://api.github.com/repos/${REPO_READONLY}/releases`
})) });
.then((response) => {
if (!response || !response.length) { if (!releasesResponse || !releasesResponse) {
console.log('No releases found. Skipping...'); console.log('No releases found. Skipping...');
return; return;
} }
let previousVersion = response[0].tag_name || response[0].name; let previousVersion = releasesResponse[0].tag_name || releasesResponse[0].name;
console.log(`Previous version: ${previousVersion}`); console.log(`Previous version: ${previousVersion}`);
return Promise.resolve(previousVersion);
})
.then((previousVersion) => {
const changelog = new releaseUtils.Changelog({ const changelog = new releaseUtils.Changelog({
changelogPath: CHANGELOG_PATH, changelogPath: CHANGELOG_PATH,
folder: path.join(process.cwd(), '.') folder: path.join(process.cwd(), '.')
@ -161,9 +152,7 @@ exports.release = () => {
.sort() .sort()
.clean(); .clean();
return Promise.resolve(); const newReleaseResponse = await releaseUtils.releases.create({
})
.then(() => releaseUtils.releases.create({
draft: true, draft: true,
preRelease: false, preRelease: false,
tagName: newVersion, tagName: newVersion,
@ -171,17 +160,14 @@ exports.release = () => {
userAgent: 'Casper', userAgent: 'Casper',
uri: `https://api.github.com/repos/${REPO}/releases`, uri: `https://api.github.com/repos/${REPO}/releases`,
github: { github: {
token: config.github.token token: githubToken
}, },
content: [`**Compatible with Ghost ≥ ${compatibleWithGhost}**\n\n`], content: [`**Compatible with Ghost ≥ ${compatibleWithGhost}**\n\n`],
changelogPath: CHANGELOG_PATH changelogPath: CHANGELOG_PATH
})) });
.then((response) => { console.log(`\nRelease draft generated: ${newReleaseResponse.releaseUrl}\n`);
console.log(`\nRelease draft generated: ${response.releaseUrl}\n`); } catch (err) {
return Promise.resolve();
})
.catch((err) => {
console.error(err); console.error(err);
process.exit(1); process.exit(1);
}); }
}; };