From d97c294dd2024215acf88741263f6abbc29d6c31 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 19 May 2020 23:50:24 -0700 Subject: [PATCH 1/4] feat: update DEP0XXX tags during release prep --- lib/prepare_release.js | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/lib/prepare_release.js b/lib/prepare_release.js index 9a5b12c9..9eec1706 100644 --- a/lib/prepare_release.js +++ b/lib/prepare_release.js @@ -113,6 +113,11 @@ 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`); + // Fetch date to use in release commit & changelogs. const todayDate = new Date().toISOString().split('T')[0]; this.date = await cli.prompt('Enter release date in YYYY-MM-DD format:', @@ -225,6 +230,45 @@ 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; From 53a4c311a8495aaef6025d640a9e480703c9eb59 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 20 May 2020 11:38:27 -0700 Subject: [PATCH 2/4] refactor: check deps during landing --- lib/deprecations.js | 57 ++++++++++++++++++++++++++++++++++++ lib/landing_session.js | 20 +++++++++++-- lib/prepare_release.js | 65 ++++++++++++++---------------------------- 3 files changed, 95 insertions(+), 47 deletions(-) create mode 100644 lib/deprecations.js diff --git a/lib/deprecations.js b/lib/deprecations.js new file mode 100644 index 00000000..8f198f6e --- /dev/null +++ b/lib/deprecations.js @@ -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 +}; diff --git a/lib/landing_session.js b/lib/landing_session.js index 38898c4d..18d0efac 100644 --- a/lib/landing_session.js +++ b/lib/landing_session.js @@ -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'; @@ -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; } diff --git a/lib/prepare_release.js b/lib/prepare_release.js index 9eec1706..87cc1a66 100644 --- a/lib/prepare_release.js +++ b/lib/prepare_release.js @@ -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'; @@ -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]; @@ -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; From f8cbdc2227a99082a4ff5807dea07a4b5593415c Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 3 Jun 2020 12:37:40 -0700 Subject: [PATCH 3/4] Only auto-assign multiple DEPOXXX when landing --- lib/deprecations.js | 3 +-- lib/landing_session.js | 9 +++++---- lib/prepare_release.js | 23 +++++++++++++---------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/deprecations.js b/lib/deprecations.js index 8f198f6e..ae9a3119 100644 --- a/lib/deprecations.js +++ b/lib/deprecations.js @@ -18,14 +18,13 @@ async function getUnmarkedDeprecations() { return unmarkedDeprecations; } -async function updateDeprecations() { +async function updateDeprecations(unmarkedDeprecations) { 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(); diff --git a/lib/landing_session.js b/lib/landing_session.js index 18d0efac..482ecf50 100644 --- a/lib/landing_session.js +++ b/lib/landing_session.js @@ -87,15 +87,16 @@ class LandingSession extends Session { } } - // Update any new deprecations in the codebase. - const unmarkedDepCount = await getUnmarkedDeprecations(); + // Check for and maybe assign any unmarked deprecations in the codebase. + const unmarkedDeprecations = await getUnmarkedDeprecations(); + const unmarkedDepCount = unmarkedDeprecations.length; if (unmarkedDepCount > 0) { cli.startSpinner('Assigning deprecation numbers to DEPOXXX items'); - const updatedDepCount = await updateDeprecations(); + await updateDeprecations(unmarkedDeprecations); // 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.stopSpinner(`Updated ${unmarkedDepCount} DEPOXXX items in codebase`); } cli.ok('Patches applied'); diff --git a/lib/prepare_release.js b/lib/prepare_release.js index 87cc1a66..e664d81d 100644 --- a/lib/prepare_release.js +++ b/lib/prepare_release.js @@ -117,20 +117,23 @@ class ReleasePreparation { await this.updateREPLACEMEs(); cli.stopSpinner('Updated REPLACEME items in docs'); - // Check for any unmarked deprecations in the codebase. - const unmarkedDepCount = await getUnmarkedDeprecations(); + // Check for and maybe assign any unmarked deprecations in the codebase. + const unmarkedDeprecations = await getUnmarkedDeprecations(); + const unmarkedDepCount = unmarkedDeprecations.length; if (unmarkedDepCount > 0) { - const mark = await cli.prompt( - `Automatically mark ${unmarkedDepCount} deprecations?`); - if (mark) { + if (unmarkedDepCount === 1) { cli.startSpinner( - `Marking ${unmarkedDepCount} unmarked DEPOXXX items in codebase`); - const depCount = await updateDeprecations(); - cli.stopSpinner(`Updated ${depCount} DEPOXXX items in codebase`); + 'Assigning deprecation number to DEPOXXX item'); + await updateDeprecations(unmarkedDeprecations); + cli.stopSpinner('Assigned deprecation numbers to DEPOXXX items'); } else { - await cli.prompt('Finished updating unmarked DEPOXXX items?', + cli.warn( + 'More than one unmarked DEPOXXX item - manual resolution required.'); + + await cli.prompt( + `Finished updating ${unmarkedDepCount} unmarked DEPOXXX items?`, { defaultAnswer: false }); - cli.stopSpinner('Finished updating DEPOXXX items in codebase'); + cli.stopSpinner(`Finished updating ${unmarkedDepCount} DEPOXXX items`); } } From a3c6eb7b45f668ac5e4b5465cf4fb8f492bc6be1 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 4 Jun 2020 07:52:42 -0700 Subject: [PATCH 4/4] Staging......also important --- lib/landing_session.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/landing_session.js b/lib/landing_session.js index 482ecf50..c89d11e7 100644 --- a/lib/landing_session.js +++ b/lib/landing_session.js @@ -92,10 +92,12 @@ class LandingSession extends Session { const unmarkedDepCount = unmarkedDeprecations.length; if (unmarkedDepCount > 0) { cli.startSpinner('Assigning deprecation numbers to DEPOXXX items'); - await updateDeprecations(unmarkedDeprecations); - // Amend the last commit with the updated deprecation items. + // Update items then stage files and amend the last commit. + await updateDeprecations(unmarkedDeprecations); + await runAsync('git', ['add', 'doc', 'lib', 'src', 'test']); await runAsync('git', ['commit', '--amend', '--no-edit']); + cli.stopSpinner(`Updated ${unmarkedDepCount} DEPOXXX items in codebase`); }