|
1 |
| -# The Mongo Shell Build System |
2 |
| - |
3 |
| -[Evergreen Build][evergreen-url] |
4 |
| - |
5 |
| -This package contains all the tools needed to build and release mongosh. |
6 |
| - |
7 |
| -Build process is done on [Evergreen][evergreen-url] and is triggered with every commit. |
8 |
| -Releases are triggered by a git tag when ran with `npm run publish-npm` from the |
9 |
| -root of the project. |
10 |
| - |
11 |
| -For full details on how to run a release, check in with [`compass-internal |
12 |
| --docs`](https://github.com/10gen/compass-internal-docs/blob/master/technical/mongosh/mongosh-release.md) repo. |
13 |
| - |
14 |
| -Current build and release flow is as follows: |
15 |
| - |
16 |
| -### `npm run evergreen-release package` |
17 |
| -- A commit triggers an evergreen build based on currently available build |
18 |
| - variants: MacOS, Windows, Linux, Debian, and RedHat. |
19 |
| -- MacOS, Linux and Windows run three tasks: check, test, and release. Debian and |
20 |
| - Redhat run two tasks: check and release. Debian and Redhat also depend on |
21 |
| - tests to pass on Linux. |
22 |
| -- Identical bundle and binary are built on all five variants. |
23 |
| -- MacOS binary is signed and notarized. |
24 |
| -- Each variant creates its own archive (`.zip`, `.tgz`, `.deb`, `.rpm`). Type of |
25 |
| - archive is determined by the current build variant. |
26 |
| -- Each variant uploads its own tarball to Evergreen’s AWS. |
27 |
| -- Linux build variants upload their artifacts to `barque` using |
28 |
| - [`curator`](https://github.com/mongodb/curator) to be used with MongoDB's PPA. The uploaded packages can be found under the following URLs: |
29 |
| - 1. Ubuntu: https://repo.mongodb.org/apt/ubuntu/dists/bionic/mongodb-org/4.4/multiverse/binary-amd64/ |
30 |
| - 2. Redhat: https://repo.mongodb.org/yum/redhat/8Server/mongodb-org/4.4/x86_64/RPMS/ |
31 |
| - 3. Debian: https://repo.mongodb.org/apt/debian/dists/buster/mongodb-org/4.4/main/binary-amd64/ |
32 |
| -- The five build variants run in parallel. |
33 |
| -### `npm run evergreen-release publish` |
34 |
| -- All the previous build steps succeeded. |
35 |
| -- A separate MacOS build variant (darwin_publish_release) uploads config file |
36 |
| - with information about the new version for each platform to Downloads Centre. |
37 |
| -This only happens on a tagged commit. |
38 |
| -- A separate MacOS build variant (darwin_publish_release) promotes the draft |
39 |
| - github release to public. This only happens on a tagged commit. |
40 |
| - |
41 |
| -![build flow][build-img] |
42 |
| - |
43 |
| -## Usage |
44 |
| - |
45 |
| -```js |
46 |
| -const release = require('@mongosh/build'); |
47 |
| - |
48 |
| -const config = { |
49 |
| - version: '0.0.1', |
50 |
| - appleNotarizationBundleId: 'appleNotarizationBundleId', |
51 |
| - input: 'input', |
52 |
| - execInput: 'execInput', |
53 |
| - outputDir: 'outputDir', |
54 |
| - analyticsConfigFilePath: 'analyticsConfigFilePath', |
55 |
| - project: 'project', |
56 |
| - revision: 'revision', |
57 |
| - branch: 'branch', |
58 |
| - evgAwsKey: 'evgAwsKey', |
59 |
| - evgAwsSecret: 'evgAwsSecret', |
60 |
| - downloadCenterAwsKey: 'downloadCenterAwsKey', |
61 |
| - downloadCenterAwsSecret: 'downloadCenterAwsSecret', |
62 |
| - githubToken: 'githubToken', |
63 |
| - segmentKey: 'segmentKey', |
64 |
| - appleNotarizationUsername: 'appleNotarizationUsername', |
65 |
| - appleNotarizationApplicationPassword: 'appleNotarizationApplicationPassword', |
66 |
| - appleCodesignIdentity: 'appleCodesignIdentity', |
67 |
| - isCi: true, |
68 |
| - platform: 'platform', |
69 |
| - distributionBuildVariant: 'linux', |
70 |
| - repo: { |
71 |
| - owner: 'owner', |
72 |
| - repo: 'repo', |
73 |
| - }, |
74 |
| - dryRun: false |
75 |
| -} |
76 |
| - |
77 |
| -const command = 'package'; // or 'publish' |
78 |
| - |
79 |
| -const runRelease = async() => { |
80 |
| - await release(command, config); |
81 |
| -}; |
82 |
| - |
83 |
| -runRelease().then(() => { |
84 |
| - process.exit(0); |
85 |
| -}); |
| 1 | +# The Mongo Shell Build System <!-- omit in toc --> |
| 2 | + |
| 3 | +- [Releases](#releases) |
| 4 | + - [Publishing a new Release](#publishing-a-new-release) |
| 5 | + - [Branches and Tags](#branches-and-tags) |
| 6 | +- [Evergreen CI](#evergreen-ci) |
| 7 | + - [Evergreen Triggers](#evergreen-triggers) |
| 8 | + - [Evergreen Stages](#evergreen-stages) |
| 9 | + - [Tests](#tests) |
| 10 | + - [E2E Tests](#e2e-tests) |
| 11 | + - [Smoke Tests](#smoke-tests) |
| 12 | + - [Draft](#draft) |
| 13 | + - [Publish](#publish) |
| 14 | +- [Package Structure](#package-structure) |
| 15 | + |
| 16 | +## Releases |
| 17 | +New releases of the Mongo Shell project are created primarily on demand or when a bunch of worthy features or fixes is available. There is no fixed cycle for publishing new releases right now. |
| 18 | + |
| 19 | +### Publishing a new Release |
| 20 | +Execute the following steps to publish a new release: |
| 21 | + |
| 22 | +1. Ensure there is a Jira _Release_ ticket in the [`MONGOSH` project](https://jira.mongodb.org/projects/MONGOSH) for the new release and move it to _In Progress_. |
| 23 | +2. Verify that the Jira tickets you expect to be released are correctly mapped to the _Release_ ticket. Add any additional required documentation to the release ticket. |
| 24 | +3. Trigger the draft release by running: |
| 25 | + ``` |
| 26 | + npm run release draft |
| 27 | + ``` |
| 28 | + Follow the instructions and ensure that the new draft tag to be created matches the expected release version. |
| 29 | +4. Wait for Evergreen to finish the build and complete the draft stage.\ |
| 30 | + _Repeat step 3 if there are any additional changes that need to be part of the release._ |
| 31 | +5. Trigger the publication of the release by running: |
| 32 | + ``` |
| 33 | + npm run release publish |
| 34 | + ``` |
| 35 | + Follow the instructions and verify the inferred release version is correct. |
| 36 | +6. Wait for Evergreen to finish the publication stage. |
| 37 | +7. Close the Jira ticket for the release, post an update in the `#mongosh` Slack channel and ping the docs team. |
| 38 | + |
| 39 | + |
| 40 | +### Branches and Tags |
| 41 | +Typically, a release is always created from the main branch (currently `master`). The only exception are _patch releases_, i.e. when we need to fix an issue for an already published, already superseeded release. Patch releases are created from _release branches_ that match the following pattern: |
86 | 42 | ```
|
| 43 | +release/v[0-9]+\.[a-zA-Z0-9]+\.[a-zA-Z0-9]+ |
| 44 | +``` |
| 45 | +Possible values for a release branch are: |
| 46 | +* `release/v0.8.1` |
| 47 | +* `release/v0.8.x` |
| 48 | +* `release/v0.x.y` |
87 | 49 |
|
88 |
| -### API |
89 |
| -#### await release(command, config) |
90 |
| -Run a complete release of mongosh. This will bundle, create the binary and |
91 |
| -package a tarball for the current build variant. Running a release requires a |
92 |
| -config object which is usually obtained from evergreen. For current config, see |
93 |
| -[build.conf.js][build-url] |
| 50 | +See the following image for a general overview on how we handle these branches and the corresponding tags. |
94 | 51 |
|
95 |
| -__config:__ config object necessary for release. |
| 52 | + |
96 | 53 |
|
97 |
| -```js |
98 |
| -const release = require('@mongosh/build'); |
99 |
| -const configObject = {}; |
100 |
| -await release(command, config); |
101 |
| -``` |
| 54 | +We use two different types of tags for the automated release process: draft and release tags. A release tag has the form `v<major>.<minor>.<patch>`, e.g. `v0.8.0`. A draft tag is `v<major>.<minor>.<patch>-draft.<draft>`, e.g. `v0.8.0-draft.0`. |
102 | 55 |
|
103 |
| -If `config.dryRun` is set, this will only package a tarball and skip all later |
104 |
| -steps. |
105 |
| - |
106 |
| -#### await runCompile() |
107 |
| -Create a compiled down binary. Binary is created for the provided platform (e.g. |
108 |
| -windows will build `mongosh.exe`). Before we compile the binary, we bundle |
109 |
| -`execInput` into a single `.js` file. |
110 |
| - |
111 |
| -__input:__ path to build input. |
112 |
| -__execInput:__ path to compiled executive input. |
113 |
| -__outputDir:__ path to where the compiled binary will live. |
114 |
| -__platform:__ platform to run `runCompile` on. `linux`, `darwin`, and `win32` |
115 |
| -are accepted options. |
116 |
| -__analyticsConfig:__ path to analytics config for telemetry. |
117 |
| -__segmentKey:__ segment api key for telemetry. |
118 |
| - |
119 |
| -```js |
120 |
| -const compileexec = require('@mongosh/build').compileexec; |
121 |
| - |
122 |
| -const config = { |
123 |
| - input: 'path/to/input', |
124 |
| - execInput: 'path/to/exec/input', |
125 |
| - outputDir: 'path/to/output/directory', |
126 |
| - analyticsConfigFilePath: 'path/to/analytics/config', |
127 |
| - segmentKey: 'SEGMENT_API_KEY_23481k', |
128 |
| -} |
129 |
| -await runCompile( |
130 |
| - config.input, |
131 |
| - config.execInput, |
132 |
| - config.outputDir, |
133 |
| - os.platform(), |
134 |
| - config.analyticsConfigFilePath, |
135 |
| - config.segmentKey |
136 |
| -); |
137 |
| -``` |
| 56 | +Draft tags are used to trigger the automated release process. Every draft tag in the end leads to the generation of _potentially_ distributable packages with compiled binaries. |
| 57 | + |
| 58 | +Release tags are used to trigger the publication of a release and its corresponding distributable packages. A release tag must referenced the commit with the most recent draft tag for that release version (example: `v0.8.0` must reference the commit with the highest `v0.8.0-draft.x` tag). |
138 | 59 |
|
| 60 | +The automated release process for publication of a release will re-use the compiled binaries and packages that were created in the most recent draft tag. Thus, every release tag requires a prior draft tag to be present. The release automation process is handled by [Evergreen](#evergreen-ci). |
139 | 61 |
|
140 |
| -#### await createTarball(input, outputDir, buildVariant, version, rootDir) |
141 |
| -Creates a tarball for a given binary and build variant. Different build variants |
142 |
| -will create different tarballs - `.tgz`, `.zip`, or `.deb`. |
143 |
| - |
144 |
| -__input:__ path to binary file. |
145 |
| -__outputDir:__ path to where the compiled tarball will live. |
146 |
| -__buildVariant:__ build variant to create a tarball for. `macos`, `ubuntu`, `windows_ps , or `debian` are currently available. |
147 |
| -__version:__ version for the tarball. |
148 |
| -__rootDir:__ path to root project directory. |
149 |
| -```js |
150 |
| -const tarball = require('@mongosh/build').tarball; |
151 |
| - |
152 |
| -const executable = 'path/to/executable' |
153 |
| -const config = { |
154 |
| - outputDir: 'path/to/output/directory', |
155 |
| - distributionBuildVariant: 'windows_ps', |
156 |
| - version: '0.2.0', |
157 |
| - rootDir: 'path/to/root/directory', |
158 |
| -} |
159 |
| - |
160 |
| -const artifact = await createTarball( |
161 |
| - executable, |
162 |
| - config.outputDir, |
163 |
| - config.distributionBuildVariant, |
164 |
| - config.version, |
165 |
| - config.rootDir |
166 |
| -); |
167 |
| -``` |
| 62 | +## Evergreen CI |
| 63 | +The Mongo Shell project uses Evergreen for Continuous Integration and the release automation process described above. Follow [Evergreen Build][evergreen-url] to see the waterfall for the Mongo Shell project. |
| 64 | + |
| 65 | +For full details on the project's configuration see the Evergreen configuration file [`.evergreen.yml`](../../.evergreen.yml). |
| 66 | + |
| 67 | +### Evergreen Triggers |
| 68 | +Evergreen builds and _patches_ are triggered in multiple ways. The Mongo Shell project is setup to be triggered by: |
| 69 | + |
| 70 | +* New commits on the main branch (currently `master`, i.e. _waterfall builds_ |
| 71 | +* New Pull Requests against the main branch on GitHub (i.e. _patches_) |
| 72 | +* A new tag matching `v0.0.0-draft.0` is pushed on the main or a release branch (i.e. a draft build is triggered) |
| 73 | +* A new tag matching `v0.0.0` is pushed on the main or a release branch (i.e. a release is to be published) |
| 74 | + |
| 75 | +### Evergreen Stages |
| 76 | +The following image shows an overview on the different stages of the build in Evergreen. |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | +#### Tests |
| 81 | +The _Tests_ stage contains multiple tasks: |
| 82 | +* Checks that the code conforms to linting guidelines |
| 83 | +* Runs all unit tests in a matrix configuration (Node v12 and v14, server versions 4.0 / 4.2 / 4.4 / latest) |
| 84 | +* Runs additional verification tests (VS code integration and connectivity tests) |
| 85 | + |
| 86 | +#### Compile |
| 87 | +The _Compile_ stage produces an executable binary (leveraging [boxednode](https://github.com/mongodb-js/boxednode)) for every target platform and uploads it to the Evergreen S3 bucket for later user. |
| 88 | + |
| 89 | +#### Package |
| 90 | +The _Package_ stage depends on both stages _Tests_ and _Compile_ to complete successfully. It will then download the binary executable, package it into a distributable archive (e.g. a `.deb` package or a `.zip` file) and re-upload that to Evergreen S3 for every target platform. |
| 91 | + |
| 92 | +#### E2E Tests |
| 93 | +The _E2E Tests_ stage depends on the _Package_ stage to complete successfully. It will download the binary executable of the _Compile_ stage from Evergreen S3 and run JavaScript-defined E2E tests with it. |
| 94 | + |
| 95 | +#### Smoke Tests |
| 96 | +The _Smoke Tests_ stage depends on the _Package_ stage to complete successfully. It will download the _packaged_ distributable and run it via Docker or SSH on different target operating systems to verify that the distributable works as expected. |
| 97 | + |
| 98 | +#### Draft |
| 99 | +The _Draft_ stage depends on both stages _E2E Tests_ and _Smoke Tests_ to complete successfully. _Draft_ will download all distributable packages created in the _Package_ stage and re-upload them to: |
| 100 | + |
| 101 | +1. MongoDB Download Center: uploads to the corresponding S3 bucket without publishing the Download Center configuration. |
| 102 | +2. GitHub Release: creates a new draft release if there is none for the release version yet and either uploads or removes and re-uploads the distributable packages. It will also generate a changelog and add it to the draft release. |
| 103 | + |
| 104 | +#### Publish |
| 105 | +The _Publish_ stage is independent from all other stages. As mentioned at the beginning when a release tag is pushed to the repository it will directly trigger the _Publish_ stage. It will do the following things: |
| 106 | + |
| 107 | +1. Use [`curator`](https://github.com/mongodb/curator) to transfer the distributable packages from Download Center to the MongoDB PPAs. |
| 108 | +2. Upload the full configuration to Download Center so the release is available there. |
| 109 | +3. Promote the GitHub release created in _Draft_ to a published release. |
| 110 | +4. Publishes the npm packages. |
| 111 | +5. Creates a new PR for the [MongoDB Homebrew Tap](https://github.com/mongodb/homebrew-brew) and automatically merges it. |
| 112 | + |
| 113 | + |
| 114 | +## Package Structure |
| 115 | + |
| 116 | +The package has two major purposes: |
| 117 | +* Custom build commands to handle the stages outlined above |
| 118 | +* Provide easy helpers to trigger the release process |
168 | 119 |
|
169 |
| -[evergreen-url]: https://evergreen.mongodb.com/waterfall/mongosh |
170 |
| -[config-url]: https://github.com/mongodb-js/mongosh/blob/393b505c179b64fbb72e0481c63f1723a3c56f06/config/build.conf.js |
171 |
| -[build-img]: ./build.png |
| 120 | +See [index.ts](./src/index.ts) for the main entry point on the different commands. |
0 commit comments