Skip to content

Commit c2abd89

Browse files
chore(NODE-5328): add dry-run nightly release automation (mongodb#3698)
Co-authored-by: Bailey Pearson <[email protected]>
1 parent ed5e27b commit c2abd89

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

.github/scripts/nightly.mjs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// @ts-check
2+
import * as url from 'node:url';
3+
import * as fs from 'node:fs/promises';
4+
import * as path from 'node:path';
5+
import * as process from 'node:process';
6+
import * as child_process from 'node:child_process';
7+
import * as util from 'node:util';
8+
const exec = util.promisify(child_process.exec);
9+
10+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
11+
const pkgFilePath = path.join(__dirname, '..', '..', 'package.json');
12+
13+
process.env.TZ = 'Etc/UTC';
14+
15+
/**
16+
* FORMAT : M.M.P-dev+YYYYMMDD.sha.##########
17+
* EXAMPLE: 5.6.0-dev+20230601.sha.0853c6957c
18+
*/
19+
class NightlyVersion {
20+
/** @param {string} version */
21+
constructor(version) {
22+
/** @type {string} */
23+
this.version = version;
24+
const [, meta] = this.version.split('+');
25+
const [dateString, commit] = meta.split('.sha.');
26+
/** @type {string} */
27+
this.commit = commit;
28+
/** @type {string} */
29+
this.dateString = dateString;
30+
}
31+
static async currentNightlyVersion() {
32+
const { stdout } = await exec('npm show --json mongodb', { encoding: 'utf8' });
33+
/** @type {{'dist-tags': {nightly?: string} }} */
34+
const showInfo = JSON.parse(stdout);
35+
const version = showInfo?.['dist-tags']?.nightly ?? '0.0.0-dev+YYYYMMDD.sha.##########';
36+
return new NightlyVersion(version);
37+
}
38+
static async currentCommit() {
39+
const { stdout } = await exec('git rev-parse --short HEAD', { encoding: 'utf8' });
40+
return stdout.trim();
41+
}
42+
static async generateNightlyVersion() {
43+
console.log('Generating new nightly version');
44+
const currentCommit = await NightlyVersion.currentCommit();
45+
const today = new Date();
46+
const year = `${today.getFullYear()}`;
47+
const month = `${today.getMonth()}`.padStart(2, '0');
48+
const day = `${today.getUTCDate()}`.padStart(2, '0');
49+
const yyyymmdd = `${year}${month}${day}`;
50+
51+
const pkg = JSON.parse(await fs.readFile(pkgFilePath, { encoding: 'utf8' }));
52+
53+
console.log('package.json version is:', pkg.version);
54+
pkg.version = `${pkg.version}-dev+${yyyymmdd}.sha.${currentCommit}`;
55+
console.log('package.json version updated to:', pkg.version);
56+
57+
await fs.writeFile(pkgFilePath, JSON.stringify(pkg, undefined, 2), { encoding: 'utf8' });
58+
}
59+
}
60+
61+
const currentPublishedNightly = await NightlyVersion.currentNightlyVersion();
62+
console.log('current published nightly:', currentPublishedNightly?.version);
63+
const currentCommit = await NightlyVersion.currentCommit();
64+
console.log('current commit sha:', currentCommit);
65+
66+
if (currentPublishedNightly.commit === currentCommit) {
67+
console.log('Published nightly is up to date');
68+
process.exit(1);
69+
}
70+
await NightlyVersion.generateNightlyVersion();
71+
process.exit(0);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
on:
2+
schedule:
3+
# Timezone is UTC
4+
# https://crontab.guru/#0_20_*_*_1-5
5+
# At 20:00 on every day-of-week from Monday through Friday.
6+
- cron: '0 20 * * 1-5'
7+
8+
name: release-nightly
9+
10+
jobs:
11+
release-nightly:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
id-token: write
15+
steps:
16+
- uses: actions/checkout@v3
17+
with:
18+
ref: main
19+
- uses: actions/setup-node@v3
20+
with:
21+
node-version: 'lts/*'
22+
registry-url: 'https://registry.npmjs.org'
23+
- run: npm install -g npm
24+
- run: npm clean-install
25+
- run: npm run build:nightly
26+
continue-on-error: true
27+
- if: ${{ success() }}
28+
run: npm publish --dry-run --provenance --tag=nightly
29+
env:
30+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,18 @@ try {
283283
}
284284
```
285285

286+
## Nightly releases
287+
288+
If you need to test with a change from the latest `main` branch our `mongodb` npm package has nightly versions released under the `nightly` tag.
289+
290+
```sh
291+
npm install mongodb@nightly
292+
```
293+
294+
Nightly versions are published regardless of testing outcome.
295+
This means there could be sematic breakages or partially implemented features.
296+
The nightly build is not suitable for production use.
297+
286298
## Next Steps
287299

288300
- [MongoDB Documentation](https://www.mongodb.com/docs/manual/)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
"build:dts": "npm run build:ts && api-extractor run && node etc/clean_definition_files.cjs",
111111
"build:docs": "./etc/docs/build.ts",
112112
"build:typedoc": "typedoc",
113+
"build:nightly": "node ./.github/scripts/nightly.mjs",
113114
"check:bench": "node test/benchmarks/driverBench",
114115
"check:coverage": "nyc npm run test:all",
115116
"check:integration-coverage": "nyc npm run check:test",

0 commit comments

Comments
 (0)