Skip to content

Commit 49417ff

Browse files
authored
Tighten up git typings, simplify version regex (#13)
* Tighten up git typings, simplify version regex * Update ci-release.ts
1 parent ed2aed5 commit 49417ff

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

ci-release.ts

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,18 @@
66

77
import { stringCamelCase } from 'https://deno.land/x/polkadot@0.0.0-9/util/mod.ts';
88

9+
// tighter specification for git arguments
10+
type GitArgs =
11+
['add', '--all', '.'] |
12+
['checkout', 'master'] |
13+
['commit', '--no-status', '--quiet', '-m', string] |
14+
['config', 'merge.ours.driver' | 'push.default' | `user.${'email' | 'name'}`, string] |
15+
['push', string] |
16+
['push', string, '--tags'] |
17+
['tag', string];
18+
919
// regex for matching `deno.land/x/polkadot[@<version>]/
10-
const reVer = /deno\.land\/x\/polkadot(@\d\d?\d?\.\d\d?\d?\.\d\d?\d?-?\d?\d?\d?)?\//g;
20+
const RE_PKG = /deno\.land\/x\/polkadot(@\d*\.\d*\.\d*(-\d*)?)?\//g;
1121

1222
// execute a command
1323
async function exec(...cmd: string[]): Promise<void> {
@@ -22,10 +32,15 @@ async function exec(...cmd: string[]): Promise<void> {
2232
};
2333
}
2434

35+
// shortcut for exec('git', ...string[])
36+
function git (...args: GitArgs): Promise<void> {
37+
return exec('git', ...args);
38+
}
39+
2540
// retrieve the current version from CHANGELOG.md
2641
async function getVersion(): Promise<string> {
2742
const contents = await Deno.readTextFile('CHANGELOG.md');
28-
const vermatch = contents.match(/# CHANGELOG\n\n## (\d\d?.\d\d?.\d\d?-?\d?\d?) /);
43+
const vermatch = contents.match(/# CHANGELOG\n\n## (\d*.\d*.\d*(-\d*)?) /);
2944

3045
if (!vermatch || !vermatch[1]) {
3146
throw new Error('FATAL: Unable to extract expected version from CHANGELOG.md');
@@ -43,8 +58,8 @@ async function setVersion(version: string, dir: string): Promise<void> {
4358
const path = `${dir}/${entry.name}`;
4459
const contents = await Deno.readTextFile(path);
4560

46-
if (reVer.test(contents)) {
47-
await Deno.writeTextFile(path, contents.replace(reVer, `deno.land/x/polkadot@${version}/`));
61+
if (RE_PKG.test(contents)) {
62+
await Deno.writeTextFile(path, contents.replace(RE_PKG, `deno.land/x/polkadot@${version}/`));
4863
}
4964
}
5065
}
@@ -55,22 +70,22 @@ async function gitSetup(): Promise<void> {
5570
const USER = 'github-actions[bot]';
5671
const MAIL = '41898282+github-actions[bot]@users.noreply.github.com';
5772

58-
await exec('git', 'config', 'user.name', USER);
59-
await exec('git', 'config', 'user.email', MAIL);
60-
await exec('git', 'config', 'push.default', 'simple');
61-
await exec('git', 'config', 'merge.ours.driver', 'true');
62-
await exec('git', 'checkout', 'master');
73+
await git('config', 'user.name', USER);
74+
await git('config', 'user.email', MAIL);
75+
await git('config', 'push.default', 'simple');
76+
await git('config', 'merge.ours.driver', 'true');
77+
await git('checkout', 'master');
6378
}
6479

6580
// commit and push the changes to git
6681
async function gitPush(version: string): Promise<void> {
6782
const REPO = `https://${Deno.env.get('GH_PAT')}@github.com/${Deno.env.get('GITHUB_REPOSITORY')}.git`;
6883

69-
await exec('git', 'add', '--all', '.');
70-
await exec('git', 'commit', '--no-status', '--quiet', '-m', `[CI Skip] deno.land/x/polkadot@${version}`);
71-
await exec('git', 'push', REPO);
72-
await exec('git', 'tag', version);
73-
await exec('git', 'push', REPO, '--tags');
84+
await git('add', '--all', '.');
85+
await git('commit', '--no-status', '--quiet', '-m', `[CI Skip] deno.land/x/polkadot@${version}`);
86+
await git('push', REPO);
87+
await git('tag', version);
88+
await git('push', REPO, '--tags');
7489
}
7590

7691
// creates a new mod.ts file with all the available imports

0 commit comments

Comments
 (0)