@automattic/vip 2.36.1 → 2.36.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.js ADDED
@@ -0,0 +1,22 @@
1
+ require( '@automattic/eslint-plugin-wpvip/init' );
2
+
3
+ module.exports = {
4
+ extends: [
5
+ 'plugin:@automattic/wpvip/recommended',
6
+ 'plugin:@automattic/wpvip/cli',
7
+ 'plugin:@automattic/wpvip/weak-testing',
8
+ 'plugin:@automattic/wpvip/typescript',
9
+ ],
10
+ rules: {
11
+ camelcase: 'warn',
12
+ 'jest/no-mocks-import': 'warn',
13
+ 'no-await-in-loop': 'warn',
14
+ 'no-console': 0,
15
+ 'security/detect-object-injection': 0,
16
+ 'security/detect-non-literal-fs-filename': 0,
17
+ 'promise/no-multiple-resolved': 0,
18
+ 'no-unused-vars': 'off',
19
+ '@typescript-eslint/no-unused-vars': 'warn',
20
+ },
21
+ root: true,
22
+ };
package/.prettierignore CHANGED
@@ -1,4 +1,4 @@
1
- /CHANGELOG.md
1
+ /docs/CHANGELOG.md
2
2
  /__fixtures__/
3
3
  /dist/
4
- /flow-typed/
4
+ /npm-shrinkwrap.json
package/README.md CHANGED
@@ -1,31 +1,20 @@
1
- VIP-CLI is your tool for interacting with and managing your VIP applications.
1
+ # VIP-CLI
2
2
 
