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([{
type: 'input',
name: 'compatibleWithGhost',
message: 'Which version of Ghost is it compatible with?',
default: '3.0.0'
}]);
return inquirer.prompt([{ const compatibleWithGhost = result.compatibleWithGhost;
type: 'input',
name: 'compatibleWithGhost', const releasesResponse = await releaseUtils.releases.get({
message: 'Which version of Ghost is it compatible with?', userAgent: 'Casper',
default: '3.0.0' uri: `https://api.github.com/repos/${REPO_READONLY}/releases`
}]) });
.then(result => {
compatibleWithGhost = result.compatibleWithGhost; if (!releasesResponse || !releasesResponse) {
return Promise.resolve();
})
.then(() => releaseUtils.releases.get({
userAgent: 'Casper',
uri: `https://api.github.com/repos/${REPO_READONLY}/releases`
}))
.then((response) => {
if (!response || !response.length) {
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,27 +152,22 @@ exports.release = () => {
.sort() .sort()
.clean(); .clean();
return Promise.resolve(); const newReleaseResponse = await releaseUtils.releases.create({
}) draft: true,
.then(() => releaseUtils.releases.create({ preRelease: false,
draft: true, tagName: newVersion,
preRelease: false, releaseName: newVersion,
tagName: newVersion, userAgent: 'Casper',
releaseName: newVersion, uri: `https://api.github.com/repos/${REPO}/releases`,
userAgent: 'Casper', github: {
uri: `https://api.github.com/repos/${REPO}/releases`, token: githubToken
github: { },
token: config.github.token content: [`**Compatible with Ghost ≥ ${compatibleWithGhost}**\n\n`],
}, changelogPath: CHANGELOG_PATH
content: [`**Compatible with Ghost ≥ ${compatibleWithGhost}**\n\n`], });
changelogPath: CHANGELOG_PATH console.log(`\nRelease draft generated: ${newReleaseResponse.releaseUrl}\n`);
})) } catch (err) {
.then((response) => {
console.log(`\nRelease draft generated: ${response.releaseUrl}\n`);
return Promise.resolve();
})
.catch((err) => {
console.error(err); console.error(err);
process.exit(1); process.exit(1);
}); }
}; };