Skip to content

Commit 6d35121

Browse files
committed
Some cleanup new release script
1 parent 1a96e43 commit 6d35121

File tree

8 files changed

+149
-459
lines changed

8 files changed

+149
-459
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
staging/*

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"parser": "typescript",
3+
"trailingComma": "es5",
4+
"singleQuote": true,
5+
"bracketSpacing": false,
6+
"jsxBracketSameLine": true,
7+
"tabWidth": 2
8+
}

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"editor.formatOnSave": true
3+
}
File renamed without changes.

package.json

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,27 @@
77
"license": "MIT",
88
"private": true,
99
"devDependencies": {
10-
"@grupoboticario/news-fragments": "^1.7.0",
10+
"@octokit/rest": "^18.0.6",
1111
"release-it": "^14.1.0"
1212
},
1313
"scripts": {
1414
"release": "release-it"
1515
},
1616
"release-it": {
17+
"git": {
18+
"requireCleanWorkingDir": false
19+
},
1720
"github": {
18-
"release": true
21+
"release": true,
22+
"releaseNotes": "cat staging/RELEASE.md"
1923
},
2024
"npm": {
2125
"publish": false,
2226
"release": false
2327
},
2428
"plugins": {
25-
"@grupoboticario/news-fragments": {
26-
"fragmentsTypes": [
27-
{
28-
"title": "Features",
29-
"extension": "feature"
30-
},
31-
{
32-
"title": "Bugfixes",
33-
"extension": "bugfix"
34-
}
35-
]
29+
"./plugins/release.js": {
30+
"legacy": false
3631
}
3732
}
3833
}

plugins/release.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
const {Plugin} = require('release-it');
2+
const {Octokit} = require('@octokit/rest');
3+
const pkg = require('../package.json');
4+
const fs = require('fs');
5+
6+
class WandbPlugin extends Plugin {
7+
async init() {
8+
this.octokit = new Octokit({
9+
baseUrl: 'https://api.github.com',
10+
auth: process.env['GITHUB_TOKEN'],
11+
userAgent: `local/${pkg.version}`,
12+
log: null,
13+
request: {
14+
timeout: 10000,
15+
},
16+
});
17+
this.registerPrompts({
18+
release_notes: {
19+
type: 'editor',
20+
name: 'release_notes',
21+
default: this.defaultNotes.bind(this),
22+
message: () => "Let's edit the release notes.",
23+
},
24+
});
25+
}
26+
27+
async defaultNotes() {
28+
if (this.options.legacy) {
29+
// TODO: version
30+
const res = await this.octokit.repos.getReleaseByTag({
31+
owner: 'wandb',
32+
repo: 'core',
33+
tag: 'local/v0.9.4',
34+
});
35+
this.setContext({date: new Date(res.data.published_at)});
36+
return res.data.body;
37+
} else {
38+
this.setContext({date: new Date()});
39+
// TODO: latestVersion
40+
let res = await this.octokit.repos.getReleaseByTag({
41+
owner: 'wandb',
42+
repo: 'core',
43+
tag: 'local/v0.9.30',
44+
});
45+
const lastReleaseSHA = res.data.target_commitish;
46+
const publishedAt = res.data.published_at;
47+
console.log('Grabbing all commits from since', publishedAt, lastReleaseSHA);
48+
res = await this.octokit.repos.listCommits({
49+
owner: 'wandb',
50+
repo: 'core',
51+
per_page: 100,
52+
since: publishedAt,
53+
});
54+
//new Date(commit.author.date) > new Date(publishedAt)
55+
if(res.data.length > 100) {
56+
console.warn("There have been more than 100 commits since the last release!")
57+
}
58+
const notes = res.data
59+
.map((commit) => `* ${commit.commit.message.split('\n')[0]}`)
60+
.join('\n');
61+
return notes;
62+
}
63+
}
64+
65+
bump(version) {
66+
this.setContext({version});
67+
}
68+
69+
getChangelog(latestVersion) {
70+
this.setContext({latestVersion});
71+
}
72+
73+
saveChangelogToFile(filePath, renderedTemplate) {
74+
const fileDescriptor = fs.openSync(filePath, 'a+');
75+
76+
const oldData = fs.readFileSync(filePath);
77+
const newData = new Buffer.from(renderedTemplate);
78+
79+
fs.writeSync(fileDescriptor, newData, 0, newData.length, 0);
80+
fs.writeSync(fileDescriptor, oldData, 0, oldData.length, newData.length);
81+
82+
fs.closeSync(fileDescriptor);
83+
}
84+
85+
saveReleaseNotesToFile(filePath, notes) {
86+
const fileDescriptor = fs.openSync(filePath, 'a+');
87+
const newData = new Buffer.from(notes);
88+
fs.writeSync(fileDescriptor, newData, 0, newData.length, 0);
89+
fs.closeSync(fileDescriptor);
90+
}
91+
92+
getFormattedDate() {
93+
const date = this.getContext('date');
94+
return date.toLocaleDateString('en-us', {
95+
month: 'long',
96+
day: 'numeric',
97+
year: 'numeric',
98+
});
99+
}
100+
101+
async beforeRelease() {
102+
await this.step({
103+
enabled: true,
104+
task: (notes) => {
105+
this.setContext({notes});
106+
console.log('CTX', this.getContext());
107+
this.saveReleaseNotesToFile('staging/RELEASE.md', notes);
108+
this.saveChangelogToFile(
109+
'CHANGELOG.md',
110+
`# wandb/local:${this.getContext(
111+
'version'
112+
)} - ${this.getFormattedDate()}\n\n${notes}\n\n`
113+
);
114+
},
115+
label: 'Creating notes',
116+
prompt: 'release_notes',
117+
});
118+
}
119+
}
120+
121+
module.exports = WandbPlugin;

staging/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)