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