deploy-vir 2.1.0 → 2.1.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/dist/cli/cli.js +1 -1
- package/dist/git.d.ts +1 -0
- package/dist/git.js +1 -0
- package/dist/notifications/slack.d.ts +1 -1
- package/dist/notifications/slack.js +2 -2
- package/package.json +9 -9
- package/src/cli/cli.ts +1 -1
- package/src/git.ts +97 -92
- package/src/notifications/slack.ts +2 -2
package/dist/cli/cli.js
CHANGED
|
@@ -2,7 +2,7 @@ import { assertWrap } from '@augment-vir/assert';
|
|
|
2
2
|
import { awaitedForEach, extractErrorMessage, log } from '@augment-vir/common';
|
|
3
3
|
import { select } from '@inquirer/prompts';
|
|
4
4
|
import { resolve } from 'node:path';
|
|
5
|
-
import simpleGit from 'simple-git';
|
|
5
|
+
import { simpleGit } from 'simple-git';
|
|
6
6
|
import { getGitRemoteName, pushDeploy } from '../git.js';
|
|
7
7
|
import { KnownError } from '../known.error.js';
|
|
8
8
|
import { sendNotifications } from '../notifications/send-notifications.js';
|
package/dist/git.d.ts
CHANGED
package/dist/git.js
CHANGED
|
@@ -5,4 +5,4 @@ export { type ChatPostMessageArguments } from '@slack/web-api';
|
|
|
5
5
|
*
|
|
6
6
|
* @category Internal
|
|
7
7
|
*/
|
|
8
|
-
export declare function sendNotificationToSlack({
|
|
8
|
+
export declare function sendNotificationToSlack({ deployResult: { deployCommits: { deployedCommits, overwrittenCommits }, branchStatus: { after, before }, toBranchName, }, notification, repoConfig, }: Readonly<NotificationParams>): Promise<void>;
|
|
@@ -38,7 +38,7 @@ function chunkSectionLines(lines) {
|
|
|
38
38
|
*
|
|
39
39
|
* @category Internal
|
|
40
40
|
*/
|
|
41
|
-
export async function sendNotificationToSlack({
|
|
41
|
+
export async function sendNotificationToSlack({ deployResult: { deployCommits: { deployedCommits, overwrittenCommits }, branchStatus: { after, before }, toBranchName, }, notification, repoConfig, }) {
|
|
42
42
|
const deployedCommitBullets = deployedCommits.map((commit) => formatCommit(repoConfig.commitBaseUrl, commit));
|
|
43
43
|
const overwrittenCommitBullets = overwrittenCommits.map((commit) => formatCommit(repoConfig.commitBaseUrl, commit));
|
|
44
44
|
const deployedCommitBulletLines = deployedCommitBullets.map((bullet) => `- ${bullet}`);
|
|
@@ -56,7 +56,7 @@ export async function sendNotificationToSlack({ branchConfig, deployResult: { de
|
|
|
56
56
|
type: 'section',
|
|
57
57
|
text: {
|
|
58
58
|
type: 'mrkdwn',
|
|
59
|
-
text: `*${setFirstLetterCasing(repoConfig.name, StringCase.Upper)} ${setFirstLetterCasing(
|
|
59
|
+
text: `*${setFirstLetterCasing(repoConfig.name, StringCase.Upper)} ${setFirstLetterCasing(toBranchName, StringCase.Upper)}* Pushed`,
|
|
60
60
|
},
|
|
61
61
|
},
|
|
62
62
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deploy-vir",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Deploy a branch to another branch with notifications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deploy",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"test:update": "npm run test update"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@augment-vir/assert": "^31.57.
|
|
45
|
-
"@augment-vir/common": "^31.57.
|
|
46
|
-
"@augment-vir/node": "^31.57.
|
|
44
|
+
"@augment-vir/assert": "^31.57.5",
|
|
45
|
+
"@augment-vir/common": "^31.57.5",
|
|
46
|
+
"@augment-vir/node": "^31.57.5",
|
|
47
47
|
"@inquirer/prompts": "^8.1.0",
|
|
48
48
|
"@slack/web-api": "^7.13.0",
|
|
49
49
|
"cli-vir": "^1.0.3",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"@stylistic/eslint-plugin": "^5.6.1",
|
|
58
58
|
"@stylistic/eslint-plugin-ts": "^4.4.1",
|
|
59
59
|
"@types/node": "^25.0.3",
|
|
60
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^8.52.0",
|
|
61
61
|
"cspell": "^9.4.0",
|
|
62
|
-
"dependency-cruiser": "^17.3.
|
|
62
|
+
"dependency-cruiser": "^17.3.6",
|
|
63
63
|
"esbuild": "^0.27.2",
|
|
64
64
|
"eslint": "^9.39.2",
|
|
65
65
|
"eslint-config-prettier": "^10.1.8",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"eslint-plugin-unicorn": "^62.0.0",
|
|
73
73
|
"istanbul-smart-text-reporter": "^1.1.5",
|
|
74
74
|
"markdown-code-example-inserter": "^3.0.3",
|
|
75
|
-
"npm-check-updates": "^19.
|
|
75
|
+
"npm-check-updates": "^19.3.1",
|
|
76
76
|
"prettier": "~3.3.3",
|
|
77
77
|
"prettier-plugin-interpolated-html-tags": "^2.0.1",
|
|
78
78
|
"prettier-plugin-jsdoc": "^1.8.0",
|
|
@@ -84,8 +84,8 @@
|
|
|
84
84
|
"runstorm": "^1.0.0",
|
|
85
85
|
"typedoc": "^0.28.15",
|
|
86
86
|
"typescript": "^5.9.3",
|
|
87
|
-
"typescript-eslint": "^8.
|
|
88
|
-
"virmator": "^14.4.
|
|
87
|
+
"typescript-eslint": "^8.52.0",
|
|
88
|
+
"virmator": "^14.4.2"
|
|
89
89
|
},
|
|
90
90
|
"engines": {
|
|
91
91
|
"node": ">=22"
|
package/src/cli/cli.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {assertWrap} from '@augment-vir/assert';
|
|
|
2
2
|
import {awaitedForEach, extractErrorMessage, log} from '@augment-vir/common';
|
|
3
3
|
import {select} from '@inquirer/prompts';
|
|
4
4
|
import {resolve} from 'node:path';
|
|
5
|
-
import simpleGit from 'simple-git';
|
|
5
|
+
import {simpleGit} from 'simple-git';
|
|
6
6
|
import {type DeployVirConfig} from '../config.js';
|
|
7
7
|
import {getGitRemoteName, pushDeploy} from '../git.js';
|
|
8
8
|
import {KnownError} from '../known.error.js';
|
package/src/git.ts
CHANGED
|
@@ -79,6 +79,7 @@ export type DeployBranchStatus = {
|
|
|
79
79
|
export type DeployResult = {
|
|
80
80
|
deployCommits: DeployCommits;
|
|
81
81
|
branchStatus: DeployBranchStatus;
|
|
82
|
+
toBranchName: string;
|
|
82
83
|
};
|
|
83
84
|
|
|
84
85
|
/**
|
|
@@ -92,108 +93,112 @@ export async function pushDeploy(
|
|
|
92
93
|
remoteName: string,
|
|
93
94
|
bypassConfirmation = false,
|
|
94
95
|
): Promise<DeployResult[]> {
|
|
95
|
-
return await awaitedBlockingMap(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
96
|
+
return await awaitedBlockingMap(
|
|
97
|
+
branches,
|
|
98
|
+
async ({fromBranch, toBranch}): Promise<DeployResult> => {
|
|
99
|
+
assert.isTruthy(fromBranch, `Deploy '${deployName}' fromBranch cannot be empty.`);
|
|
100
|
+
assert.isTruthy(toBranch, `Deploy '${deployName}' toBranch cannot be empty.`);
|
|
101
|
+
assert.isTruthy(remoteName, 'Remote name cannot be empty.');
|
|
102
|
+
|
|
103
|
+
log.faint(`Pushing ${remoteName}/${fromBranch} to ${toBranch}`);
|
|
104
|
+
|
|
105
|
+
await git.fetch(remoteName, fromBranch);
|
|
106
|
+
await git.fetch(remoteName, toBranch);
|
|
107
|
+
|
|
108
|
+
const pushString = `${remoteName}/${fromBranch}:${toBranch}`;
|
|
109
|
+
|
|
110
|
+
// Get the current commit on the target branch before pushing
|
|
111
|
+
const beforeCommit = assertWrap.isDefined(
|
|
112
|
+
(
|
|
113
|
+
await git.log([
|
|
114
|
+
`${remoteName}/${toBranch}`,
|
|
115
|
+
'-1',
|
|
116
|
+
])
|
|
117
|
+
).latest,
|
|
118
|
+
`Failed to get current commit for ${remoteName}/${toBranch}`,
|
|
119
|
+
);
|
|
104
120
|
|
|
105
|
-
|
|
121
|
+
const afterCommit = assertWrap.isDefined(
|
|
122
|
+
(
|
|
123
|
+
await git.log([
|
|
124
|
+
`${remoteName}/${fromBranch}`,
|
|
125
|
+
'-1',
|
|
126
|
+
])
|
|
127
|
+
).latest,
|
|
128
|
+
`Failed to get current commit for ${remoteName}/${fromBranch}`,
|
|
129
|
+
);
|
|
106
130
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
(
|
|
131
|
+
/** Get commits that are on {@link toBranch} but not on {@link fromBranch}. */
|
|
132
|
+
const commitsAhead = (
|
|
110
133
|
await git.log([
|
|
111
|
-
`${remoteName}/${toBranch}`,
|
|
112
|
-
'-1',
|
|
134
|
+
`${remoteName}/${toBranch}..${remoteName}/${fromBranch}`,
|
|
113
135
|
])
|
|
114
|
-
).
|
|
115
|
-
|
|
116
|
-
|
|
136
|
+
).all;
|
|
137
|
+
|
|
138
|
+
if (!commitsAhead.length) {
|
|
139
|
+
throw new KnownError('No commit diff: nothing to deploy!');
|
|
140
|
+
}
|
|
117
141
|
|
|
118
|
-
|
|
119
|
-
(
|
|
142
|
+
/** Get commits that are on {@link toBranch} but not on {@link fromBranch}. */
|
|
143
|
+
const commitsBehind = (
|
|
120
144
|
await git.log([
|
|
121
|
-
`${remoteName}/${fromBranch}`,
|
|
122
|
-
'-1',
|
|
145
|
+
`${remoteName}/${fromBranch}..${remoteName}/${toBranch}`,
|
|
123
146
|
])
|
|
124
|
-
).
|
|
125
|
-
`Failed to get current commit for ${remoteName}/${fromBranch}`,
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
/** Get commits that are on {@link toBranch} but not on {@link fromBranch}. */
|
|
129
|
-
const commitsAhead = (
|
|
130
|
-
await git.log([
|
|
131
|
-
`${remoteName}/${toBranch}..${remoteName}/${fromBranch}`,
|
|
132
|
-
])
|
|
133
|
-
).all;
|
|
134
|
-
|
|
135
|
-
if (!commitsAhead.length) {
|
|
136
|
-
throw new KnownError('No commit diff: nothing to deploy!');
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/** Get commits that are on {@link toBranch} but not on {@link fromBranch}. */
|
|
140
|
-
const commitsBehind = (
|
|
141
|
-
await git.log([
|
|
142
|
-
`${remoteName}/${fromBranch}..${remoteName}/${toBranch}`,
|
|
143
|
-
])
|
|
144
|
-
).all;
|
|
145
|
-
|
|
146
|
-
const requiresForcePush = commitsBehind.length > 0;
|
|
147
|
-
|
|
148
|
-
log.info(
|
|
149
|
-
`\n${requiresForcePush ? 'Only on' : 'Releasing from'} ${logColors.bold}${fromBranch}${logColors.reset}:`,
|
|
150
|
-
);
|
|
151
|
-
commitsAhead.forEach((commit, index) => {
|
|
152
|
-
log.faint(
|
|
153
|
-
` ${index + 1}. ${commit.hash.slice(0, 7)} (${commit.author_name}) - ${commit.message}`,
|
|
154
|
-
);
|
|
155
|
-
});
|
|
147
|
+
).all;
|
|
156
148
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
149
|
+
const requiresForcePush = commitsBehind.length > 0;
|
|
150
|
+
|
|
151
|
+
log.info(
|
|
152
|
+
`\n${requiresForcePush ? 'Only on' : 'Releasing from'} ${logColors.bold}${fromBranch}${logColors.reset}:`,
|
|
153
|
+
);
|
|
154
|
+
commitsAhead.forEach((commit, index) => {
|
|
160
155
|
log.faint(
|
|
161
156
|
` ${index + 1}. ${commit.hash.slice(0, 7)} (${commit.author_name}) - ${commit.message}`,
|
|
162
157
|
);
|
|
163
158
|
});
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
159
|
+
|
|
160
|
+
if (requiresForcePush) {
|
|
161
|
+
log.info(`\nOnly on ${logColors.bold}${toBranch}${logColors.reset}:`);
|
|
162
|
+
commitsBehind.forEach((commit, index) => {
|
|
163
|
+
log.faint(
|
|
164
|
+
` ${index + 1}. ${commit.hash.slice(0, 7)} (${commit.author_name}) - ${commit.message}`,
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const shouldPush =
|
|
170
|
+
bypassConfirmation ||
|
|
171
|
+
(await confirm({
|
|
172
|
+
message: requiresForcePush
|
|
173
|
+
? `\n${logColors.warning}Do you want to force push ${logColors.bold}${fromBranch}${logColors.normalWeight} to ${logColors.bold}${toBranch}${logColors.normalWeight}?\n\nThis will overwrite the commits only on ${logColors.bold}${toBranch}${logColors.normalWeight}.${logColors.reset}?`
|
|
174
|
+
: 'Ready to deploy?',
|
|
175
|
+
default: false,
|
|
176
|
+
}));
|
|
177
|
+
|
|
178
|
+
if (!shouldPush) {
|
|
179
|
+
throw new KnownError(`Deploy aborted.`);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (requiresForcePush) {
|
|
183
|
+
await git.push(remoteName, pushString, ['--force']);
|
|
184
|
+
log.warning(
|
|
185
|
+
`Force pushed ${logColors.bold}${fromBranch}${logColors.normalWeight} to ${logColors.bold}${toBranch}${logColors.reset}.`,
|
|
186
|
+
);
|
|
187
|
+
} else {
|
|
188
|
+
await git.push(remoteName, pushString);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
toBranchName: toBranch,
|
|
193
|
+
deployCommits: {
|
|
194
|
+
deployedCommits: commitsAhead,
|
|
195
|
+
overwrittenCommits: commitsBehind,
|
|
196
|
+
},
|
|
197
|
+
branchStatus: {
|
|
198
|
+
before: beforeCommit,
|
|
199
|
+
after: afterCommit,
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
},
|
|
203
|
+
);
|
|
199
204
|
}
|
|
@@ -53,10 +53,10 @@ function chunkSectionLines(lines: ReadonlyArray<string>): string[][] {
|
|
|
53
53
|
* @category Internal
|
|
54
54
|
*/
|
|
55
55
|
export async function sendNotificationToSlack({
|
|
56
|
-
branchConfig,
|
|
57
56
|
deployResult: {
|
|
58
57
|
deployCommits: {deployedCommits, overwrittenCommits},
|
|
59
58
|
branchStatus: {after, before},
|
|
59
|
+
toBranchName,
|
|
60
60
|
},
|
|
61
61
|
notification,
|
|
62
62
|
repoConfig,
|
|
@@ -86,7 +86,7 @@ export async function sendNotificationToSlack({
|
|
|
86
86
|
type: 'section',
|
|
87
87
|
text: {
|
|
88
88
|
type: 'mrkdwn',
|
|
89
|
-
text: `*${setFirstLetterCasing(repoConfig.name, StringCase.Upper)} ${setFirstLetterCasing(
|
|
89
|
+
text: `*${setFirstLetterCasing(repoConfig.name, StringCase.Upper)} ${setFirstLetterCasing(toBranchName, StringCase.Upper)}* Pushed`,
|
|
90
90
|
},
|
|
91
91
|
},
|
|
92
92
|
{
|