3
- ## Getting started
3
+ VIP-CLI is a tool for interacting with and managing your [WordPress VIP applications](https://wpvip.com/).
4
4
 
5
- First, install the package:
5
+ ## Further documentation
6
6
 
7
- ```
8
- npm install -g @automattic/vip
9
- ```
7
+ - [SETUP.md](https://github.com/Automattic/vip-cli/blob/trunk/docs/SETUP.md) for installation and setup instructions, basic usage and environmental variables.
8
+ - [ARCHITECTURE.md](https://github.com/Automattic/vip-cli/blob/trunk/docs/ARCHITECTURE.md) for information on architecture, code structure, data storage and security.
9
+ - [CONTRIBUTING.md](https://github.com/Automattic/vip-cli/blob/trunk/docs/CONTRIBUTING.md) for information on how to contribute patches and features, also issue and pull request labels.
10
+ - [DEBUGGING.md](https://github.com/Automattic/vip-cli/blob/trunk/docs/DEBUGGING.md) for information on how to debug the software.
11
+ - [TESTING.md](https://github.com/Automattic/vip-cli/blob/trunk/docs/TESTING.md) for details on testing the software and individual tasks.
12
+ - [RELEASING.md](https://github.com/Automattic/vip-cli/blob/trunk/docs/RELEASING.md) for details on deploying a new release.
13
+ - [SECURITY.md](https://github.com/Automattic/vip-cli/blob/trunk/docs/SECURITY.md) for information if you **found a security issue**.
10
14
 
11
- The above command may fail in linux if you do not have `make` and `g++` installed. In that case, install them first:
15
+ ## Further information
12
16
 
13
- ```
14
- sudo apt install make g++
15
- ```
16
-
17
- Then, launch the command and follow the prompts:
18
-
19
- ```
20
- vip
21
- ```
22
-
23
- If you need more information, check out our [VIP-CLI documentation](https://docs.wpvip.com/technical-references/vip-cli/).
24
-
25
- ## Contributing
26
-
27
- For help with contributing to this project, including instructions for local development, please see [CONTRIBUTING](CONTRIBUTING.md) and [SECURITY](SECURITY.md).
28
-
29
- ## Analytics
30
-
31
- By default, we record information about the usage of this tool using an in-house analytics sytem. If you would prefer to opt-out of this data collection, you can do so via the `DO_NOT_TRACK` environment variable. You may either export it in your shell configuration or specify it on the command line (e.g. `DO_NOT_TRACK=1 vip app list`).
17
+ - In the [WordPress VIP Lobby](https://lobby.vip.wordpress.com/) find announcements related to the [CLI](https://lobby.vip.wordpress.com/?s=vip-cli) and [API](https://lobby.vip.wordpress.com/?s=vip%20go%20api).
18
+ - The [WordPress VIP Documentation](https://docs.wpvip.com/) has instructions related to the [CLI](https://docs.wpvip.com/technical-references/vip-cli/).
19
+ - [Changelog](https://github.com/Automattic/vip-cli/blob/trunk/docs/CHANGELOG.md) file for VIP-CLI is available.
20
+ - [VIP Cloud Changelog](https://wpvipchangelog.wordpress.com/) logs changes to the [CLI](https://wpvipchangelog.wordpress.com/?s=cli) and other aspects of the platform.
@@ -27,11 +27,17 @@ const examples = [{
27
27
  const slug = await (0, _devEnvironmentCli.getEnvironmentName)(opt);
28
28
  const cmd = new _devEnvImportSql.DevEnvImportSQLCommand(fileName, opt, slug);
29
29
  const trackingInfo = (0, _devEnvironmentCli.getEnvTrackingInfo)(cmd.slug);
30
+ const trackerFn = (0, _tracker.makeCommandTracker)('dev_env_import_sql', trackingInfo);
31
+ await trackerFn('execute');
30
32
  try {
31
33
  await cmd.run();
32
- await (0, _tracker.trackEvent)('dev_env_import_sql_command_success', trackingInfo);
34
+ await trackerFn('success');
33
35
  } catch (error) {
34
- await (0, _devEnvironmentCli.handleCLIException)(error, 'dev_env_import_sql_command_error', trackingInfo);
36
+ await (0, _devEnvironmentCli.handleCLIException)(error);
37
+ await trackerFn('error', {
38
+ message: error.message,
39
+ stack: error.stack
40
+ });
35
41
  process.exitCode = 1;
36
42
  }
37
43
  });
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * External dependencies
5
+ */
6
+ "use strict";
7
+
8
+ var _chalk = _interopRequireDefault(require("chalk"));
9
+ var _debug = _interopRequireDefault(require("debug"));
10
+ var _command = _interopRequireDefault(require("../lib/cli/command"));
11
+ var _devEnvironment = require("../lib/constants/dev-environment");
12
+ var _devEnvironmentCli = require("../lib/dev-environment/dev-environment-cli");
13
+ var _devEnvironmentCore = require("../lib/dev-environment/dev-environment-core");
14
+ var _devEnvironmentLando = require("../lib/dev-environment/dev-environment-lando");
15
+ var _tracker = require("../lib/tracker");
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+ /**
18
+ * Internal dependencies
19
+ */
20
+ const debug = (0, _debug.default)('@automattic/vip:bin:dev-environment');
21
+ const examples = [{
22
+ usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} purge`,
23
+ description: 'Destroys all local dev environments'
24
+ }, {
25
+ usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} purge --force`,
26
+ description: 'Destroys all local dev environments without prompting'
27
+ }];
28
+ (0, _command.default)().option('soft', 'Keep config files needed to start an environment intact').option('force', 'Removes prompt that verifies if user wants to destroy all environments').examples(examples).argv(process.argv, async (arg, opt) => {
29
+ debug('Args: ', arg, 'Options: ', opt);
30
+ const allEnvNames = (0, _devEnvironmentCore.getAllEnvironmentNames)();
31
+ const lando = await (0, _devEnvironmentLando.bootstrapLando)();
32
+ if (allEnvNames.length === 0) {
33
+ console.log('No environments to purge!');
34
+ return;
35
+ }
36
+ if (!opt.force) {
37
+ const purge = await (0, _devEnvironmentCli.promptForBoolean)('Are you sure you want to purge ALL existing dev environments?', true);
38
+ if (!purge) {
39
+ return;
40
+ }
41
+ }
42
+ const trackingInfo = {
43
+ all: true
44
+ };
45
+ await (0, _tracker.trackEvent)('dev_env_purge_command_execute', trackingInfo);
46
+ await (0, _devEnvironmentCli.validateDependencies)(lando, '');
47
+ const removeFiles = !(opt.soft || false);
48
+ try {
49
+ for (const slug of allEnvNames) {
50
+ try {
51
+ // eslint-disable-next-line no-await-in-loop
52
+ await (0, _devEnvironmentCore.destroyEnvironment)(lando, slug, removeFiles);
53
+ const message = _chalk.default.green('✓') + ' Environment destroyed.\n';
54
+ console.log(message);
55
+ } catch (error) {
56
+ const trackingInfoChild = (0, _devEnvironmentCli.getEnvTrackingInfo)(slug);
57
+ // eslint-disable-next-line no-await-in-loop
58
+ await (0, _devEnvironmentCli.handleCLIException)(error, 'dev_env_purge_command_error', trackingInfoChild);
59
+ process.exitCode = 1;
60
+ }
61
+ }
62
+ await (0, _tracker.trackEvent)('dev_env_purge_command_success', trackingInfo);
63
+ } catch (error) {
64
+ await (0, _devEnvironmentCli.handleCLIException)(error, 'dev_env_purge_command_error', trackingInfo);
65
+ process.exitCode = 1;
66
+ }
67
+ });
@@ -67,7 +67,7 @@ cmd.argv(process.argv, async (arg, opt) => {
67
67
  const instanceData = await (0, _devEnvironmentCli.promptForArguments)(finalPreselectedOptions, defaultOptions, suppressPrompts);
68
68
  instanceData.siteSlug = slug;
69
69
  await (0, _devEnvironmentCore.updateEnvironment)(instanceData);
70
- const message = '\n' + _chalk.default.green('✓') + ' environment updated. Please start environment again for changes to take effect: ' + _chalk.default.bold(`vip dev env --slug ${slug} start`);
70
+ const message = '\n' + _chalk.default.green('✓') + ' environment updated. Please start environment again for changes to take effect: ' + _chalk.default.bold(`vip dev-env --slug ${slug} start`);
71
71
  console.log(message);
72
72
  await (0, _tracker.trackEvent)('dev_env_update_command_success', trackingInfo);
73
73
  } catch (error) {
@@ -5,4 +5,4 @@ var _command = _interopRequireDefault(require("../lib/cli/command"));
5
5
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
6
  (0, _command.default)({
7
7
  requiredArgs: 0
8
- }).command('create', 'Create a new local dev environment').command('update', 'Update an already created local dev environment').command('start', 'Start a local dev environment').command('stop', 'Stop a local dev environment').command('destroy', 'Remove containers, networks, volumes and configuration files of a local dev environment').command('info', 'Provides basic info about one or multiple local dev environments').command('list', 'Provides basic info about all local dev environments').command('exec', 'Execute a WP-CLI command in local dev environment').command('import', 'Import data into a local WordPress environment').command('shell', 'Spawns a shell in a dev environment').command('logs', 'View logs from a local WordPress environment').command('sync', 'Pull data from production to local development environment').argv(process.argv);
8
+ }).command('create', 'Create a new local dev environment').command('update', 'Update an already created local dev environment').command('start', 'Start a local dev environment').command('stop', 'Stop a local dev environment').command('destroy', 'Remove containers, networks, volumes and configuration files of a local dev environment').command('info', 'Provides basic info about one or multiple local dev environments').command('list', 'Provides basic info about all local dev environments').command('exec', 'Execute a WP-CLI command in local dev environment').command('import', 'Import data into a local WordPress environment').command('shell', 'Spawns a shell in a dev environment').command('logs', 'View logs from a local WordPress environment').command('sync', 'Pull data from production to local development environment').command('purge', 'Destroy all existing environments').argv(process.argv);
package/dist/bin/vip.js CHANGED
@@ -4,7 +4,6 @@
4
4
  var _chalk = _interopRequireDefault(require("chalk"));
5
5
  var _debug = _interopRequireDefault(require("debug"));
6
6
  var _enquirer = require("enquirer");
7
- var _opn = _interopRequireDefault(require("opn"));
8
7
  var _command = _interopRequireWildcard(require("../lib/cli/command"));
9
8
  var _config = _interopRequireDefault(require("../lib/cli/config"));
10
9
  var _token = _interopRequireDefault(require("../lib/token"));
@@ -66,7 +65,10 @@ const rootCmd = async function () {
66
65
  await (0, _tracker.trackEvent)('login_command_browser_cancelled');
67
66
  return;
68
67
  }
69
- (0, _opn.default)(tokenURL, {
68
+ const {
69
+ default: open
70
+ } = await import('open');
71
+ open(tokenURL, {
70
72
  wait: false
71
73
  });
72
74
  await (0, _tracker.trackEvent)('login_command_browser_opened');
@@ -19,7 +19,6 @@ class DevEnvImportSQLCommand {
19
19
  fileName;
20
20
  options;
21
21
  slug;
22
- trackingInfo;
23
22
  constructor(fileName, options, slug) {
24
23
  this.fileName = fileName;
25
24
  this.options = options;
@@ -376,7 +376,7 @@ class ExportSQLCommand {
376
376
  error_message: err?.message,
377
377
  stack: err?.stack
378
378
  });
379
- exit.withError('There is an export job already running for this environment: ' + `https://dashboard.wpvip.com/apps/${this.app.id}/${this.env.uniqueLabel}/data/database/backups\n` + 'Currently, we allow only one export job at a time, per site. Please try again later.');
379
+ exit.withError('There is an export job already running for this environment: ' + `https://dashboard.wpvip.com/apps/${this.app.id}/${this.env.uniqueLabel}/database/backups\n` + 'Currently, we allow only one export job at a time, per site. Please try again later.');
380
380
  } else {
381
381
  await this.track('error', {
382
382
  error_type: 'create_export_job',
@@ -0,0 +1,95 @@
1
+ # Architecture
2
+
3
+ ## Basic functionality
4
+
5
+ This is a CLI for interacting with and managing your [WordPress VIP applications](https://docs.wpvip.com/technical-references/vip-cli/). Data is inputted and outputted via terminal to the [API offered by WordPress VIP](#communicating-with-wpvip-api) and to/from local filesystem.
6
+
7
+ For configuration, a few [environmental variables](SETUP.md#environmental-variables) are used and some [configuration files](SETUP.md#configuration-files) as well. No [database](#database) is required.
8
+
9
+ ### Scalability
10
+
11
+ No specific considerations.
12
+
13
+ ### Communicating with WPVIP API
14
+
15
+ The CLI communicates primarily with https://api.wpvip.com. An authentication token is required to access the API which the CLI will ask for when executed. Tokens can be retrieved from the [VIP Dashboard](https://dashboard.wpvip.com/).
16
+
17
+ ## Languages & coding standard
18
+
19
+ Both JavaScript and TypeScript are used to implement the software. **TypeScript should be used for new code.**
20
+
21
+ We require that the WPVIP defined coding style to be used, defined in [.eslintrc.js](https://github.com/Automattic/vip-cli/blob/trunk/.eslintrc.js).
22
+
23
+ ## Code structure
24
+
25
+ The code is structured in the following way:
26
+
27
+ - [.github](https://github.com/Automattic/vip-cli/tree/trunk/.github) — configuration and templates for GitHub.
28
+ - [\_\_fixtures\_\_](https://github.com/Automattic/vip-cli/tree/trunk/__fixtures__) — fixtures for testing package.
29
+ - [\_\_tests\_\_](https://github.com/Automattic/vip-cli/tree/trunk/__tests__) — testing package.
30
+ - [config](https://github.com/Automattic/vip-cli/tree/trunk/config) — configuration files.
31
+ - [docs](https://github.com/Automattic/vip-cli/tree/trunk/docs) — documentation package.
32
+ - [types](https://github.com/Automattic/vip-cli/tree/trunk/types) - for TypeScript.
33
+ - [helpers](https://github.com/Automattic/vip-cli/tree/trunk/helpers) - helper scripts.
34
+ - [src](https://github.com/Automattic/vip-cli/tree/trunk/src) - main source code.
35
+
36
+ ## API interfaces
37
+
38
+ No APIs are offered.
39
+
40
+ ### GraphQL interfaces
41
+
42
+ No APIs are offered.
43
+
44
+ ## Feature flags
45
+
46
+ TODO: Do we apply feature flags in this code? Describe how it works.
47
+
48
+ ## Database
49
+
50
+ No database is needed.
51
+
52
+ ## Dependency services
53
+
54
+ VIP-CLI communicates with a few services via APIs:
55
+
56
+ - [WPVIP API](#communicating-with-wpvip-api).
57
+ - https://public-api.wordpress.com/rest – for analytics (can be [disabled](SETUP.md#analytics)).
58
+
59
+ ## Development
60
+
61
+ Here are guidelines to ensure we have consistency across the CLI and web interfaces.
62
+
63
+ ### Adding commands
64
+
65
+ - New command names should use the singular form (e.g. site vs sites).
66
+ - Add new commands to `package.json#bin`.
67
+ - Run `npm link` so that `arg` knows how to spawn the command locally. (Skipping this step will result in `Error: spawn vip-command ENOENT`.)
68
+
69
+ ### Adding libraries
70
+
71
+ New libraries should generally support both CLI and web contexts, though some cases that won't make sense (e.g. formatting for CLI output). Ensuring the libraries are useful everywhere will allow us to offer consistent experiences regardless of the interface.
72
+
73
+ ### go-search-replace binaries
74
+
75
+ Some unit tests require some go-search-replace executable binary files to run. Binaries files for
76
+ several OS architectures can be downloaded
77
+ from https://github.com/Automattic/go-search-replace/releases/
78
+
79
+ If, for some reason, you need to compile these binaries yourself, please follow instructions
80
+ at https://github.com/Automattic/go-search-replace
81
+
82
+ ### Generating the types
83
+
84
+ If you're an employee of Automattic, you can follow these steps to regenerate the GraphQL types
85
+ used.
86
+
87
+ 1. Get a hold of `schema.gql` and paste it in project root - this is the schema of the endpoint that
88
+ we communicate with.
89
+ 2. Run `npm run typescript:codegen:install-dependencies` - this will install the codegen
90
+ dependencies without updating `package.json`
91
+ 3. Run `npm run typescript:codegen:generate` - this will regenerate the types.
92
+
93
+ ## Alerting
94
+
95
+ There are no alerts.
@@ -1,5 +1,29 @@
1
1
  ## Changelog
2
2
 
3
+ ### 2.36.2
4
+
5
+ - #1558 fix(dev-env): Fix typo on suggested start command after updating env
6
+ - #1557 fix(dev-env): Fix an issue where dev-env-import-sql command execute event was not being tracked
7
+ - #1554 chore(dev-deps): update testing tools
8
+ - #1556 chore(dev-deps): update eslint from 8.52.0 to 8.54.0
9
+ - #1555 chore(deps): replace the deprecated `opn` with `open`
10
+ - #1553 chore(dev-deps): update TypeScript and typings
11
+ - #1578 build(deps-dev): bump @types/semver from 7.5.4 to 7.5.6
12
+ - #1577 Updating ESLint config
13
+ - #1559 Restructure and refine documentation + add missing tests
14
+ - #1591 Fix database backup URL in error message
15
+ - #1537 Add vip dev-env purge command logic
16
+ - #1590 build(deps): bump actions/setup-node from 3 to 4
17
+ - #1589 build(deps): bump actions/checkout from 3 to 4
18
+ - #1592 chore: group dependencies that should be updated together
19
+ - #1594 build(deps-dev): bump the babel group with 4 updates
20
+ - #1593 build(deps-dev): bump the testing group with 1 update
21
+ - #1595 build(deps-dev): bump typescript from 5.2.2 to 5.3.2
22
+ - #1596 build(deps): bump @automattic/vip-go-preflight-checks from 2.0.16 to 2.0.17
23
+ - #1580 build(deps): bump ini from 2.0.0 to 4.1.1
24
+ - #1598 build(deps-dev): bump @automattic/eslint-plugin-wpvip from 0.8.0 to 0.9.0
25
+ - #1597 chore(deps): update Lando
26
+
3
27
  ### 2.36.1
4
28
 
5
29
  - #1550 chore(deps): replace cli-table with cli-table3
@@ -0,0 +1,29 @@
1
+ # Contributing
2
+
3
+ ## Pull requests & issues
4
+
5
+ We welcome any contributions to this project.
6
+
7
+ If you have a small bugfix and already have the code available, feel free to [create a pull request](https://github.com/Automattic/vip-cli/compare). If you have a feature suggestion, please [create an issue](https://github.com/Automattic/vip-cli/issues/new). Please follow the instructions provided. Please assign a priority to the issue/pull request according to the definitions found below.
8
+
9
+ Before writing a patch or a larger chunk of code, please ensure to study the [ARCHITECTURE.md](ARCHITECTURE.md) and [TESTING.md](TESTING.md) files. Ensure that all tests pass before asking for a review of your pull request.
10
+
11
+ ## Priorities
12
+
13
+ Each GitHub issue and pull request relating to this repository should have a priority label to make prioritizing easier. The definition of each priority is as follows:
14
+
15
+ - [Critical](https://github.com/Automattic/vip-cli/labels/%5BPri%5D%20Critical): A bug currently affecting normal operation or a security problem that needs to be addressed urgently.
16
+ - [High](https://github.com/Automattic/vip-cli/labels/%5BPri%5D%20High): An issue that is: a) relevant to current goals of the project, b) a bug that needs to addressed soon to maintain stability, or c) a feature often requested.
17
+ - [Normal](https://github.com/Automattic/vip-cli/labels/%5BPri%5D%20Normal): Most issues belong here. These will include features less often requested, new lower priority features, documentation updates, etc.
18
+ - [Low](https://github.com/Automattic/vip-cli/labels/%5BPri%5D%20Low): Features that are good to have belong here.
19
+
20
+ ## Type of change labels
21
+
22
+ Each GitHub issue and pull-request should have a type of change label associated with it. The definition of these are as follows:
23
+
24
+ - [Bug](https://github.com/Automattic/vip-cli/labels/%5BType%5D%20Bug): Code change to fix a bug, or a bug report.
25
+ - [Clean up](https://github.com/Automattic/vip-cli/labels/%5B%20Type%20%5D%20Clean%20up): Pull request for general code clean ups.
26
+ - [Documentation](https://github.com/Automattic/vip-cli/labels/%5B%20Type%20%5D%20Documentation): Pull request to update documentation.
27
+ - [Enhancement](https://github.com/Automattic/vip-cli/labels/%5BType%5D%20Enhancement): A general enhancement – new feature, better implementation, new tests and so forth.
28
+ - [Remove feature](https://github.com/Automattic/vip-cli/labels/%5B%20Type%20%5D%20Remove%20feature): Pull request to remove feature code.
29
+ - [Update dependency](https://github.com/Automattic/vip-cli/labels/%5B%20Type%20%5D%20Update%20dependency): Pull request to update one or more dependencies.
@@ -0,0 +1,33 @@
1
+ # Debugging
2
+
3
+ ## Using debugger
4
+
5
+ A debugger can easily be used to help pinpointing issues with the code. Follow these steps.
6
+
7
+ 1. First, make sure to run the `npm run build:watch`, this will generate source maps
8
+ 2. Run the command you want via `node --inspect`, like so: `node --inspect ./dist/bin/vip-dev-env-import-sql.js`
9
+ 3. Note the port the debugger is listening on:
10
+
11
+ ```
12
+ Debugger listening on ws://127.0.0.1:9229/db6c03e9-2585-4a08-a1c6-1fee0295c9ff
13
+ For help, see: https://nodejs.org/en/docs/inspector
14
+ ```
15
+
16
+ 4. In your editor of choice attach to the debugger. For VSCode: Hit 'Run and Debug' panel, hit the "gear" icon (open launch.json), make your `Attach` configuration entry to look like so:
17
+ Make sure the `port` matches the port from step 3, and the `runtimeExecutable` matches the exact `node` executable you ran. If you use a version manager like `nvm`, its especially important to check this.
18
+
19
+ ```json
20
+ {
21
+ "name": "Attach",
22
+ "port": 9229,
23
+ "request": "attach",
24
+ "skipFiles": [ "<node_internals>/**" ],
25
+ "type": "node",
26
+ "runtimeExecutable": "/Users/user/.nvm/versions/node/v14.18.2/bin/node"
27
+ }
28
+ ```
29
+
30
+ 5. Set your breakpoints, add debug code, and hit the play button.
31
+ 6. Confirm that you attached the debugger to continue command execution.
32
+ 7. Resolve the problem.
33
+ 8. [Optional but recommended] Pay it forward and implement a similar approach to other internal/external tooling.
@@ -0,0 +1,163 @@
1
+ # Releasing
2
+
3
+ Please familiarize yourself with the [SETUP.md](SETUP.md) file before releasing.
4
+
5
+ ## New pull requests
6
+
7
+ Follow these steps for new pull requests:
8
+
9
+ 1. Please note the publishing method (see [below](#releasing-a-new-version)).
10
+
11
+ 1. Ensure when you create your pull request that:
12
+
13
+ a. It merges to `trunk`. The release flow for VIP-CLI follows this pattern: **_feature branch -> `trunk` branch_**
14
+
15
+ b. The feature branch follows A8C branch naming conventions, e.g.: `add/health-query`, `fix/subsite-mutation`, etc.
16
+
17
+ c. The pull request code and description contain no sensitive information. Please do not include any internal links in PRs, changelogs, testing instructions, etc. as this is a public repository.
18
+
19
+ d. You have included changelog entry by adding a `## Changelog Description` section to the GitHub pull request description. All changelogs are posted to the [VIP Cloud Changelog P2](https://wpvipchangelog.wordpress.com/) which customers can view and follow.
20
+
21
+ 1. Once you've created your pull request, ensure that:
22
+
23
+ a. You have added [all the automated tests required](TESTING.md#automated-testing).
24
+
25
+ b. You have completed [manual testing of your change](TESTING.md#manual-testing).
26
+
27
+ 1. If updating a dependency (NPM package or Node), follow the [guidelines on updating dependencies](SETUP.md#updating-dependencies).
28
+
29
+ 1. Have your pull request reviewed by a colleague and approved — especially if it is a large change or a complex addition.
30
+
31
+ 1. Verify that your pull request passes all automated tests.
32
+
33
+ 1. Merge your pull request.
34
+
35
+ ## Preparing for release
36
+
37
+ A few steps should be completed before releasing:
38
+
39
+ 1. Verify that [all relevant pull requests](https://github.com/Automattic/vip-cli/pulls) are merged.
40
+
41
+ 1. The [changelog](CHANGELOG.md) file in the repository should be [amended](#changelog-generation) to.
42
+
43
+ 1. Please note the publishing method (see [below](#releasing-a-new-version)).
44
+
45
+ 1. Determine strategy to [respond to problems post-deployment](#in-case-of-problems).
46
+
47
+ 1. The release has been tested across macOS, Windows, and Linux.
48
+
49
+ 1. All tests pass and your working directory is clean (we have pre-publish checks to catch this,
50
+ just-in-case).
51
+
52
+ 1. You have completed [final testing before deployment](TESTING.md#final-testing-before-releasing).
53
+
54
+ 1. The pre-publish [script](https://github.com/Automattic/vip-cli/blob/trunk/helpers/prepublishOnly.js) has been run. This script performs some confidence checks to avoid common mistakes.
55
+
56
+ 1. Finally, release your changes as a [new minor or major NPM version](#releasing-a-new-version).
57
+
58
+ If you need to publish a security release, see [details below](#patching-old-releases).
59
+
60
+ ### Changelog generation
61
+
62
+ Run the following to generate a changelog entry for CHANGELOG.md:
63
+
64
+ ```bash
65
+ export LAST_RELEASE_DATE=2021-08-25T13:40:00+02
66
+ gh pr list --search "is:merged sort:updated-desc closed:>$LAST_RELEASE_DATE" | sed -e 's/\s\+\S\+\tMERGED.*$//' -e 's/^/- #/'
67
+ ```
68
+
69
+ ## Releasing a new version
70
+
71
+ You can release either using GitHub Actions or locally.
72
+
73
+ ### Publishing via GitHub Actions (preferred)
74
+
75
+ This is the preferred method for pushing out the latest release. The workflow runs a bunch of validations, generates a build, bump versions + tags, pushes out to npm, and bumps to the next dev version.
76
+
77
+ Please keep in mind internal guidelines before releasing.
78
+
79
+ To release, follow these steps:
80
+
81
+ 1. Initiate the [release process here](https://github.com/Automattic/vip-cli/actions/workflows/npm-prepare-release.yml).
82
+ 1. On the right-hand side, select "Run Workflow".
83
+ 1. Pick your preferred version bump.
84
+ 1. Click `Run Workflow`.
85
+ 1. Wait for a pull request to appear. The pull request will update the version number and shall be assigned to you.
86
+ 1. When ready, merge the pull request. This will lead to a new version to be [published on npmjs.com](https://www.npmjs.com/package/@automattic/vip).
87
+ 1. Another pull request will be created to bump to a development version, also assigned to you. Merge it to finish the process.
88
+
89
+ #### Versioning Guidelines
90
+
91
+ - `patch`: for non-breaking changes/bugfixes and small updates.
92
+ - `minor`: for some new features, bug fixes, and other non-breaking changes.
93
+ - `major`: for breaking changes.
94
+
95
+ #### Note on NPM token
96
+
97
+ Publishing via the GitHub Action requires that the `NPM_TOKEN` be set correctly in GitHub Actions secrets. This should be an npm token generated for a bot user on [the npm @automattic org](https://www.npmjs.com/settings/automattic) that has publish access to this repo.
98
+
99
+ ### Alternative methods of releasing
100
+
101
+ #### Publishing locally
102
+
103
+ To publish locally, follow these steps:
104
+
105
+ <summary><details>
106
+
107
+ 1. Create a pull request that adds the next version's changelog into `trunk`. Use the Changelog
108
+ Generate Hint above to generate the changelog, and refer to previous releases to ensure that your
109
+ format matches.
110
+ 1. Merge it after approval.
111
+ 1. Make sure `trunk` branch is up-to-date: `git pull`.
112
+ 1. Make sure to clean all of your repositories of extra files. Run a dangerous, destructive
113
+ command `git clean -xfd` to do so.
114
+ 1. Run `npm install`.
115
+ 1. Set the version (via `npm version minor` or `npm version major` or `npm version patch`)
116
+ 1. For most regular releases, this will be `npm version minor`.
117
+ 1. Push the tag to GitHub (`git push --tags`)
118
+ 1. Push the trunk branch `git push`
119
+ 1. Make sure you're part of the Automattic organization in npm
120
+ 1. Publish the release to npm (`npm publish --access public`) the script will do some extra checks (
121
+ node version, branch, etc) to ensure everything is correct. If all looks good, the new version
122
+ will be published and you can proceed.
123
+ 1. Edit [the release on GitHub](https://github.com/Automattic/vip-cli/releases) to include a description
124
+ of the changes and publish (this can just copy the details from the changelog).
125
+
126
+ Once released, it's worth running `npm i -g @automattic/vip` to install / upgrade the released version to make sure everything looks good.
127
+
128
+ </details></summary>
129
+
130
+ #### Test Releases
131
+
132
+ Sometimes, we want to release a version we can test before releasing it to the public. In order to that, we need to release it under a tag other than `latest`, usually `next`. By default, `npm` install from the `latest` tag, so if `@next` isn't specified explicitely in the installation command like `npm install @automattic/vip@next`, a user will not get this version.
133
+
134
+ In order to do that, please follow this:
135
+
136
+ <summary><details>
137
+
138
+ 1. Manually change the version in `package.json` and `package-lock.json` to a dev version. Example: `1.4.0-dev1`
139
+ 1. Run `npm publish --tag next` (When `--tag` is specified, we bypass the usual branch protection that doesn't allow you to publish form a brunch other than `trunk`).
140
+
141
+ You can repeat this with every new version until you're happy with your version and ready to a public release. We currently don't support multiple branches for multiple versions. When it's the case, this process needs to be done for every version in every branch.
142
+
143
+ </details></summary>
144
+
145
+ #### Patching Old Releases
146
+
147
+ There may be times when we need to push out a critical fix to the most recent release (or several past releases) such as for patching security issues or major bugs. This can be complicated by the fact that we may have some larger changes already merged into the `trunk` branch.
148
+
149
+ <summary><details>
150
+
151
+ For these cases:
152
+
153
+ 1. `git checkout` to the tag of the previous release.
154
+ 1. Apply the fix (either manually or by cherry-picking).
155
+ 1. Follow the release steps outlined above (as a `patch` release).
156
+
157
+ Then, repeat for any additional versions that we need to patch.
158
+
159
+ </details></summary>
160
+
161
+ ## In case of problems
162
+
163
+ TODO: How to revert to a good state in case of problems?