@cmflow/cli 1.1.0 → 1.1.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +5 -0
- package/.prettierrc +10 -0
- package/README.md +106 -32
- package/bin/cm-changelog.js +20 -12
- package/bin/cm-clean.js +4 -7
- package/bin/cm-config.js +8 -8
- package/bin/cm-deploy.js +4 -8
- package/bin/cm-fetch.js +7 -7
- package/bin/cm-finish.js +9 -9
- package/bin/cm-merge.js +7 -7
- package/bin/cm-publish.js +10 -10
- package/bin/cm-push.js +10 -10
- package/bin/cm-rebase.js +10 -10
- package/bin/cm-republish.js +7 -7
- package/bin/cm-start.js +10 -10
- package/bin/cm.js +20 -20
- package/bin/cmrelease.js +2 -2
- package/eslint.config.mjs +67 -0
- package/package.json +27 -21
- package/release.config.mjs +49 -19
- package/src/commands/changelog.js +23 -23
- package/src/commands/clean.js +13 -13
- package/src/commands/config.js +8 -8
- package/src/commands/deploy.js +15 -20
- package/src/commands/fetch.js +7 -10
- package/src/commands/finish.js +18 -19
- package/src/commands/index.js +10 -11
- package/src/commands/merge.js +30 -14
- package/src/commands/prompts/branches.js +20 -20
- package/src/commands/push.js +11 -14
- package/src/commands/rebase.js +17 -19
- package/src/commands/release.js +10 -11
- package/src/commands/republish.js +11 -14
- package/src/commands/start.js +52 -48
- package/src/commands/tasks/merge-branch.js +41 -37
- package/src/commands/tasks/push-branch.js +5 -11
- package/src/commands/tasks/rebase-all-branches.js +19 -24
- package/src/commands/tasks/refresh-repository.js +26 -24
- package/src/commands/tasks/run-test.js +11 -17
- package/src/commands/tasks/update-branch.js +33 -30
- package/src/commands/tasks/update-dependencies.js +38 -32
- package/src/commands/utils/check-install.js +16 -15
- package/src/common/cli/cli.js +55 -57
- package/src/common/cli/docker.js +31 -28
- package/src/common/cli/docker.test.js +94 -96
- package/src/common/cli/git.js +59 -68
- package/src/common/cli/git.test.js +187 -189
- package/src/common/cli/lerna.js +12 -12
- package/src/common/cli/lerna.test.js +38 -40
- package/src/common/cli/npm.js +17 -17
- package/src/common/cli/npm.test.js +38 -40
- package/src/common/cli/yarn.js +17 -17
- package/src/common/cli/yarn.test.js +40 -40
- package/src/common/configure-git-workspace.js +11 -17
- package/src/common/get-config.js +63 -119
- package/src/common/get-package-json.js +4 -4
- package/src/common/get-release-config.js +4 -5
- package/src/common/index.js +10 -10
- package/src/common/run-command.js +26 -28
- package/src/common/run-command.test.js +35 -39
- package/src/index.js +10 -1
- package/src/semantic/core/analyze-commits.js +17 -0
- package/src/semantic/core/fail.js +29 -0
- package/src/semantic/core/generate-notes.js +11 -0
- package/src/semantic/core/prepare/bump-version.js +38 -0
- package/src/semantic/core/prepare/post.js +38 -0
- package/src/semantic/core/prepare/run.js +22 -0
- package/src/semantic/core/publish.js +9 -0
- package/src/semantic/core/success.js +37 -0
- package/src/semantic/core/verify-conditions.js +32 -0
- package/src/semantic/core/verify-release.js +9 -0
- package/src/semantic/define-config.js +68 -0
- package/src/semantic/docker/publish.js +5 -0
- package/src/semantic/docker/success.js +9 -0
- package/src/semantic/utils/bump-packages-version.js +52 -0
- package/src/semantic/utils/bump-packages-version.test.js +75 -0
- package/src/semantic/utils/calculate-snapshot-version.js +15 -0
- package/src/semantic/utils/calculate-snapshot-version.test.js +67 -0
- package/src/semantic/utils/display-package-info.js +11 -0
- package/src/semantic/utils/display-release-info.js +12 -0
- package/src/semantic/utils/docker-clean-tags.js +51 -0
- package/src/semantic/utils/docker-clean-tags.test.js +61 -0
- package/src/semantic/utils/docker-publish.js +23 -0
- package/src/semantic/utils/docker-publish.test.js +44 -0
- package/src/semantic/utils/log-section.js +5 -0
- package/src/semantic/utils/release-rules.js +5 -0
- package/src/semantic/utils/transform-writer.js +75 -0
- package/src/workflow/index.js +22 -22
- package/tsconfig.json +54 -0
- package/vitest.config.mts +10 -0
- package/bin/cm-publish-pages.js +0 -12
- package/semantic.js +0 -1
- package/src/commands/publish-pages.js +0 -29
- package/src/common/cli/heroku.js +0 -21
- package/src/common/cli/heroku.test.js +0 -62
- package/src/main.js +0 -10
- package/src/semantic-release/actions/analyze-commits.js +0 -14
- package/src/semantic-release/actions/fail.js +0 -16
- package/src/semantic-release/actions/generate-notes.js +0 -12
- package/src/semantic-release/actions/index.js +0 -8
- package/src/semantic-release/actions/prepare.js +0 -114
- package/src/semantic-release/actions/publish.js +0 -17
- package/src/semantic-release/actions/success.js +0 -32
- package/src/semantic-release/actions/verify-conditions.js +0 -30
- package/src/semantic-release/actions/verify-release.js +0 -9
- package/src/semantic-release/get-semantic-config.js +0 -115
- package/src/semantic-release/utils/bump-packages-version.js +0 -51
- package/src/semantic-release/utils/bump-packages-version.test.js +0 -78
- package/src/semantic-release/utils/calculate-snapshot-version.js +0 -10
- package/src/semantic-release/utils/calculate-snapshot-version.test.js +0 -69
- package/src/semantic-release/utils/display-package-info.js +0 -11
- package/src/semantic-release/utils/display-release-info.js +0 -12
- package/src/semantic-release/utils/docker-clean-tags.js +0 -45
- package/src/semantic-release/utils/docker-clean-tags.test.js +0 -63
- package/src/semantic-release/utils/docker-publish.js +0 -47
- package/src/semantic-release/utils/docker-publish.test.js +0 -67
- package/src/semantic-release/utils/ghpages-publish.js +0 -16
- package/src/semantic-release/utils/log-section.js +0 -5
- /package/src/{semantic-release → semantic}/utils/__mock__/test1/package.json +0 -0
- /package/src/{semantic-release → semantic}/utils/__mock__/test1/packages/a/package.json +0 -0
- /package/src/{semantic-release → semantic}/utils/__mock__/test1/packages/b/package.json +0 -0
- /package/src/{semantic-release → semantic}/utils/__mock__/test2/package.json +0 -0
- /package/src/{semantic-release → semantic}/utils/__mock__/test2/packages/a/package.json +0 -0
- /package/src/{semantic-release → semantic}/utils/__mock__/test2/packages/b/package.json +0 -0
|
@@ -1,37 +1,43 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import {
|
|
1
|
+
import Listr from "listr";
|
|
2
|
+
import { catchError } from "rxjs";
|
|
3
|
+
|
|
4
|
+
import { npm, yarn } from "../../common/index.js";
|
|
5
|
+
import { refreshMetadata, shouldReinstall } from "../utils/check-install.js";
|
|
5
6
|
|
|
6
7
|
export const updateDependencies = ({ useYarn }) => {
|
|
7
|
-
const manager = useYarn ? yarn : npm
|
|
8
|
-
const reinstall = shouldReinstall()
|
|
8
|
+
const manager = useYarn ? yarn : npm;
|
|
9
|
+
const reinstall = shouldReinstall();
|
|
9
10
|
|
|
10
|
-
return
|
|
11
|
-
title:
|
|
11
|
+
return {
|
|
12
|
+
title: "Install",
|
|
12
13
|
enabled: () => reinstall,
|
|
13
|
-
task: () =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
task: () =>
|
|
15
|
+
new Listr(
|
|
16
|
+
[
|
|
17
|
+
{
|
|
18
|
+
title: `Restore dependencies using ${useYarn ? "Yarn" : "Npm"}`,
|
|
19
|
+
task: () =>
|
|
20
|
+
manager
|
|
21
|
+
.restore()
|
|
22
|
+
.toObservable()
|
|
23
|
+
.pipe(
|
|
24
|
+
catchError((error) => {
|
|
25
|
+
if (useYarn) {
|
|
26
|
+
if (error.stderr.startsWith("error Your lockfile needs to be updated")) {
|
|
27
|
+
throw new Error("yarn.lock file is outdated. Run yarn, commit the updated lockfile and try again.");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
31
|
+
throw error;
|
|
32
|
+
})
|
|
33
|
+
)
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
title: "Refresh metadata",
|
|
37
|
+
task: () => refreshMetadata()
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
{ concurrency: false }
|
|
41
|
+
)
|
|
42
|
+
};
|
|
43
|
+
};
|
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
import isEqual from
|
|
2
|
-
import { getPackageJson, git } from '../../common/index.js'
|
|
1
|
+
import isEqual from "lodash/isEqual.js";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { getPackageJson, git } from "../../common/index.js";
|
|
4
|
+
|
|
5
|
+
function getDeps() {
|
|
6
|
+
const pkg = getPackageJson();
|
|
6
7
|
return {
|
|
7
8
|
dependencies: pkg.dependencies,
|
|
8
9
|
devDependencies: pkg.devDependencies
|
|
9
|
-
}
|
|
10
|
+
};
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export function getHash
|
|
13
|
-
return Buffer.from(JSON.stringify(getDeps())).toString(
|
|
13
|
+
export function getHash() {
|
|
14
|
+
return Buffer.from(JSON.stringify(getDeps())).toString("base64");
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
export function getDepsFromHash
|
|
17
|
+
export function getDepsFromHash() {
|
|
17
18
|
try {
|
|
18
|
-
return JSON.parse(Buffer.from(git.config(
|
|
19
|
-
} catch
|
|
20
|
-
return
|
|
19
|
+
return JSON.parse(Buffer.from(git.config("--local", "npm.hash"), "base64").toString("utf8"));
|
|
20
|
+
} catch {
|
|
21
|
+
return "";
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
export function shouldReinstall
|
|
25
|
-
return !isEqual(getDeps(), getDepsFromHash())
|
|
25
|
+
export function shouldReinstall() {
|
|
26
|
+
return !isEqual(getDeps(), getDepsFromHash());
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
export function refreshMetadata
|
|
29
|
-
git.config(
|
|
29
|
+
export function refreshMetadata() {
|
|
30
|
+
git.config("--local", "npm.hash", `${getHash()}`);
|
|
30
31
|
}
|
package/src/common/cli/cli.js
CHANGED
|
@@ -1,112 +1,110 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import "any-observable/register/rxjs-all.js";
|
|
2
|
+
|
|
3
|
+
import { spawnSync } from "child_process";
|
|
4
|
+
import execa from "execa";
|
|
5
|
+
import { filter, fromEvent, map, merge, takeUntil } from "rxjs";
|
|
5
6
|
export class Cli {
|
|
6
|
-
constructor
|
|
7
|
-
this.cmd = cmd
|
|
7
|
+
constructor(cmd) {
|
|
8
|
+
this.cmd = cmd;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
sync
|
|
11
|
-
return Cli.run(this.cmd, args).sync()
|
|
11
|
+
sync(...args) {
|
|
12
|
+
return Cli.run(this.cmd, args).sync();
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
run
|
|
15
|
-
return Cli.run(this.cmd, args)
|
|
15
|
+
run(...args) {
|
|
16
|
+
return Cli.run(this.cmd, args);
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
get
|
|
19
|
-
return Cli.run(this.cmd, args).get()
|
|
19
|
+
get(...args) {
|
|
20
|
+
return Cli.run(this.cmd, args).get();
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
static run
|
|
23
|
+
static run(cmd, args = [], options = {}) {
|
|
23
24
|
const run = (opt = {}) => {
|
|
24
25
|
return execa(cmd, args, {
|
|
25
26
|
cwd: process.cwd(),
|
|
26
27
|
...opt,
|
|
27
28
|
...options
|
|
28
|
-
})
|
|
29
|
-
}
|
|
29
|
+
});
|
|
30
|
+
};
|
|
30
31
|
|
|
31
|
-
let isPromise = true
|
|
32
|
+
let isPromise = true;
|
|
32
33
|
|
|
33
34
|
const promise = new Promise((resolve, reject) => {
|
|
34
35
|
setTimeout(async () => {
|
|
35
36
|
if (isPromise) {
|
|
36
37
|
try {
|
|
37
38
|
const result = await run({
|
|
38
|
-
stdio:
|
|
39
|
-
})
|
|
39
|
+
stdio: "inherit"
|
|
40
|
+
});
|
|
40
41
|
|
|
41
|
-
resolve(result)
|
|
42
|
+
resolve(result);
|
|
42
43
|
} catch (err) {
|
|
43
|
-
|
|
44
|
-
reject(err)
|
|
44
|
+
reject(err);
|
|
45
45
|
}
|
|
46
46
|
} else {
|
|
47
|
-
resolve()
|
|
47
|
+
resolve();
|
|
48
48
|
}
|
|
49
|
-
}, 10)
|
|
50
|
-
})
|
|
49
|
+
}, 10);
|
|
50
|
+
});
|
|
51
51
|
|
|
52
52
|
promise.toObservable = (opt) => {
|
|
53
|
-
isPromise = false
|
|
54
|
-
const cp = run(opt)
|
|
55
|
-
const end$ = fromEvent(cp,
|
|
56
|
-
const stdout$ = fromEvent(cp.stdout,
|
|
53
|
+
isPromise = false;
|
|
54
|
+
const cp = run(opt);
|
|
55
|
+
const end$ = fromEvent(cp, "close");
|
|
56
|
+
const stdout$ = fromEvent(cp.stdout, "data").pipe(
|
|
57
57
|
takeUntil(end$),
|
|
58
|
-
map(data => data.toString())
|
|
59
|
-
)
|
|
60
|
-
const stderr$ = fromEvent(cp.stderr,
|
|
58
|
+
map((data) => data.toString())
|
|
59
|
+
);
|
|
60
|
+
const stderr$ = fromEvent(cp.stderr, "data").pipe(
|
|
61
61
|
takeUntil(end$),
|
|
62
|
-
map(data => data.toString())
|
|
63
|
-
)
|
|
62
|
+
map((data) => data.toString())
|
|
63
|
+
);
|
|
64
64
|
|
|
65
|
-
return merge(stdout$, stderr$).pipe(
|
|
66
|
-
|
|
67
|
-
)
|
|
68
|
-
}
|
|
65
|
+
return merge(stdout$, stderr$).pipe(filter(Boolean));
|
|
66
|
+
};
|
|
69
67
|
|
|
70
68
|
promise.toStream = (opt) => {
|
|
71
|
-
isPromise = false
|
|
69
|
+
isPromise = false;
|
|
72
70
|
|
|
73
|
-
return run(opt)
|
|
74
|
-
}
|
|
71
|
+
return run(opt);
|
|
72
|
+
};
|
|
75
73
|
|
|
76
74
|
promise.cwd = (cwd) => {
|
|
77
|
-
options.cwd = cwd
|
|
78
|
-
return promise
|
|
79
|
-
}
|
|
75
|
+
options.cwd = cwd;
|
|
76
|
+
return promise;
|
|
77
|
+
};
|
|
80
78
|
|
|
81
79
|
promise.sync = (opt) => {
|
|
82
|
-
isPromise = false
|
|
80
|
+
isPromise = false;
|
|
83
81
|
return execa.sync(cmd, args, {
|
|
84
82
|
cwd: process.cwd(),
|
|
85
|
-
stdio:
|
|
83
|
+
stdio: "inherit",
|
|
86
84
|
...options,
|
|
87
85
|
...opt
|
|
88
|
-
})
|
|
89
|
-
}
|
|
86
|
+
});
|
|
87
|
+
};
|
|
90
88
|
|
|
91
89
|
promise.getRaw = (opt) => {
|
|
92
|
-
isPromise = false
|
|
90
|
+
isPromise = false;
|
|
93
91
|
return Cli.getRaw(cmd, args, {
|
|
94
92
|
cwd: process.cwd(),
|
|
95
93
|
...options,
|
|
96
94
|
...opt
|
|
97
|
-
})
|
|
98
|
-
}
|
|
95
|
+
});
|
|
96
|
+
};
|
|
99
97
|
|
|
100
|
-
promise.get = promise.getRaw
|
|
98
|
+
promise.get = promise.getRaw;
|
|
101
99
|
|
|
102
|
-
return promise
|
|
100
|
+
return promise;
|
|
103
101
|
}
|
|
104
102
|
|
|
105
|
-
static getRaw
|
|
103
|
+
static getRaw(cmd, args, options) {
|
|
106
104
|
return spawnSync(cmd, args, options)
|
|
107
|
-
.output.filter(o => !!o)
|
|
108
|
-
.map(o => o.toString())
|
|
109
|
-
.join(
|
|
110
|
-
.trim()
|
|
105
|
+
.output.filter((o) => !!o)
|
|
106
|
+
.map((o) => o.toString())
|
|
107
|
+
.join("\n")
|
|
108
|
+
.trim();
|
|
111
109
|
}
|
|
112
110
|
}
|
package/src/common/cli/docker.js
CHANGED
|
@@ -1,63 +1,66 @@
|
|
|
1
|
-
import axios from
|
|
2
|
-
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
|
|
3
|
+
import { Cli } from "./cli.js";
|
|
3
4
|
|
|
4
5
|
class DockerCli extends Cli {
|
|
5
|
-
constructor
|
|
6
|
-
super(
|
|
6
|
+
constructor() {
|
|
7
|
+
super("docker");
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
tag
|
|
10
|
-
return this.get(
|
|
10
|
+
tag(...args) {
|
|
11
|
+
return this.get("tag", ...args);
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
login
|
|
14
|
-
return this.sync(
|
|
14
|
+
login(...args) {
|
|
15
|
+
return this.sync("login", ...args);
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
push
|
|
18
|
-
return this.run(
|
|
18
|
+
push(...args) {
|
|
19
|
+
return this.run("push", ...args);
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
async getToken
|
|
22
|
-
const {
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
async getToken(username, password) {
|
|
23
|
+
const {
|
|
24
|
+
data: { token }
|
|
25
|
+
} = await axios({
|
|
26
|
+
method: "POST",
|
|
27
|
+
url: "https://hub.docker.com/v2/users/login/",
|
|
25
28
|
headers: {
|
|
26
|
-
Accept:
|
|
27
|
-
|
|
29
|
+
Accept: "application/json",
|
|
30
|
+
"Content-Type": "application/json"
|
|
28
31
|
},
|
|
29
32
|
data: {
|
|
30
33
|
username,
|
|
31
34
|
password
|
|
32
35
|
}
|
|
33
|
-
})
|
|
36
|
+
});
|
|
34
37
|
|
|
35
|
-
return token
|
|
38
|
+
return token;
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
async getTags
|
|
41
|
+
async getTags({ token, repository }) {
|
|
39
42
|
const { data } = await axios({
|
|
40
|
-
method:
|
|
43
|
+
method: "GET",
|
|
41
44
|
url: `https://hub.docker.com/v2/repositories/${repository}/tags/?page=1&page_size=500`,
|
|
42
45
|
headers: {
|
|
43
|
-
Accept:
|
|
46
|
+
Accept: "application/json",
|
|
44
47
|
Authorization: `JWT ${token}`
|
|
45
48
|
}
|
|
46
|
-
})
|
|
49
|
+
});
|
|
47
50
|
|
|
48
|
-
return data.results
|
|
51
|
+
return data.results;
|
|
49
52
|
}
|
|
50
53
|
|
|
51
|
-
async deleteTag
|
|
54
|
+
async deleteTag(tag, { token, repository }) {
|
|
52
55
|
await axios({
|
|
53
|
-
method:
|
|
56
|
+
method: "DELETE",
|
|
54
57
|
url: `https://hub.docker.com/v2/repositories/${repository}/tags/${tag}/`,
|
|
55
58
|
headers: {
|
|
56
|
-
Accept:
|
|
59
|
+
Accept: "application/json",
|
|
57
60
|
Authorization: `JWT ${token}`
|
|
58
61
|
}
|
|
59
|
-
})
|
|
62
|
+
});
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
65
|
|
|
63
|
-
export const docker = new DockerCli()
|
|
66
|
+
export const docker = new DockerCli();
|
|
@@ -1,135 +1,133 @@
|
|
|
1
|
-
|
|
1
|
+
vi.mock("axios", () => {
|
|
2
|
+
return { default: vi.fn() };
|
|
3
|
+
});
|
|
4
|
+
vi.mock("execa", () => {
|
|
5
|
+
const execaMock = vi.fn();
|
|
6
|
+
execaMock.sync = vi.fn();
|
|
7
|
+
return { default: execaMock };
|
|
8
|
+
});
|
|
9
|
+
const { default: execa } = await import("execa");
|
|
10
|
+
const { default: axios } = await import("axios");
|
|
11
|
+
const { docker } = await import("./docker.js");
|
|
12
|
+
const { Cli } = await import("./cli.js");
|
|
2
13
|
|
|
3
|
-
|
|
4
|
-
return { default: jest.fn() }
|
|
5
|
-
})
|
|
6
|
-
jest.unstable_mockModule('execa', () => {
|
|
7
|
-
const execaMock = jest.fn()
|
|
8
|
-
execaMock.sync = jest.fn()
|
|
9
|
-
return { default: execaMock }
|
|
10
|
-
})
|
|
11
|
-
const { default: execa } = await import('execa')
|
|
12
|
-
const { default: axios } = await import('axios')
|
|
13
|
-
const { docker } = await import('./docker.js')
|
|
14
|
-
const { Cli } = await import('./cli.js')
|
|
15
|
-
|
|
16
|
-
execa.mockReturnValue({})
|
|
14
|
+
execa.mockReturnValue({});
|
|
17
15
|
|
|
18
16
|
execa.sync.mockImplementation((...args) => {
|
|
19
17
|
return {
|
|
20
|
-
stdout: `CMD: ${[].concat(...args.filter(arg => typeof arg ===
|
|
21
|
-
}
|
|
22
|
-
})
|
|
18
|
+
stdout: `CMD: ${[].concat(...args.filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`
|
|
19
|
+
};
|
|
20
|
+
});
|
|
23
21
|
|
|
24
|
-
describe(
|
|
22
|
+
describe("DockerCli", () => {
|
|
25
23
|
beforeEach(() => {
|
|
26
|
-
|
|
27
|
-
return `CMD: ${[].concat(...args.filter(arg => typeof arg ===
|
|
28
|
-
})
|
|
29
|
-
})
|
|
30
|
-
describe(
|
|
31
|
-
it(
|
|
32
|
-
const result = docker.tag(
|
|
24
|
+
vi.spyOn(Cli, "getRaw").mockImplementation((...args) => {
|
|
25
|
+
return `CMD: ${[].concat(...args.filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`;
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
describe("tag", () => {
|
|
29
|
+
it("should run tag cmd", () => {
|
|
30
|
+
const result = docker.tag("tag-arg", "image");
|
|
33
31
|
|
|
34
|
-
expect(result).toEqual(
|
|
35
|
-
expect(Cli.getRaw).toHaveBeenCalledWith(
|
|
32
|
+
expect(result).toEqual("CMD: docker tag tag-arg image");
|
|
33
|
+
expect(Cli.getRaw).toHaveBeenCalledWith("docker", ["tag", "tag-arg", "image"], {
|
|
36
34
|
cwd: process.cwd()
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
describe(
|
|
41
|
-
it(
|
|
42
|
-
const result = docker.login(
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe("login", () => {
|
|
39
|
+
it("should run login cmd", () => {
|
|
40
|
+
const result = docker.login("login-arg");
|
|
43
41
|
|
|
44
|
-
expect(result.stdout).toEqual(
|
|
45
|
-
expect(execa.sync).toHaveBeenCalledWith(
|
|
42
|
+
expect(result.stdout).toEqual("CMD: docker login login-arg");
|
|
43
|
+
expect(execa.sync).toHaveBeenCalledWith("docker", ["login", "login-arg"], {
|
|
46
44
|
cwd: process.cwd(),
|
|
47
|
-
stdio:
|
|
48
|
-
})
|
|
49
|
-
})
|
|
50
|
-
})
|
|
51
|
-
describe(
|
|
52
|
-
it(
|
|
53
|
-
await docker.push(
|
|
45
|
+
stdio: "inherit"
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe("push", () => {
|
|
50
|
+
it("should run push cmd", async () => {
|
|
51
|
+
await docker.push("push-arg");
|
|
54
52
|
|
|
55
|
-
expect(execa).toHaveBeenCalledWith(
|
|
53
|
+
expect(execa).toHaveBeenCalledWith("docker", ["push", "push-arg"], {
|
|
56
54
|
cwd: process.cwd(),
|
|
57
|
-
stdio:
|
|
58
|
-
})
|
|
59
|
-
})
|
|
60
|
-
})
|
|
61
|
-
describe(
|
|
55
|
+
stdio: "inherit"
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe("getToken", () => {
|
|
62
60
|
beforeEach(() => {
|
|
63
|
-
axios.mockReturnValue({ data: { token:
|
|
64
|
-
})
|
|
65
|
-
it(
|
|
66
|
-
const token = await docker.getToken(
|
|
61
|
+
axios.mockReturnValue({ data: { token: "token" } });
|
|
62
|
+
});
|
|
63
|
+
it("should get token", async () => {
|
|
64
|
+
const token = await docker.getToken("username", "password");
|
|
67
65
|
|
|
68
66
|
expect(axios).toHaveBeenCalledWith({
|
|
69
|
-
method:
|
|
70
|
-
url:
|
|
67
|
+
method: "POST",
|
|
68
|
+
url: "https://hub.docker.com/v2/users/login/",
|
|
71
69
|
headers: {
|
|
72
|
-
Accept:
|
|
73
|
-
|
|
70
|
+
Accept: "application/json",
|
|
71
|
+
"Content-Type": "application/json"
|
|
74
72
|
},
|
|
75
73
|
data: {
|
|
76
|
-
password:
|
|
77
|
-
username:
|
|
74
|
+
password: "password",
|
|
75
|
+
username: "username"
|
|
78
76
|
}
|
|
79
|
-
})
|
|
80
|
-
expect(token).toEqual(
|
|
81
|
-
})
|
|
82
|
-
})
|
|
83
|
-
describe(
|
|
77
|
+
});
|
|
78
|
+
expect(token).toEqual("token");
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
describe("getTags", () => {
|
|
84
82
|
beforeEach(() => {
|
|
85
83
|
axios.mockReturnValue({
|
|
86
84
|
data: {
|
|
87
85
|
results: [
|
|
88
86
|
{
|
|
89
|
-
name:
|
|
90
|
-
last_updated: new Date(
|
|
87
|
+
name: "branch-1",
|
|
88
|
+
last_updated: new Date("2020-06-01")
|
|
91
89
|
}
|
|
92
90
|
]
|
|
93
91
|
}
|
|
94
|
-
})
|
|
95
|
-
})
|
|
96
|
-
it(
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
it("should get token", async () => {
|
|
97
95
|
const tags = await docker.getTags({
|
|
98
|
-
token:
|
|
99
|
-
repository:
|
|
100
|
-
})
|
|
96
|
+
token: "token",
|
|
97
|
+
repository: "owner"
|
|
98
|
+
});
|
|
101
99
|
|
|
102
100
|
expect(tags).toEqual([
|
|
103
101
|
{
|
|
104
|
-
name:
|
|
105
|
-
last_updated: new Date(
|
|
102
|
+
name: "branch-1",
|
|
103
|
+
last_updated: new Date("2020-06-01")
|
|
106
104
|
}
|
|
107
|
-
])
|
|
105
|
+
]);
|
|
108
106
|
expect(axios).toHaveBeenCalledWith({
|
|
109
|
-
method:
|
|
110
|
-
url:
|
|
107
|
+
method: "GET",
|
|
108
|
+
url: "https://hub.docker.com/v2/repositories/owner/tags/?page=1&page_size=500",
|
|
111
109
|
headers: {
|
|
112
|
-
Accept:
|
|
113
|
-
Authorization:
|
|
110
|
+
Accept: "application/json",
|
|
111
|
+
Authorization: "JWT token"
|
|
114
112
|
}
|
|
115
|
-
})
|
|
116
|
-
})
|
|
117
|
-
})
|
|
118
|
-
describe(
|
|
119
|
-
it(
|
|
120
|
-
await docker.deleteTag(
|
|
121
|
-
token:
|
|
122
|
-
repository:
|
|
123
|
-
})
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
describe("deleteTag", () => {
|
|
117
|
+
it("should run delete Tag", async () => {
|
|
118
|
+
await docker.deleteTag("my-tag", {
|
|
119
|
+
token: "token",
|
|
120
|
+
repository: "owner"
|
|
121
|
+
});
|
|
124
122
|
|
|
125
123
|
expect(axios).toHaveBeenCalledWith({
|
|
126
124
|
headers: {
|
|
127
|
-
Accept:
|
|
128
|
-
Authorization:
|
|
125
|
+
Accept: "application/json",
|
|
126
|
+
Authorization: "JWT token"
|
|
129
127
|
},
|
|
130
|
-
method:
|
|
131
|
-
url:
|
|
132
|
-
})
|
|
133
|
-
})
|
|
134
|
-
})
|
|
135
|
-
})
|
|
128
|
+
method: "DELETE",
|
|
129
|
+
url: "https://hub.docker.com/v2/repositories/owner/tags/my-tag/"
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
});
|