Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! feat: automate creation of the first LTS release
  • Loading branch information
richardlau committed Oct 22, 2020
commit 37b0acbb3c1301d7570770a3c49b6c58bff4a005
37 changes: 33 additions & 4 deletions lib/prepare_release.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
updateDeprecations
} = require('./deprecations');
const {
getEOLDate,
getStartLTSBlurb,
updateTestProcessRelease
} = require('./release/utils');
Expand Down Expand Up @@ -287,7 +288,7 @@ class ReleasePreparation {
}

async updateMainChangelog() {
const { versionComponents, newVersion } = this;
const { date, isLTSTransition, versionComponents, newVersion } = this;

// Remove the leading 'v'.
const lastRef = this.getLastRef().substring(1);
Expand All @@ -301,7 +302,20 @@ class ReleasePreparation {
const lastRefLink = `<a href="${hrefLink}#${lastRef}">${lastRef}</a>`;

for (let idx = 0; idx < arr.length; idx++) {
if (arr[idx].includes(`<b>${lastRefLink}</b><br/>`)) {
if (isLTSTransition) {
if (arr[idx].includes(hrefLink)) {
const eolDate = getEOLDate(date);
const eol = eolDate.toISOString().split('-').slice(0, 2).join('-');
arr[idx] = arr[idx].replace('**Current**', '**Long Term Support**');
arr[idx] = arr[idx].replace('"Current"', `"LTS Until ${eol}"`);
arr[idx] = arr[idx].replace('<sup>Current</sup>', '<sup>LTS</sup>');
} else if (arr[idx].includes('**Long Term Support**')) {
arr[idx] = arr[idx].replace(
'**Long Term Support**',
'Long Term Support'
);
}
} else if (arr[idx].includes(`<b>${lastRefLink}</b><br/>`)) {
arr.splice(idx, 1, `<b>${newRefLink}</b><br/>`, `${lastRefLink}<br/>`);
break;
}
Expand Down Expand Up @@ -341,9 +355,24 @@ class ReleasePreparation {
const newHeader =
`<a href="#${newVersion}">${newVersion}</a><br/>`;
for (let idx = 0; idx < arr.length; idx++) {
if (arr[idx].includes(topHeader)) {
arr.splice(idx, 0, newHeader);
if (isLTSTransition && arr[idx].includes('<th>Current</th>')) {
// Create a new column for LTS.
arr.splice(idx, 0, `<th>LTS '${ltsCodename}'</th>`);
idx++;
} else if (arr[idx].includes(topHeader)) {
if (isLTSTransition) {
// New release needs to go into the new column for LTS.
const toAppend = [
newHeader,
'</td>',
arr[idx - 1]
];
arr.splice(idx, 0, ...toAppend);
idx += toAppend.length;
} else {
arr.splice(idx, 0, newHeader);
idx++;
}
} else if (arr[idx].includes(`<a id="${lastRef.substring(1)}"></a>`)) {
const toAppend = [];
toAppend.push(`<a id="${newVersion}"></a>`);
Expand Down
29 changes: 22 additions & 7 deletions lib/release/utils.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
'use strict';

function getEOLDate(ltsStartDate) {
// Maintenance LTS lasts for 18 months.
const result = getLTSMaintenanceStartDate(ltsStartDate);
result.setMonth(result.getMonth() + 18);
return result;
}

function getLTSMaintenanceStartDate(ltsStartDate) {
// Active LTS lasts for one year.
const result = new Date(ltsStartDate);
result.setMonth(result.getMonth() + 12);
return result;
}

function getStartLTSBlurb({ date, ltsCodename, versionComponents }) {
const dateFormat = { month: 'long', year: 'numeric' };
// TODO pull these from the schedule.json in the Release repo?
// Active LTS lasts for one year.
const mainDate = new Date(date);
mainDate.setMonth(mainDate.getMonth() + 12);
const mainDate = getLTSMaintenanceStartDate(date);
const mainStart = mainDate.toLocaleString('en-US', dateFormat);
// Maintenance LTS lasts another 18 months.
const eolDate = new Date(mainStart);
eolDate.setMonth(eolDate.getMonth() + 18);
const eolDate = getEOLDate(date);
const eol = eolDate.toLocaleString('en-US', dateFormat);
const { major } = versionComponents;
return [
Expand Down Expand Up @@ -43,4 +53,9 @@ function updateTestProcessRelease(test, { versionComponents, ltsCodename }) {
return outLines.join('\n');
}

module.exports = { getStartLTSBlurb, updateTestProcessRelease };
module.exports = {
getEOLDate,
getLTSMaintenanceStartDate,
getStartLTSBlurb,
updateTestProcessRelease
};
26 changes: 25 additions & 1 deletion test/unit/prepare_release.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@ const assert = require('assert');
const { readFileSync } = require('fs');
const utils = require('../../lib/release/utils');

describe('prepare_release: utils.getEOLDate', () => {
it('calculates the correct EOL date', () => {
const test = utils.getEOLDate('2020-10-27');
const expected = new Date('2023-04-27');
const format = { month: 'short', year: 'numeric' };
assert.strictEqual(
test.toLocaleString('en-US', format),
expected.toLocaleString('en-US', format)
);
});
});

describe('prepare_release: utils.getLTSMaintenanceStartDate', () => {
it('calculates the correct LTS maintenance start date', () => {
const test = utils.getLTSMaintenanceStartDate('2020-10-27');
const expected = new Date('2021-10-27');
const format = { month: 'short', year: 'numeric' };
assert.strictEqual(
test.toLocaleString('en-US', format),
expected.toLocaleString('en-US', format)
);
});
});

describe('prepare_release: utils.getStartLTSBlurb', () => {
it('generates first LTS release text with correct dates', () => {
const expected = [
Expand All @@ -24,7 +48,7 @@ describe('prepare_release: utils.getStartLTSBlurb', () => {
});

describe('prepare_release: utils.updateTestProcessRelease', () => {
it('inserts test a for a new LTS codename', () => {
it('inserts test for a new LTS codename', () => {
const expected = readFileSync(
`${__dirname}/../fixtures/release/expected-test-process-release.js`,
{ encoding: 'utf8' }
Expand Down