Skip to content

Commit

Permalink
refactor: check deps during landing
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed May 20, 2020
1 parent 3a8e38c commit 2f0b952
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 47 deletions.
57 changes: 57 additions & 0 deletions lib/deprecations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

const { promises: fs } = require('fs');
const path = require('path');
const replace = require('replace-in-file');

const newDeprecationPattern =
/<\s*a id="DEP0([X]+[0-9]*)+"[^>]*><\s*\/\s*a>/g;

async function getUnmarkedDeprecations() {
const deprecationFilePath = path.resolve('doc', 'api', 'deprecations.md');
const deprecationFile = await fs.readFile(deprecationFilePath, 'utf8');

const unmarkedDeprecations = [
...deprecationFile.matchAll(newDeprecationPattern)
].map(m => m[1]);

return unmarkedDeprecations;
}

async function updateDeprecations() {
const deprecationPattern =
/<\s*a id="DEP0([0-9]{3})+"[^>]*><\s*\/\s*a>/g;

const deprecationFilePath = path.resolve('doc', 'api', 'deprecations.md');
const deprecationFile = await fs.readFile(deprecationFilePath, 'utf8');

const unmarkedDeprecations = await getUnmarkedDeprecations();
const deprecationNumbers = [
...deprecationFile.matchAll(deprecationPattern)
].map(m => m[1]).reverse();

// Pull highest deprecation number off the list and increment from there.
let depNumber = parseInt(deprecationNumbers[0]) + 1;

// Loop through each new unmarked deprecation number and replace instances.
for (const unmarked of unmarkedDeprecations) {
await replace({
files: [
'doc/api/*.md',
'lib/**/*.js',
'src/**/*.{h,cc}',
'test/**/*.js'
],
ignore: 'test/common/README.md',
from: new RegExp(`DEP0${unmarked}`, 'g'),
to: `DEP0${depNumber}`
});

depNumber++;
}
}

module.exports = {
updateDeprecations,
getUnmarkedDeprecations
};
20 changes: 17 additions & 3 deletions lib/landing_session.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
'use strict';

const path = require('path');
const {
getUnmarkedDeprecations,
updateDeprecations
} = require('./deprecations');

const {
runAsync, runSync, forceRunAsync
} = require('./run');
const Session = require('./session');
const {
shortSha
} = require('./utils');
const { shortSha } = require('./utils');

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

Expand Down Expand Up @@ -84,6 +86,18 @@ class LandingSession extends Session {
process.exit(1);
}
}

// Update any new deprecations in the codebase.
const unmarkedDepCount = await getUnmarkedDeprecations();
if (unmarkedDepCount > 0) {
cli.startSpinner('Assigning deprecation numbers to DEPOXXX items');
const updatedDepCount = await updateDeprecations();

// Amend the last commit with the updated deprecation items.
await runAsync('git', ['commit', '--amend', '--no-edit']);
cli.stopSpinner(`Updated ${updatedDepCount} DEPOXXX items in codebase`);
}

cli.ok('Patches applied');
return patch;
}
Expand Down
65 changes: 21 additions & 44 deletions lib/prepare_release.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
'use strict';

const path = require('path');
const fs = require('fs').promises;
const { promises: fs } = require('fs');
const semver = require('semver');
const replace = require('replace-in-file');

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

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

Expand Down Expand Up @@ -113,10 +117,22 @@ class ReleasePreparation {
await this.updateREPLACEMEs();
cli.stopSpinner('Updated REPLACEME items in docs');

// Update any new deprecations in the codebase.
cli.startSpinner('Updating DEPOXXX items in codebase');
const depCount = await this.updateDeprecations();
cli.stopSpinner(`Updated ${depCount} DEPOXXX items in codebase`);
// Check for any unmarked deprecations in the codebase.
const unmarkedDepCount = await getUnmarkedDeprecations();
if (unmarkedDepCount > 0) {
const mark = await cli.prompt(
`Automatically mark ${unmarkedDepCount} deprecations?`);
if (mark) {
cli.startSpinner(
`Marking ${unmarkedDepCount} unmarked DEPOXXX items in codebase`);
const depCount = await updateDeprecations();
cli.stopSpinner(`Updated ${depCount} DEPOXXX items in codebase`);
} else {
await cli.prompt('Finished updating unmarked DEPOXXX items?',
{ defaultAnswer: false });
cli.stopSpinner('Finished updating DEPOXXX items in codebase');
}
}

// Fetch date to use in release commit & changelogs.
const todayDate = new Date().toISOString().split('T')[0];
Expand Down Expand Up @@ -230,45 +246,6 @@ class ReleasePreparation {
]).trim();
}

async updateDeprecations() {
const deprecationPattern =
/<\s*a id="DEP0([0-9]{3})+"[^>]*><\s*\/\s*a>/g;
const newDeprecationPattern =
/<\s*a id="DEP0([X]+[0-9]*)+"[^>]*><\s*\/\s*a>/g;

const deprecationFilePath = path.resolve('doc', 'api', 'deprecations.md');
const deprecationFile = await fs.readFile(deprecationFilePath, 'utf8');

const deprecationNumbers = [
...deprecationFile.matchAll(deprecationPattern)
].map(m => m[1]).reverse();
const newDeprecationNumbers = [
...deprecationFile.matchAll(newDeprecationPattern)
].map(m => m[1]);

// Pull highest deprecation number off the list and increment from there.
let depNumber = parseInt(deprecationNumbers[0]) + 1;

// Loop through each new unmarked deprecation number and replace instances.
for (const newDep of newDeprecationNumbers) {
await replace({
files: [
'doc/api/*.md',
'lib/**/*.js',
'src/**/*.{h,cc}',
'test/**/*.js'
],
ignore: 'test/common/README.md',
from: new RegExp(`DEP0${newDep}`, 'g'),
to: `DEP0${depNumber}`
});

depNumber++;
}

return newDeprecationNumbers.length;
}

async updateREPLACEMEs() {
const { newVersion } = this;

Expand Down

0 comments on commit 2f0b952

Please sign in to comment.