Skip to content

Commit e4a1a91

Browse files
authored
ci: add release script (#211)
1 parent f985b9c commit e4a1a91

File tree

7 files changed

+756
-0
lines changed

7 files changed

+756
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea
22
.vscode
3+
node_modules

CHANGELOG.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Changelog
2+
3+
## v1.0.0-beta.3 (2019-10-01)
4+
5+
### Features
6+
7+
* add interface body getter to std err ([#192](https://github.com/scaleway/scaleway-sdk-go/pull/192))
8+
* add support for out of stock error ([#190](https://github.com/scaleway/scaleway-sdk-go/pull/190))
9+
* use uint32 for page count ([#193](https://github.com/scaleway/scaleway-sdk-go/pull/193))
10+
* add raw body to standard errors ([#191](https://github.com/scaleway/scaleway-sdk-go/pull/191))
11+
* update generated apis ([#188](https://github.com/scaleway/scaleway-sdk-go/pull/188))
12+
13+
### Fixes
14+
15+
* e2e tests project ([#195](https://github.com/scaleway/scaleway-sdk-go/pull/195))
16+
* **instance**: allow image to be empty in CreateServer ([#189](https://github.com/scaleway/scaleway-sdk-go/pull/189))
17+
18+
19+
## v1.0.0-beta.2 (2019-09-16)
20+
21+
### Features
22+
23+
* test standard errors ([#183](https://github.com/scaleway/scaleway-sdk-go/pull/183))
24+
* update generated apis ([#182](https://github.com/scaleway/scaleway-sdk-go/pull/182))
25+
* standard error structures ([#177](https://github.com/scaleway/scaleway-sdk-go/pull/177))
26+
27+
### Fixes
28+
29+
* attach volume key choice ([#184](https://github.com/scaleway/scaleway-sdk-go/pull/184))
30+
* add user agent to e2e tests ([#181](https://github.com/scaleway/scaleway-sdk-go/pull/181))
31+
* update version ([#180](https://github.com/scaleway/scaleway-sdk-go/pull/180))
32+
* UpdateSecurityGroupRule can now remove DestPortFrom and DestPortTo ([#179](https://github.com/scaleway/scaleway-sdk-go/pull/179))
33+

scripts/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Scaleway GO SDK - Scripts
2+
3+
This directory contains useful scripts to work on scaleway-go-sdk.
4+
5+
### check_for_tokens.sh \*\*
6+
7+
Checks that no token are present in cassette file
8+
9+
```
10+
Usage: ./script/check_for_tokens.sh
11+
```
12+
13+
### release.sh \*\*
14+
15+
This script will trigger the release process.
16+
For more information on the release process you can refer to ./release/release.js file
17+
18+
```
19+
Usage: ./script/release.sh
20+
```

scripts/release.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
cd scripts/release || (echo "Please run this script from repo root" && exit 1)
4+
5+
yarn install --frozen-lock-file
6+
yarn run release

scripts/release/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "scripts",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "Apache-2.0",
6+
"dependencies": {
7+
"colors": "^1.4.0",
8+
"get-stream": "^5.1.0",
9+
"git-raw-commits": "^2.0.2",
10+
"semver": "^6.3.0"
11+
},
12+
"scripts": {
13+
"release": "node release.js"
14+
}
15+
}

scripts/release/release.js

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
/******************************************************************************
2+
* Scaleway GO SDK release script.
3+
*
4+
* This script will trigger a release process for the scaleway Go SDK.
5+
*
6+
* The script will proceed as follow:
7+
* - Create a new remote `scaleway-release` that point to main repo
8+
* - Prompt the new version number
9+
* - Create release commit
10+
* - Generate a changelog
11+
* - Update version in scw/version.go
12+
* - Ask to review changes
13+
* - Ask to merge this changes to master via PR
14+
* - Create a github release
15+
* - Ask to create a github release
16+
* - Create a post release commit
17+
* - Update scw/version.go to add +dev at the end
18+
* - Ask to merge this changes to master via PR
19+
* - Delete temporary remote `scaleway-release` that was created earlier
20+
******************************************************************************/
21+
22+
const { spawnSync } = require("child_process"),
23+
readline = require("readline"),
24+
fs = require("fs")
25+
;
26+
27+
const gitRawCommits = require("git-raw-commits"),
28+
semver = require("semver"),
29+
getStream = require("get-stream"),
30+
_ = require("colors")
31+
;
32+
33+
const _typeReg = /(?<type>[a-zA-Z]+)/;
34+
const _scopeReg = /(\((?<scope>.*)\))?/;
35+
const _messageReg = /(?<message>[^(]*)/;
36+
const _mrReg = /(\(#(?<mr>[0-9]+)\))?/;
37+
const COMMIT_REGEX = new RegExp(`${_typeReg.source}${_scopeReg.source}: *${_messageReg.source} *${_mrReg.source}`);
38+
const CHANGELOG_PATH = "../../CHANGELOG.md";
39+
const GO_VERSION_PATH = "../../scw/version.go";
40+
const TMP_BRANCH = "new-release";
41+
const TMP_REMOTE = "scaleway-release";
42+
const REPO_URL = "[email protected]:scaleway/scaleway-sdk-go.git";
43+
44+
async function main() {
45+
46+
//
47+
// Initialization
48+
//
49+
console.log("Adding temporary remote on local repo".blue);
50+
git( "remote", "add", TMP_REMOTE, REPO_URL);
51+
console.log(` Successfully created ${TMP_REMOTE} remote`.green);
52+
53+
console.log("Make sure we are working on an up to date master".blue);
54+
git( "fetch", TMP_REMOTE);
55+
git( "checkout", `${TMP_REMOTE}/master`);
56+
console.log(` Successfully created ${TMP_REMOTE} remote`.green);
57+
58+
console.log("Trying to find last release tag".blue);
59+
const lastSemverTag = git("tag")
60+
.trim()
61+
.split("\n")
62+
.filter(semver.valid)
63+
.sort((a, b) => semver.rcompare(semver.clean(a), semver.clean(b)))[0];
64+
console.log(` Last found release tag was ${lastSemverTag}`.green);
65+
66+
console.log("Listing commit since last release".blue);
67+
const commits = (await getStream.array(gitRawCommits({ from: lastSemverTag, format: "%s" }))).map(c => c.toString().trim());
68+
commits.forEach(c => console.log(` ${c}`.grey));
69+
console.log(` We found ${commits.length} commits since last release`.green);
70+
71+
const newVersion = semver.clean(await prompt("Enter new version: ".magenta));
72+
if (!newVersion) {
73+
throw new Error(`invalid version`);
74+
}
75+
76+
//
77+
// Creating release commit
78+
//
79+
80+
console.log(`Updating ${CHANGELOG_PATH} and ${GO_VERSION_PATH}`.blue);
81+
// Generate changelog lines by section
82+
const changelogLines = { feat: [], fix: [] };
83+
commits.forEach(commit => {
84+
const result = COMMIT_REGEX.exec(commit);
85+
if (!result || !(result.groups.type in changelogLines)) {
86+
console.warn(`WARNING: Ignoring commit ${commit}`.yellow);
87+
return;
88+
}
89+
const stdCommit = result.groups;
90+
91+
let line = [`*`, stdCommit.scope ? `**${stdCommit.scope}**:` : "", stdCommit.message, stdCommit.mr ? `([#${stdCommit.mr}](https://github.com/scaleway/scaleway-sdk-go/pull/${stdCommit.mr}))` : ""]
92+
.map(s => s.trim())
93+
.filter(v => v)
94+
.join(" ");
95+
changelogLines[stdCommit.type].push(line);
96+
});
97+
98+
const changelogHeader = `## v${newVersion} (${new Date().toISOString().substring(0, 10)})`;
99+
const changelogSections = [];
100+
if (changelogLines.feat) {
101+
changelogSections.push("### Features\n\n" + changelogLines.feat.join("\n"));
102+
}
103+
if (changelogLines.fix) {
104+
changelogSections.push("### Fixes\n\n" + changelogLines.fix.join("\n"));
105+
}
106+
const changelogBody = changelogSections.join("\n\n");
107+
const changelog = `${changelogHeader}\n\n${changelogBody}`;
108+
109+
replaceInFile(CHANGELOG_PATH, "# Changelog", "# Changelog\n\n" + changelog + "\n");
110+
replaceInFile(GO_VERSION_PATH, /const version[^\n]*\n/, `const version = "v${newVersion}"\n`);
111+
console.log(` Update success`.green);
112+
113+
await prompt(`Please review ${CHANGELOG_PATH} and ${GO_VERSION_PATH}. When everything is fine hit enter to continue ...`.magenta);
114+
115+
console.log(`Creating release commit`.blue);
116+
git("checkout", "-b", TMP_BRANCH);
117+
git("add", CHANGELOG_PATH, GO_VERSION_PATH);
118+
git("commit", "-m", `chore: release ${newVersion}`);
119+
git("push", "-f", "--set-upstream", TMP_REMOTE, TMP_BRANCH);
120+
121+
await prompt(`Please create an PR here: https://github.com/scaleway/scaleway-sdk-go/pull/new/new-release . Hit enter when its merged .....`.magenta);
122+
123+
console.log("Time to create a github release with the following info\n".blue);
124+
console.log(`Title: v${newVersion}\n\n`.gray);
125+
console.log(`${changelogBody}\n\n`.gray);
126+
await prompt(`You should create a new github release here: https://github.com/scaleway/scaleway-sdk-go/releases/new/ . Hit enter when the new release is created .....`.magenta);
127+
128+
//
129+
// Creating post release commit
130+
//
131+
console.log("Make sure we pull the latest commit from master".blue);
132+
git("fetch", TMP_REMOTE);
133+
git("checkout", `${TMP_REMOTE}/master`);
134+
console.log(" Successfully checkout upstream/master".green);
135+
136+
console.log(`Creating post release commit`.blue);
137+
git("branch", "-D", TMP_BRANCH);
138+
git("checkout", "-b", TMP_BRANCH);
139+
replaceInFile(GO_VERSION_PATH, /const version[^\n]*\n/, `const version = "v${newVersion}+dev"\n`);
140+
git("add", GO_VERSION_PATH);
141+
git("commit", "-m", "chore: post release commit");
142+
git("push", "-f", "--set-upstream", TMP_REMOTE, TMP_BRANCH);
143+
git("checkout", "master");
144+
git("branch", "-D", TMP_BRANCH);
145+
await prompt(`Please create an PR here: https://github.com/scaleway/scaleway-sdk-go/pull/new/new-release . Hit enter when its merged .....`.magenta);
146+
147+
console.log("Make sure we pull the latest commit from master".blue);
148+
git("pull", TMP_REMOTE, "master");
149+
console.log(" Successfully pull master".green);
150+
151+
console.log("Remove temporary remote".blue);
152+
git("remote", "remove", TMP_REMOTE);
153+
console.log(" Successfully remove temporary remote".green);
154+
155+
console.log(`🚀 Release Success `.green);
156+
}
157+
158+
function git(...args) {
159+
console.log(` git ${args.join(" ")}`.grey);
160+
const { stdout, status, stderr } = spawnSync("git", args, { encoding: "utf8" });
161+
if (status !== 0) {
162+
throw new Error(`return status ${status}\n${stderr}\n`);
163+
}
164+
return stdout;
165+
}
166+
167+
function replaceInFile(path, oldStr, newStr) {
168+
console.log(` Editing ${path}`.grey);
169+
const content = fs.readFileSync(path, { encoding: "utf8" }).replace(oldStr, newStr);
170+
fs.writeFileSync(path, content);
171+
}
172+
173+
function prompt(prompt) {
174+
const rl = readline.createInterface({
175+
input: process.stdin,
176+
output: process.stdout
177+
});
178+
return new Promise(resolve => {
179+
rl.question(prompt, answer => {
180+
resolve(answer);
181+
rl.close();
182+
});
183+
});
184+
}
185+
186+
main().catch(console.error);

0 commit comments

Comments
 (0)