-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathcreateNextBranch.ts
More file actions
96 lines (89 loc) · 3.89 KB
/
createNextBranch.ts
File metadata and controls
96 lines (89 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import Listr from "listr";
import { increaseFromLocalVersion } from "../utils/versions/increaseFromLocalVersion";
import { getManifestPath } from "../utils/manifest";
import { getComposePath } from "../utils/compose";
import { CliGlobalOptions, ListrContextBuildAndPublish } from "../types";
import { shell } from "../utils/shell";
import { Github } from "../providers/github/Github";
import { defaultDir } from "../params";
/**
* Create (or edit) a Github release, then upload all assets
*/
export function createNextBranch({
dir = defaultDir,
verbose,
silent
}: CliGlobalOptions): Listr<ListrContextBuildAndPublish> {
// Gather repo data, repoSlug = "dappnode/DNP_ADMIN"
const github = Github.fromDir(dir);
return new Listr<ListrContextBuildAndPublish>(
[
// Create the next version branch and advance versions
// - Run `dappnodesdk increase patch` to compute next version
// - Run `git checkout -b v${FUTURE_VERSION}`
// - git add dappnode_package.json docker-compose.yml
// - git commit -m "Advance manifest and docker-compose versions to new version: $FUTURE_VERSION"
// - git push origin $BRANCH_NAME
{
title: "Create next version branch",
task: async (ctx, task) => {
try {
// Openning next version branches in dev branches is confusing and never usefull
// Actual releases are always done in master.
const currenBranch = await shell(`git rev-parse --abbrev-ref HEAD`);
if (currenBranch !== "master") {
task.skip(`Next version branches are only created from master`);
return;
}
const manifestPath = getManifestPath();
const composePath = getComposePath();
const nextVersion = await increaseFromLocalVersion({
type: "patch",
dir
});
const branch = `v${nextVersion}`;
// Check if branch exists in Github
task.output = "Checking next version branch...";
const remoteBranchInfo = await shell(
`git ls-remote --heads origin ${branch}`
);
if (remoteBranchInfo) {
task.skip(`Next version branch ${branch} already exists`);
return;
}
// Make sure git is configured in this environment
// Otherwise it will fail when run in a CI environemnt
// `git config user.email` returns exit code 1 if not configured
if (
process.env.CI &&
!(await shell(`git config user.email`).catch(() => false))
) {
await shell(`git config user.email next-branch@bot`);
await shell(`git config user.name next-branch`);
}
// Using the git CLI directly since you can't create and push
// a commit that has two files (at least in an easy way)
// CI runs should be authorized to use the CLI directly
// while running locally should have the origin configured and work OK
await shell(`git checkout -b ${branch}`);
await shell(`git add ${manifestPath} ${composePath}`);
await shell(`git commit -m "Bump to new version: ${nextVersion}"`);
task.output = "Pushing bump versions commit...";
await shell(`git push --set-upstream origin ${branch}`);
// Open a PR from next branch to master
task.output = "Openning a PR to master...";
await github.openPR({
from: branch,
to: "master",
title: `${branch} Release`
});
} catch (e) {
// Non-essential step, don't stop release for a failure on this task
console.log(`Error creating next version branch:\n${e.stack}`);
}
}
}
],
{ renderer: verbose ? "verbose" : silent ? "silent" : "default" }
);
}