@regressionproof/snapshotter 0.5.2 → 0.5.4
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/build/.spruce/errors/errors.types.d.ts +7 -0
- package/build/.spruce/errors/regressionproofSnapshotter/execCommandFailed.schema.js +6 -0
- package/build/errors/SpruceError.js +1 -1
- package/build/errors/execCommandFailed.builder.d.ts +4 -0
- package/build/errors/execCommandFailed.builder.js +4 -0
- package/build/esm/.spruce/errors/errors.types.d.ts +7 -0
- package/build/esm/errors/SpruceError.js +1 -1
- package/build/esm/errors/execCommandFailed.builder.d.ts +4 -0
- package/build/esm/errors/execCommandFailed.builder.js +4 -0
- package/build/esm/git.js +36 -9
- package/build/esm/utilities/version.d.ts +1 -0
- package/build/esm/utilities/version.js +13 -0
- package/build/git.js +30 -9
- package/build/utilities/version.d.ts +1 -0
- package/build/utilities/version.js +18 -0
- package/package.json +2 -2
|
@@ -6,6 +6,7 @@ export declare namespace SpruceErrors.RegressionproofSnapshotter {
|
|
|
6
6
|
'command': string;
|
|
7
7
|
'stdout'?: string | undefined | null;
|
|
8
8
|
'stderr'?: string | undefined | null;
|
|
9
|
+
'version': string;
|
|
9
10
|
}
|
|
10
11
|
interface ExecCommandFailedSchema extends SpruceSchema.Schema {
|
|
11
12
|
id: 'execCommandFailed';
|
|
@@ -29,6 +30,12 @@ export declare namespace SpruceErrors.RegressionproofSnapshotter {
|
|
|
29
30
|
type: 'text';
|
|
30
31
|
options: undefined;
|
|
31
32
|
};
|
|
33
|
+
/** . */
|
|
34
|
+
'version': {
|
|
35
|
+
type: 'text';
|
|
36
|
+
isRequired: true;
|
|
37
|
+
options: undefined;
|
|
38
|
+
};
|
|
32
39
|
};
|
|
33
40
|
}
|
|
34
41
|
type ExecCommandFailedEntity = SchemaEntity<SpruceErrors.RegressionproofSnapshotter.ExecCommandFailedSchema>;
|
|
@@ -23,6 +23,12 @@ const execCommandFailedSchema = {
|
|
|
23
23
|
type: 'text',
|
|
24
24
|
options: undefined
|
|
25
25
|
},
|
|
26
|
+
/** . */
|
|
27
|
+
'version': {
|
|
28
|
+
type: 'text',
|
|
29
|
+
isRequired: true,
|
|
30
|
+
options: undefined
|
|
31
|
+
},
|
|
26
32
|
}
|
|
27
33
|
};
|
|
28
34
|
schema_1.SchemaRegistry.getInstance().trackSchema(execCommandFailedSchema);
|
|
@@ -6,6 +6,7 @@ export declare namespace SpruceErrors.RegressionproofSnapshotter {
|
|
|
6
6
|
'command': string;
|
|
7
7
|
'stdout'?: string | undefined | null;
|
|
8
8
|
'stderr'?: string | undefined | null;
|
|
9
|
+
'version': string;
|
|
9
10
|
}
|
|
10
11
|
interface ExecCommandFailedSchema extends SpruceSchema.Schema {
|
|
11
12
|
id: 'execCommandFailed';
|
|
@@ -29,6 +30,12 @@ export declare namespace SpruceErrors.RegressionproofSnapshotter {
|
|
|
29
30
|
type: 'text';
|
|
30
31
|
options: undefined;
|
|
31
32
|
};
|
|
33
|
+
/** . */
|
|
34
|
+
'version': {
|
|
35
|
+
type: 'text';
|
|
36
|
+
isRequired: true;
|
|
37
|
+
options: undefined;
|
|
38
|
+
};
|
|
32
39
|
};
|
|
33
40
|
}
|
|
34
41
|
type ExecCommandFailedEntity = SchemaEntity<SpruceErrors.RegressionproofSnapshotter.ExecCommandFailedSchema>;
|
package/build/esm/git.js
CHANGED
|
@@ -12,6 +12,7 @@ import { existsSync } from 'fs';
|
|
|
12
12
|
import path from 'path';
|
|
13
13
|
import { promisify } from 'util';
|
|
14
14
|
import SpruceError from './errors/SpruceError.js.js';
|
|
15
|
+
import { getPackageVersion } from './utilities/version.js.js';
|
|
15
16
|
const execAsync = promisify(exec);
|
|
16
17
|
export function gitCommit(mirrorPath, log) {
|
|
17
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -33,25 +34,50 @@ export function gitCommit(mirrorPath, log) {
|
|
|
33
34
|
export function gitPush(mirrorPath, remote, log) {
|
|
34
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
36
|
const authedUrl = remote.url.replace('://', `://${remote.token}@`);
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
const originExists = yield remoteExists(mirrorPath, 'origin');
|
|
38
|
+
if (originExists) {
|
|
38
39
|
yield execOrThrow(`git -C "${mirrorPath}" remote set-url origin "${authedUrl}"`);
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
+
else {
|
|
41
42
|
yield execOrThrow(`git -C "${mirrorPath}" remote add origin "${authedUrl}"`);
|
|
42
43
|
}
|
|
44
|
+
yield pullFromRemote(mirrorPath, log);
|
|
45
|
+
yield execOrThrow(`git -C "${mirrorPath}" push -u origin HEAD`, log);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function pullFromRemote(mirrorPath, log) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
50
|
yield execOrThrow(`git -C "${mirrorPath}" fetch origin`, log);
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
const branch = yield getCurrentBranch(mirrorPath);
|
|
52
|
+
const remoteBranchExists = yield checkRemoteBranchExists(mirrorPath, branch);
|
|
53
|
+
if (remoteBranchExists) {
|
|
54
|
+
yield execOrThrow(`git -C "${mirrorPath}" rebase origin/${branch}`, log);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function getCurrentBranch(mirrorPath) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const { stdout } = yield execAsync(`git -C "${mirrorPath}" rev-parse --abbrev-ref HEAD`);
|
|
61
|
+
return stdout.trim();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function checkRemoteBranchExists(mirrorPath, branch) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
try {
|
|
67
|
+
const { stdout } = yield execAsync(`git -C "${mirrorPath}" ls-remote --heads origin ${branch}`);
|
|
68
|
+
return stdout.trim().length > 0;
|
|
69
|
+
}
|
|
70
|
+
catch (_a) {
|
|
71
|
+
return false;
|
|
46
72
|
}
|
|
47
|
-
yield execOrThrow(`git -C "${mirrorPath}" push -u origin HEAD`, log);
|
|
48
73
|
});
|
|
49
74
|
}
|
|
50
|
-
function
|
|
75
|
+
function remoteExists(mirrorPath, remoteName) {
|
|
51
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
77
|
try {
|
|
53
|
-
yield execAsync(`git -C "${mirrorPath}"
|
|
54
|
-
|
|
78
|
+
const { stdout } = yield execAsync(`git -C "${mirrorPath}" remote`);
|
|
79
|
+
const remotes = stdout.trim().split('\n');
|
|
80
|
+
return remotes.includes(remoteName);
|
|
55
81
|
}
|
|
56
82
|
catch (_a) {
|
|
57
83
|
return false;
|
|
@@ -74,6 +100,7 @@ function execOrThrow(command, log) {
|
|
|
74
100
|
command,
|
|
75
101
|
stdout,
|
|
76
102
|
stderr,
|
|
103
|
+
version: getPackageVersion(),
|
|
77
104
|
});
|
|
78
105
|
}
|
|
79
106
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getPackageVersion(): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
export function getPackageVersion() {
|
|
4
|
+
var _a;
|
|
5
|
+
try {
|
|
6
|
+
const packagePath = path.join(__dirname, '../../package.json');
|
|
7
|
+
const packageJson = JSON.parse(readFileSync(packagePath, 'utf-8'));
|
|
8
|
+
return (_a = packageJson.version) !== null && _a !== void 0 ? _a : '*** unable to resolve version ***';
|
|
9
|
+
}
|
|
10
|
+
catch (_b) {
|
|
11
|
+
return '*** unable to resolve version ***';
|
|
12
|
+
}
|
|
13
|
+
}
|
package/build/git.js
CHANGED
|
@@ -10,6 +10,7 @@ const fs_1 = require("fs");
|
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
11
|
const util_1 = require("util");
|
|
12
12
|
const SpruceError_js_1 = __importDefault(require("./errors/SpruceError.js"));
|
|
13
|
+
const version_js_1 = require("./utilities/version.js");
|
|
13
14
|
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
14
15
|
async function gitCommit(mirrorPath, log) {
|
|
15
16
|
const gitDir = path_1.default.join(mirrorPath, '.git');
|
|
@@ -28,23 +29,42 @@ async function gitCommit(mirrorPath, log) {
|
|
|
28
29
|
}
|
|
29
30
|
async function gitPush(mirrorPath, remote, log) {
|
|
30
31
|
const authedUrl = remote.url.replace('://', `://${remote.token}@`);
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
const originExists = await remoteExists(mirrorPath, 'origin');
|
|
33
|
+
if (originExists) {
|
|
33
34
|
await execOrThrow(`git -C "${mirrorPath}" remote set-url origin "${authedUrl}"`);
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
+
else {
|
|
36
37
|
await execOrThrow(`git -C "${mirrorPath}" remote add origin "${authedUrl}"`);
|
|
37
38
|
}
|
|
39
|
+
await pullFromRemote(mirrorPath, log);
|
|
40
|
+
await execOrThrow(`git -C "${mirrorPath}" push -u origin HEAD`, log);
|
|
41
|
+
}
|
|
42
|
+
async function pullFromRemote(mirrorPath, log) {
|
|
38
43
|
await execOrThrow(`git -C "${mirrorPath}" fetch origin`, log);
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
const branch = await getCurrentBranch(mirrorPath);
|
|
45
|
+
const remoteBranchExists = await checkRemoteBranchExists(mirrorPath, branch);
|
|
46
|
+
if (remoteBranchExists) {
|
|
47
|
+
await execOrThrow(`git -C "${mirrorPath}" rebase origin/${branch}`, log);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function getCurrentBranch(mirrorPath) {
|
|
51
|
+
const { stdout } = await execAsync(`git -C "${mirrorPath}" rev-parse --abbrev-ref HEAD`);
|
|
52
|
+
return stdout.trim();
|
|
53
|
+
}
|
|
54
|
+
async function checkRemoteBranchExists(mirrorPath, branch) {
|
|
55
|
+
try {
|
|
56
|
+
const { stdout } = await execAsync(`git -C "${mirrorPath}" ls-remote --heads origin ${branch}`);
|
|
57
|
+
return stdout.trim().length > 0;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return false;
|
|
41
61
|
}
|
|
42
|
-
await execOrThrow(`git -C "${mirrorPath}" push -u origin HEAD`, log);
|
|
43
62
|
}
|
|
44
|
-
async function
|
|
63
|
+
async function remoteExists(mirrorPath, remoteName) {
|
|
45
64
|
try {
|
|
46
|
-
await execAsync(`git -C "${mirrorPath}"
|
|
47
|
-
|
|
65
|
+
const { stdout } = await execAsync(`git -C "${mirrorPath}" remote`);
|
|
66
|
+
const remotes = stdout.trim().split('\n');
|
|
67
|
+
return remotes.includes(remoteName);
|
|
48
68
|
}
|
|
49
69
|
catch {
|
|
50
70
|
return false;
|
|
@@ -64,6 +84,7 @@ async function execOrThrow(command, log) {
|
|
|
64
84
|
command,
|
|
65
85
|
stdout,
|
|
66
86
|
stderr,
|
|
87
|
+
version: (0, version_js_1.getPackageVersion)(),
|
|
67
88
|
});
|
|
68
89
|
}
|
|
69
90
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getPackageVersion(): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getPackageVersion = getPackageVersion;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
function getPackageVersion() {
|
|
10
|
+
try {
|
|
11
|
+
const packagePath = path_1.default.join(__dirname, '../../package.json');
|
|
12
|
+
const packageJson = JSON.parse((0, node_fs_1.readFileSync)(packagePath, 'utf-8'));
|
|
13
|
+
return packageJson.version ?? '*** unable to resolve version ***';
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return '*** unable to resolve version ***';
|
|
17
|
+
}
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regressionproof/snapshotter",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"@sprucelabs/spruce-core-schemas": "^42.1.3",
|
|
95
95
|
"@sprucelabs/spruce-skill-utils": "^34.0.3"
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "01c36085fc6f8c0fdc7778de7f7dee6e194cb3f4"
|
|
98
98
|
}
|