Skip to content

Commit

Permalink
git-node: add promotion step
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Apr 9, 2020
1 parent 9d9fb2f commit 06dfd34
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 6 deletions.
36 changes: 30 additions & 6 deletions components/git/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

const yargs = require('yargs');

const auth = require('../../lib/auth');
const CLI = require('../../lib/cli');
const ReleasePreparation = require('../../lib/prepare_release');
const ReleasePromotion = require('../../lib/promote_release');
const TeamInfo = require('../../lib/team_info');
const Request = require('../../lib/request');
const { runPromise } = require('../../lib/run');

const PREPARE = 'prepare';
const PROMOTE = 'promote';
const RELEASERS = 'releasers';

const releaseOptions = {
prepare: {
Expand All @@ -30,7 +35,9 @@ function builder(yargs) {
describe: 'Version number of the release to be prepared or promoted'
})
.example('git node release --prepare 1.2.3',
'Prepare a new release of Node.js tagged v1.2.3');
'Prepare a new release of Node.js tagged v1.2.3')
.example('git node release --promote 1.2.3',
'Promote a prepared release of Node.js tagged v1.2.3');
}

function handler(argv) {
Expand Down Expand Up @@ -67,15 +74,17 @@ module.exports = {
};

async function main(state, argv, cli, dir) {
let release;

if (state === PREPARE) {
const prep = new ReleasePreparation(argv, cli, dir);
release = new ReleasePreparation(argv, cli, dir);

if (prep.warnForWrongBranch()) return;
if (release.warnForWrongBranch()) return;

// If the new version was automatically calculated, confirm it.
if (!argv.newVersion) {
const create = await cli.prompt(
`Create release with new version ${prep.newVersion}?`,
`Create release with new version ${release.newVersion}?`,
{ defaultAnswer: true });

if (!create) {
Expand All @@ -84,8 +93,23 @@ async function main(state, argv, cli, dir) {
}
}

return prep.prepare();
return release.prepare();
} else if (state === PROMOTE) {
// TODO(codebytere): implement release promotion.
release = new ReleasePromotion(argv, cli, dir);

cli.startSpinner('Verifying Releaser status');
const credentials = await auth({ github: true });
const request = new Request(credentials);
const info = new TeamInfo(cli, request, 'nodejs', RELEASERS);

const releasers = await info.getMembers();
if (!releasers.some(r => r.login === release.username)) {
cli.stopSpinner(
`${release.username} is not a Releaser; aborting release`);
return;
}
cli.stopSpinner('Verified Releaser status');

return release.promote();
}
}
80 changes: 80 additions & 0 deletions lib/promote_release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
'use strict';

const path = require('path');
const { promises: fs } = require('fs');
const semver = require('semver');

const { getMergedConfig } = require('./config');
const { runAsync, runSync } = require('./run');
const { writeJson, readJson } = require('./file');

const isWindows = process.platform === 'win32';

class ReleasePreparation {
constructor(argv, cli, dir) {
this.cli = cli;
this.dir = dir;
this.isSecurityRelease = argv.security;
this.isLTS = await this.checkIsLTS;
this.ltsCodename = '';
this.date = '';
this.config = getMergedConfig(this.dir);
}

async promote() {
// Verify that CI is green

// Verify that the PR has at least one approval from a Releaser

//
}

async checkIsLTS() {
const filePath = path.resolve('src', 'node_version.h');
const data = await fs.readFile(filePath, 'utf8');
const arr = data.split('\n');

for (let idx = 0; idx < arr.length; idx++) {
const line = arr[idx];
if (line.includes('#define NODE_VERSION_IS_LTS')) {
return line.split(' ')[2] === '1';
}
}
}

// Returns the LTS codename for the Release line; e.g 'Erbium' for 12.x.
async checkReleaseCodename() {
const filePath = path.resolve('src', 'node_version.h');
const data = await fs.readFile(filePath, 'utf8');
const arr = data.split('\n');

for (let idx = 0; idx < arr.length; idx++) {
const line = arr[idx];
if (line.includes('#define NODE_VERSION_LTS_CODENAME')) {
return line.split(' ')[2];
}
}


}

// Set up the branch so that nightly builds are produced with the next
// version number and a pre-release tag.
async setupForNextRelease() {
const { versionComponents } = this;

const filePath = path.resolve('src', 'node_version.h');
const data = await fs.readFile(filePath, 'utf8');
const arr = data.split('\n');

arr.forEach((line, idx) => {
if (line.includes('#define NODE_PATCH_VERSION')) {
arr[idx] = `#define NODE_PATCH_VERSION ${versionComponents.patch + 1}`;
} else if (line.includes('#define NODE_VERSION_IS_RELEASE')) {
arr[idx] = '#define NODE_VERSION_IS_RELEASE 0';
}
});

await fs.writeFile(filePath, arr.join('\n'));
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"figures": "^3.1.0",
"fs-extra": "^8.1.0",
"ghauth": "^4.0.0",
"git-secure-tag": "^2.3.1",
"inquirer": "^7.0.0",
"listr": "^0.14.3",
"listr-input": "^0.2.0",
Expand Down

0 comments on commit 06dfd34

Please sign in to comment.