From 7213bd8477d8726e5f94676cc8803443c05294a3 Mon Sep 17 00:00:00 2001 From: Bandini Bhopi Date: Wed, 7 Sep 2022 01:49:20 +0000 Subject: [PATCH] Remove release script and devDependencies used in script Issue Resolved: https://github.com/opensearch-project/oui/issues/64 Signed-off-by: Bandini Bhopi --- package.json | 3 - scripts/release.js | 293 --------------------------------------------- yarn.lock | 78 ++---------- 3 files changed, 9 insertions(+), 365 deletions(-) delete mode 100644 scripts/release.js diff --git a/package.json b/package.json index 4dbace94bb..c57df8a3ab 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,6 @@ }, "resolutions": { "**/trim": "0.0.3", - "prompt/async": "^3.2.3", "**/axios": "^0.21.1", "**/ansi-html": "^0.0.8", "**/merge": "^2.1.1", @@ -146,7 +145,6 @@ "@types/uuid": "^8.3.0", "@typescript-eslint/eslint-plugin": "^4.8.1", "@typescript-eslint/parser": "^4.8.1", - "argparse": "^2.0.1", "autoprefixer": "^9.8.6", "axe-core": "^4.1.1", "babel-core": "7.0.0-bridge.0", @@ -208,7 +206,6 @@ "postcss-loader": "^4.0.1", "pre-commit": "^1.2.2", "prettier": "^2.1.2", - "prompt": "^1.3.0", "prop-types": "^15.6.0", "puppeteer": "^5.5.0", "raw-loader": "^4.0.1", diff --git a/scripts/release.js b/scripts/release.js deleted file mode 100644 index edd1955f37..0000000000 --- a/scripts/release.js +++ /dev/null @@ -1,293 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - * - * Modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -const argparse = require('argparse'); -const chalk = require('chalk'); -const fs = require('fs'); -const path = require('path'); -const prompt = require('prompt'); -let { execSync } = require('child_process'); - -const cwd = path.resolve(__dirname, '..'); -const stdio = 'inherit'; -const execOptions = { cwd, stdio }; - -const TYPE_MAJOR = 0; -const TYPE_MINOR = 1; -const TYPE_PATCH = 2; -const humanReadableTypes = { - [TYPE_MAJOR]: 'major', - [TYPE_MINOR]: 'minor', - [TYPE_PATCH]: 'patch' -}; - -const args = parseArguments(); - -if (args.dry_run) { - console.warn(chalk.yellow('Dry run mode: no changes will be pushed to npm or Github')); - execSync = function() { - console.log.apply(null, arguments); - }; -} - -(async function () { - // make sure the release script is being run by npm (required for `npm publish` step) - // https://github.com/yarnpkg/yarn/issues/5063 - const packageManagerScript = path.basename(process.env.npm_execpath); - if (packageManagerScript !== 'npm-cli.js') { - console.error('The release script must be run with npm: npm run release'); - process.exit(1); - } - - // ensure git is on the master branch - await ensureMasterBranch(); - - // run linting and unit tests - if (args.steps.indexOf('test') > -1) { - execSync('npm test', execOptions); - } - - // (trans|com)pile `src` into `lib` and `dist` - if (args.steps.indexOf('build') > -1) { - execSync('npm run build', execOptions); - } - - - if (args.steps.indexOf('version') > -1) { - // prompt user for what type of version bump to make (major|minor|patch) - const versionTarget = await getVersionTypeFromChangelog(); - - // build may have generated a new i18ntokens.json file, dirtying the git workspace - // it's important to track those changes with this release, so determine the changes and write them - // to i18ntokens_changelog.json, comitting both to the workspace before running `npm version` - execSync(`npm run update-token-changelog -- ${versionTarget}`, execOptions); - - // update package.json & package-lock.json version, git commit, git tag - execSync(`npm version ${versionTarget}`, execOptions); - } - - if (args.steps.indexOf('tag') > -1) { - // push the version commit & tag to upstream - execSync('git push upstream --tags', execOptions); - } - - if (args.steps.indexOf('publish') > -1) { - // prompt user for npm 2FA - const otp = await getOneTimePassword(); - - // publish new version to npm - execSync(`npm publish --otp=${otp}`, execOptions); - } - - if (args.steps.indexOf('docs') > -1) { - // update docs, git commit, git push - execSync('npm run sync-docs', execOptions); - } -}()).catch(e => console.error(e)); - -function parseArguments() { - const parser = new argparse.ArgumentParser({ - add_help: true, - description: 'Tag and publish a new version of OUI', - }); - - parser.add_argument('--type', { - help: 'Version type; can be "major", "minor" or "patch"', - choices: Object.values(humanReadableTypes), - }); - - parser.add_argument('--dry-run', { - action: 'store_true', - default: false, - help: 'Dry run mode; no changes are made', - }); - - const allSteps = ['test', 'build', 'version', 'tag', 'publish', 'docs']; - parser.add_argument('--steps', { - help: 'Which release steps to run; a comma-separated list of values that can include "test", "build", "version", "tag", "publish" and "docs". If no value is given, all steps are run. Example: --steps=test,build,version,tag', - default: allSteps.join(','), - }); - - const args = parser.parse_args(); - - // validate --steps argument - const steps = args.steps.split(',').map(step => step.trim()); - const diff = steps.filter(x => allSteps.indexOf(x) === -1); - if (diff.length > 0) { - console.error(`Invalid --step value(s): ${diff.join(', ')}`); - process.exit(1); - } - - return { - ...args, - steps, - }; -} - -async function ensureMasterBranch() { - // ignore master check in CI since it's checking out the HEAD commit instead - if (process.env.CI === 'true') { - return; - } - - // delay importing nodegit because it can introduce environmental pains in a CI environment - const git = require('nodegit'); - const repo = await git.Repository.open(cwd); - const currentBranch = await repo.getCurrentBranch(); - const currentBranchName = currentBranch.shorthand(); - - if (currentBranchName !== 'master') { - console.error(`Unable to release: currently on branch "${currentBranchName}", expected "master"`); - process.exit(1); - } -} - -async function getVersionTypeFromChangelog() { - const pathToChangelog = path.resolve(cwd, 'CHANGELOG.md'); - - const changelog = fs.readFileSync(pathToChangelog).toString(); - - // Sanity check, if the changelog contains "No public interface changes"then we shouldn't be releasing - if (changelog.indexOf('No public interface changes') !== -1) { - console.error('Unable to release: CHANGELOG.md indicates "No public interface changes"'); - process.exit(1); - } - - // get contents between the first two headings - // changelog headings always use ##, this matches: - // - // "##.+?[\r\n]+" consume the first heading & linebreak(s), which describes the master branch - // "(.+?)" capture (non-greedy) all changes until the rest of the regex matches - // "[\r\n]+##" any linebreak(s) leading up to the next ## heading - // - // regex flags "su" enable dotAll (s) and unicode-character matching (u) - // - // effectively capturing pending changes in the capture group - // which is stored as the second item in the returned array from `changelog.match()` - const [, unreleasedchanges] = changelog.match(/##.+?[\r\n]+(.+?)[\r\n]+##/su); - - // these changes contain bug fixes if the string "**bug fixes**" exists - const hasBugFixes = unreleasedchanges.toLowerCase().indexOf('**bug fixes**') !== -1; - - // by convention, non-bug changes are listed first - // this checks if a markdown list character "-" exists before the "bug fixes" string, - // which indicates that there are other changes than bug fixes - const hasFeaturesWithBugFixes = !!unreleasedchanges.match(/.*-.*bug fixes/isu); - - // breaking changes are described under a "**breaking changes**" string - const hasBreakingChanges = unreleasedchanges.toLowerCase().indexOf('**breaking changes**') !== -1; - - // default to a MINOR bump (new features, may have bug fixes, no breaking changes) - let recommendedType = TYPE_MINOR; - - if (hasBugFixes && !hasFeaturesWithBugFixes) { - // there are bug fixes with no minor features - recommendedType = TYPE_PATCH; - } - - if (hasBreakingChanges) { - // detected breaking changes - recommendedType = TYPE_MAJOR; - } - - const humanReadableRecommendation = humanReadableTypes[recommendedType]; - console.log(chalk.magenta('Detected the following unreleased changes from CHANGELOG.md')); - console.log(''); - console.log(chalk.gray(unreleasedchanges)); - console.log(''); - console.log(`${chalk.magenta('The recommended version update for these changes is')} ${chalk.blue(humanReadableRecommendation)}`); - - // checking for --type argument value; used by CI to automate releases - const versionType = args.type; - if (versionType) { - // detected version type preference set - console.log(`${chalk.magenta('--type argument identifed, set to')} ${chalk.blue(versionType)}`); - - if (versionType !== humanReadableRecommendation) { - console.warn(`${chalk.yellow('WARNING: --type argument does not match recommended version update')}`); - } - - return versionType; - } else { - console.log(`${chalk.magenta('What part of the package version do you want to bump?')} ${chalk.gray('(major, minor, patch)')}`); - - return await promptUserForVersionType(); - } -} - -async function promptUserForVersionType() { - return new Promise((resolve, reject) => { - prompt.message = ''; - prompt.delimiter = ''; - prompt.start(); - prompt.get( - { - properties: { - version: { - description: 'choice:', - pattern: /^(major|minor|patch)$/, - message: 'Your choice must be major, minor or patch', - required: true - }, - } - }, - (err, { version }) => { - if (err) { - reject(err); - } else { - resolve(version); - } - } - ); - }); -} - -async function getOneTimePassword() { - const version = require('../package.json').version - console.log(chalk.magenta(`Preparing to publish @opensearch-project/oui@${version} to npm registry`)); - console.log(''); - console.log(chalk.magenta('The @elastic organization requires membership and 2FA to publish')); - - if (process.env.NPM_OTP) { - console.log(chalk.magenta('2FA code provided by NPM_OTP environment variable')); - return process.env.NPM_OTP; - } - - console.log(chalk.magenta('What is your one-time password?')); - - return await promptUserForOneTimePassword(); -} - -async function promptUserForOneTimePassword() { - return new Promise((resolve, reject) => { - prompt.message = ''; - prompt.delimiter = ''; - prompt.start(); - prompt.get( - { - properties: { - otp: { - description: 'Enter password:', - message: 'One-time password is required', - required: true - }, - } - }, - (err, { otp }) => { - if (err) { - reject(err); - } else { - resolve(otp); - } - } - ); - }); -} diff --git a/yarn.lock b/yarn.lock index d1ace131d4..f124362c97 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1110,11 +1110,6 @@ exec-sh "^0.3.2" minimist "^1.2.0" -"@colors/colors@1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9" - integrity sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ== - "@elastic/charts@^30.2.0": version "30.2.0" resolved "https://registry.yarnpkg.com/@elastic/charts/-/charts-30.2.0.tgz#95942317ac19a4b7cd81b78807059c82a565f3fb" @@ -2777,7 +2772,7 @@ ajv-keywords@^3.1.0, ajv-keywords@^3.4.1, ajv-keywords@^3.5.2: resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.5.2.tgz#31f29da5ab6e00d1c2d329acf7b5929614d5014d" integrity sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ== -ajv@^6.1.0, ajv@^6.10.0, ajv@^6.10.2, ajv@^6.12.2, ajv@^6.12.4, ajv@^6.9.1, ajv@^6.12.3, ajv@^6.12.5: +ajv@^6.1.0, ajv@^6.10.0, ajv@^6.10.2, ajv@^6.12.2, ajv@^6.12.3, ajv@^6.12.4, ajv@^6.12.5, ajv@^6.9.1: version "6.12.6" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g== @@ -2931,11 +2926,6 @@ argparse@^1.0.7: dependencies: sprintf-js "~1.0.2" -argparse@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38" - integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q== - aria-hidden@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/aria-hidden/-/aria-hidden-1.1.1.tgz#0c356026d3f65e2bd487a3adb73f0c586be2c37e" @@ -3141,11 +3131,6 @@ async-limiter@~1.0.0: resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.0.tgz#78faed8c3d074ab81f22b4e985d79e8738f720f8" integrity sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg== -async@3.2.3, async@^3.2.3: - version "3.2.4" - resolved "https://registry.yarnpkg.com/async/-/async-3.2.4.tgz#2d22e00f8cddeb5fde5dd33522b56d1cf569a81c" - integrity sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ== - async@^2.6.1, async@^2.6.2: version "2.6.4" resolved "https://registry.yarnpkg.com/async/-/async-2.6.4.tgz#706b7ff6084664cd7eae713f6f965433b5504221" @@ -3153,6 +3138,11 @@ async@^2.6.1, async@^2.6.2: dependencies: lodash "^4.17.14" +async@^3.2.3: + version "3.2.4" + resolved "https://registry.yarnpkg.com/async/-/async-3.2.4.tgz#2d22e00f8cddeb5fde5dd33522b56d1cf569a81c" + integrity sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ== + asynckit@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" @@ -4565,7 +4555,7 @@ colorette@^1.2.1: resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.1.tgz#4d0b921325c14faf92633086a536db6e89564b1b" integrity sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw== -colors@1.0.3, colors@1.0.x: +colors@1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b" integrity sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs= @@ -5155,11 +5145,6 @@ cwd@^0.9.1: dependencies: find-pkg "^0.1.0" -cycle@1.0.x: - version "1.0.3" - resolved "https://registry.yarnpkg.com/cycle/-/cycle-1.0.3.tgz#21e80b2be8580f98b468f379430662b046c34ad2" - integrity sha1-IegLK+hYD5i0aPN5QwZisEbDStI= - cyclist@~0.2.2: version "0.2.2" resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-0.2.2.tgz#1b33792e11e914a2fd6d6ed6447464444e5fa640" @@ -6722,11 +6707,6 @@ extsprintf@^1.2.0: resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f" integrity sha1-4mifjzVvrWLMplo6kcXfX5VRaS8= -eyes@0.1.x: - version "0.1.8" - resolved "https://registry.yarnpkg.com/eyes/-/eyes-0.1.8.tgz#62cf120234c683785d902348a800ef3e0cc20bc0" - integrity sha1-Ys8SAjTGg3hdkCNIqADvPgzCC8A= - faker@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/faker/-/faker-4.1.0.tgz#1e45bbbecc6774b3c195fad2835109c6d748cc3f" @@ -9223,7 +9203,7 @@ isobject@^3.0.0, isobject@^3.0.1: resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df" integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8= -isstream@0.1.x, isstream@~0.1.2: +isstream@~0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a" integrity sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo= @@ -11032,7 +11012,7 @@ mute-stream@0.0.7: resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab" integrity sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s= -mute-stream@0.0.8, mute-stream@~0.0.4: +mute-stream@0.0.8: version "0.0.8" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d" integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA== @@ -12932,17 +12912,6 @@ promise-retry@^2.0.1: err-code "^2.0.2" retry "^0.12.0" -prompt@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/prompt/-/prompt-1.3.0.tgz#b1f6d47cb1b6beed4f0660b470f5d3ec157ad7ce" - integrity sha512-ZkaRWtaLBZl7KKAKndKYUL8WqNT+cQHKRZnT4RYYms48jQkFw3rrBL+/N5K/KtdEveHkxs982MX2BkDKub2ZMg== - dependencies: - "@colors/colors" "1.5.0" - async "3.2.3" - read "1.0.x" - revalidator "0.1.x" - winston "2.x" - prompts@^2.0.1: version "2.0.3" resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.0.3.tgz#c5ccb324010b2e8f74752aadceeb57134c1d2522" @@ -13575,13 +13544,6 @@ read-pkg@^5.2.0: parse-json "^5.0.0" type-fest "^0.6.0" -read@1.0.x: - version "1.0.7" - resolved "https://registry.yarnpkg.com/read/-/read-1.0.7.tgz#b3da19bd052431a97671d44a42634adf710b40c4" - integrity sha1-s9oZvQUkMal2cdRKQmNK33ELQMQ= - dependencies: - mute-stream "~0.0.4" - "readable-stream@1 || 2", readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.4, readable-stream@^2.0.6, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.0, readable-stream@^2.3.3, readable-stream@^2.3.5: version "2.3.6" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf" @@ -14101,11 +14063,6 @@ reusify@^1.0.4: resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76" integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw== -revalidator@0.1.x: - version "0.1.8" - resolved "https://registry.yarnpkg.com/revalidator/-/revalidator-0.1.8.tgz#fece61bfa0c1b52a206bd6b18198184bdd523a3b" - integrity sha1-/s5hv6DBtSoga9axgZgYS91SOjs= - rgb-regex@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/rgb-regex/-/rgb-regex-1.0.1.tgz#c0e0d6882df0e23be254a475e8edd41915feaeb1" @@ -14986,11 +14943,6 @@ stable@^0.1.8: resolved "https://registry.yarnpkg.com/stable/-/stable-0.1.8.tgz#836eb3c8382fe2936feaf544631017ce7d47a3cf" integrity sha512-ji9qxRnOVfcuLDySj9qzhGSEFVobyt1kIOSkj1qZzYLzq7Tos/oUUWvotUPQLlrsidqsK6tBH89Bc9kL5zHA6w== -stack-trace@0.0.x: - version "0.0.10" - resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0" - integrity sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA= - stack-utils@^1.0.1: version "1.0.5" resolved "https://registry.yarnpkg.com/stack-utils/-/stack-utils-1.0.5.tgz#a19b0b01947e0029c8e451d5d61a498f5bb1471b" @@ -16837,18 +16789,6 @@ windows-release@^3.1.0: dependencies: execa "^1.0.0" -winston@2.x: - version "2.4.6" - resolved "https://registry.yarnpkg.com/winston/-/winston-2.4.6.tgz#da616f332928f70aac482f59b43d62228f29e478" - integrity sha512-J5Zu4p0tojLde8mIOyDSsmLmcP8I3Z6wtwpTDHx1+hGcdhxcJaAmG4CFtagkb+NiN1M9Ek4b42pzMWqfc9jm8w== - dependencies: - async "^3.2.3" - colors "1.0.x" - cycle "1.0.x" - eyes "0.1.x" - isstream "0.1.x" - stack-trace "0.0.x" - word-wrap@^1.2.3, word-wrap@~1.2.3: version "1.2.3" resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"