projektor-publish 3.5.1 → 3.8.0
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/package.json +6 -6
- package/publish-functional-test/package.json +4 -4
- package/src/index.js +71 -27
- package/src/publish-coverage.js +5 -3
- package/src/publish.js +11 -4
- package/src/slack.js +35 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "projektor-publish",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.0",
|
|
4
4
|
"homepage": "https://projektor.dev/docs/node-script/",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"projektor": "env-cmd -f ~/.env projektor-publish"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"axios": "0.21.
|
|
20
|
+
"axios": "0.21.2",
|
|
21
21
|
"glob": "7.1.4",
|
|
22
22
|
"lodash": "4.17.21",
|
|
23
23
|
"minimist": "1.2.5",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"axios-mock-adapter": "1.17.0",
|
|
28
28
|
"env-cmd": "10.1.0",
|
|
29
|
-
"jest": "27.
|
|
30
|
-
"jest-junit": "
|
|
31
|
-
"prettier": "2.
|
|
32
|
-
"projektor-publish": "3.
|
|
29
|
+
"jest": "27.2.5",
|
|
30
|
+
"jest-junit": "13.0.0",
|
|
31
|
+
"prettier": "2.4.1",
|
|
32
|
+
"projektor-publish": "3.7.0",
|
|
33
33
|
"wait-for-expect": "3.0.2"
|
|
34
34
|
},
|
|
35
35
|
"jest": {
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
"format": "prettier --write src/**/*.js"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"axios": "0.21.
|
|
12
|
+
"axios": "0.21.2",
|
|
13
13
|
"env-cmd": "10.1.0",
|
|
14
|
-
"jest": "
|
|
15
|
-
"jest-junit": "
|
|
16
|
-
"prettier": "2.1
|
|
14
|
+
"jest": "27.2.5",
|
|
15
|
+
"jest-junit": "13.0.0",
|
|
16
|
+
"prettier": "2.4.1",
|
|
17
17
|
"projektor-publish": "file:../",
|
|
18
18
|
"wait-for-expect": "3.0.1"
|
|
19
19
|
}
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { writeNoResultsSlackMessageFileToDisk } = require("./slack");
|
|
2
|
+
|
|
1
3
|
async function runCLI(cliArgs, publishToken, defaultConfigFilePath) {
|
|
2
4
|
const parsedArgs = require("minimist")(cliArgs, {
|
|
3
5
|
boolean: "exitWithFailure",
|
|
@@ -23,6 +25,7 @@ async function run(args, env, publishToken, defaultConfigFilePath) {
|
|
|
23
25
|
let performanceFileGlobs;
|
|
24
26
|
let baseDirectoryPath;
|
|
25
27
|
let exitWithFailure;
|
|
28
|
+
let failOnPublishError;
|
|
26
29
|
let writeSlackMessageFile;
|
|
27
30
|
let slackMessageFileName;
|
|
28
31
|
let slackProjectName;
|
|
@@ -32,6 +35,7 @@ async function run(args, env, publishToken, defaultConfigFilePath) {
|
|
|
32
35
|
let resultsMaxSizeMB;
|
|
33
36
|
let attachmentMaxSizeMB;
|
|
34
37
|
let groupResults;
|
|
38
|
+
let gitMainBranchNames;
|
|
35
39
|
|
|
36
40
|
const configFilePath = args.configFile || defaultConfigFilePath;
|
|
37
41
|
|
|
@@ -45,7 +49,10 @@ async function run(args, env, publishToken, defaultConfigFilePath) {
|
|
|
45
49
|
coverageFileGlobs = config.coverage;
|
|
46
50
|
performanceFileGlobs = config.performance;
|
|
47
51
|
baseDirectoryPath = config.baseDirectoryPath;
|
|
52
|
+
|
|
48
53
|
exitWithFailure = config.exitWithFailure;
|
|
54
|
+
failOnPublishError = config.failOnPublishError;
|
|
55
|
+
|
|
49
56
|
writeSlackMessageFile = config.writeSlackMessageFile;
|
|
50
57
|
slackMessageFileName = config.slackMessageFileName;
|
|
51
58
|
slackProjectName = config.slackProjectName;
|
|
@@ -55,6 +62,7 @@ async function run(args, env, publishToken, defaultConfigFilePath) {
|
|
|
55
62
|
resultsMaxSizeMB = config.resultsMaxSizeMB;
|
|
56
63
|
attachmentMaxSizeMB = config.attachmentMaxSizeMB;
|
|
57
64
|
groupResults = config.groupResults;
|
|
65
|
+
gitMainBranchNames = config.gitMainBranchNames;
|
|
58
66
|
} else {
|
|
59
67
|
serverUrl = args.serverUrl;
|
|
60
68
|
resultsFileGlobs = args.resultsFileGlobs;
|
|
@@ -75,7 +83,10 @@ async function run(args, env, publishToken, defaultConfigFilePath) {
|
|
|
75
83
|
: [args.performance];
|
|
76
84
|
}
|
|
77
85
|
baseDirectoryPath = args.baseDirectoryPath;
|
|
86
|
+
|
|
78
87
|
exitWithFailure = args.exitWithFailure;
|
|
88
|
+
failOnPublishError = args.failOnPublishError;
|
|
89
|
+
|
|
79
90
|
writeSlackMessageFile = args.writeSlackMessageFile;
|
|
80
91
|
slackMessageFileName = args.slackMessageFileName;
|
|
81
92
|
slackProjectName = args.slackProjectName;
|
|
@@ -85,6 +96,12 @@ async function run(args, env, publishToken, defaultConfigFilePath) {
|
|
|
85
96
|
resultsMaxSizeMB = args.resultsMaxSizeMB;
|
|
86
97
|
attachmentMaxSizeMB = args.attachmentMaxSizeMB;
|
|
87
98
|
groupResults = args.groupResults;
|
|
99
|
+
|
|
100
|
+
if (args.gitMainBranchNames) {
|
|
101
|
+
gitMainBranchNames = Array.isArray(args.gitMainBranchNames)
|
|
102
|
+
? args.gitMainBranchNames
|
|
103
|
+
: args.gitMainBranchNames.split(",");
|
|
104
|
+
}
|
|
88
105
|
}
|
|
89
106
|
|
|
90
107
|
if (_.isNil(compressionEnabled)) {
|
|
@@ -103,6 +120,10 @@ async function run(args, env, publishToken, defaultConfigFilePath) {
|
|
|
103
120
|
resultsMaxSizeMB = 20;
|
|
104
121
|
}
|
|
105
122
|
|
|
123
|
+
if (_.isNil(gitMainBranchNames)) {
|
|
124
|
+
gitMainBranchNames = ["main", "master"];
|
|
125
|
+
}
|
|
126
|
+
|
|
106
127
|
if (resultsFileGlobs || performanceFileGlobs) {
|
|
107
128
|
// https://go-vela.github.io/docs/concepts/pipeline/steps/environment/
|
|
108
129
|
// https://docs.github.com/en/actions/reference/environment-variables
|
|
@@ -124,28 +145,36 @@ async function run(args, env, publishToken, defaultConfigFilePath) {
|
|
|
124
145
|
group = buildNumber;
|
|
125
146
|
}
|
|
126
147
|
|
|
127
|
-
const {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
148
|
+
const {
|
|
149
|
+
resultsBlob,
|
|
150
|
+
performanceResults,
|
|
151
|
+
reportUrl,
|
|
152
|
+
publicId,
|
|
153
|
+
error: publishError,
|
|
154
|
+
} = await collectAndSendResults(
|
|
155
|
+
serverUrl,
|
|
156
|
+
publishToken,
|
|
157
|
+
resultsFileGlobs,
|
|
158
|
+
attachmentFileGlobs,
|
|
159
|
+
coverageFileGlobs,
|
|
160
|
+
performanceFileGlobs,
|
|
161
|
+
gitRepoName,
|
|
162
|
+
gitBranchName,
|
|
163
|
+
gitCommitSha,
|
|
164
|
+
gitPullRequestNumber,
|
|
165
|
+
projectName,
|
|
166
|
+
isCI,
|
|
167
|
+
group,
|
|
168
|
+
compressionEnabled,
|
|
169
|
+
baseDirectoryPath,
|
|
170
|
+
resultsMaxSizeMB,
|
|
171
|
+
attachmentMaxSizeMB,
|
|
172
|
+
gitMainBranchNames
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
const hasResults = resultsBlob || performanceFileGlobs;
|
|
147
176
|
|
|
148
|
-
if (!
|
|
177
|
+
if (!hasResults) {
|
|
149
178
|
console.log(
|
|
150
179
|
`No test results files found in locations ${resultsFileGlobs}`
|
|
151
180
|
);
|
|
@@ -162,12 +191,27 @@ async function run(args, env, publishToken, defaultConfigFilePath) {
|
|
|
162
191
|
}
|
|
163
192
|
|
|
164
193
|
if (writeSlackMessageFile) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
194
|
+
const messageFileName =
|
|
195
|
+
slackMessageFileName || "projektor_failure_message.json";
|
|
196
|
+
const messageProjectName = slackProjectName || projectName;
|
|
197
|
+
|
|
198
|
+
if (hasResults) {
|
|
199
|
+
writeSlackMessageFileToDisk(
|
|
200
|
+
reportUrl,
|
|
201
|
+
messageFileName,
|
|
202
|
+
messageProjectName,
|
|
203
|
+
containsTestFailure(resultsBlob)
|
|
204
|
+
);
|
|
205
|
+
} else {
|
|
206
|
+
writeNoResultsSlackMessageFileToDisk(
|
|
207
|
+
messageFileName,
|
|
208
|
+
messageProjectName
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (publishError && failOnPublishError) {
|
|
214
|
+
process.exitCode = 1;
|
|
171
215
|
}
|
|
172
216
|
|
|
173
217
|
if (exitWithFailure && containsTestFailure(resultsBlob)) {
|
package/src/publish-coverage.js
CHANGED
|
@@ -3,9 +3,11 @@ const { collectFileContents } = require("./file-utils");
|
|
|
3
3
|
const collectCoverage = (coverageFileGlobs, baseDirectoryPath) => {
|
|
4
4
|
const coverageFiles = collectFileContents(coverageFileGlobs);
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
if (coverageFileGlobs) {
|
|
7
|
+
console.log(
|
|
8
|
+
`Found ${coverageFiles.length} coverage file(s) in ${coverageFileGlobs}`
|
|
9
|
+
);
|
|
10
|
+
}
|
|
9
11
|
|
|
10
12
|
return coverageFiles.map((coverageFile) => {
|
|
11
13
|
const coverageFilePayload = {
|
package/src/publish.js
CHANGED
|
@@ -53,7 +53,8 @@ const sendResults = async (
|
|
|
53
53
|
isCI,
|
|
54
54
|
group,
|
|
55
55
|
compressionEnabled,
|
|
56
|
-
resultsMaxSizeMB
|
|
56
|
+
resultsMaxSizeMB,
|
|
57
|
+
gitMainBranchNames
|
|
57
58
|
) => {
|
|
58
59
|
const headers = {};
|
|
59
60
|
|
|
@@ -82,7 +83,10 @@ const sendResults = async (
|
|
|
82
83
|
git: {
|
|
83
84
|
repoName: gitRepoName,
|
|
84
85
|
branchName: gitBranchName,
|
|
85
|
-
isMainBranch:
|
|
86
|
+
isMainBranch:
|
|
87
|
+
gitBranchName &&
|
|
88
|
+
gitMainBranchNames &&
|
|
89
|
+
gitMainBranchNames.includes(gitBranchName),
|
|
86
90
|
projectName,
|
|
87
91
|
commitSha: gitCommitSha,
|
|
88
92
|
pullRequestNumber: gitPullRequestNumber,
|
|
@@ -148,7 +152,8 @@ const collectAndSendResults = async (
|
|
|
148
152
|
compressionEnabled,
|
|
149
153
|
baseDirectoryPath,
|
|
150
154
|
resultsMaxSizeMB,
|
|
151
|
-
attachmentMaxSizeMB
|
|
155
|
+
attachmentMaxSizeMB,
|
|
156
|
+
gitMainBranchNames
|
|
152
157
|
) => {
|
|
153
158
|
console.log(
|
|
154
159
|
createResultsLogMessage(resultsFileGlobs, coverageFileGlobs, serverUrl)
|
|
@@ -177,7 +182,8 @@ const collectAndSendResults = async (
|
|
|
177
182
|
isCI,
|
|
178
183
|
group,
|
|
179
184
|
compressionEnabled,
|
|
180
|
-
resultsMaxSizeMB
|
|
185
|
+
resultsMaxSizeMB,
|
|
186
|
+
gitMainBranchNames
|
|
181
187
|
);
|
|
182
188
|
|
|
183
189
|
const publicId = resultsResponseData.id;
|
|
@@ -207,6 +213,7 @@ const collectAndSendResults = async (
|
|
|
207
213
|
performanceResults,
|
|
208
214
|
publicId: null,
|
|
209
215
|
reportUrl: null,
|
|
216
|
+
error: e,
|
|
210
217
|
};
|
|
211
218
|
}
|
|
212
219
|
} else {
|
package/src/slack.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
|
|
1
3
|
function writeSlackMessageFileToDisk(
|
|
2
4
|
reportUrl,
|
|
3
5
|
slackMessageFileName,
|
|
@@ -45,7 +47,40 @@ function createSlackMessageJson(
|
|
|
45
47
|
return JSON.stringify(message);
|
|
46
48
|
}
|
|
47
49
|
|
|
50
|
+
function writeNoResultsSlackMessageFileToDisk(
|
|
51
|
+
slackMessageFileName,
|
|
52
|
+
projectName
|
|
53
|
+
) {
|
|
54
|
+
const fs = require("fs");
|
|
55
|
+
|
|
56
|
+
const messageJson = createNoResultsSlackMessageJson(projectName);
|
|
57
|
+
|
|
58
|
+
fs.writeFileSync(slackMessageFileName, messageJson);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function createNoResultsSlackMessageJson(projectName, currentTimestamp) {
|
|
62
|
+
const projectNameToDisplay = projectName || "";
|
|
63
|
+
|
|
64
|
+
const message = {
|
|
65
|
+
attachments: [
|
|
66
|
+
{
|
|
67
|
+
fallback: "Projektor test report",
|
|
68
|
+
color: "#FFFF00",
|
|
69
|
+
pretext: "No test results found",
|
|
70
|
+
title: "Projektor test report",
|
|
71
|
+
text: `No test results found to publish in project ${projectNameToDisplay}`,
|
|
72
|
+
footer: "Projektor",
|
|
73
|
+
ts: currentTimestamp || new Date().getTime(),
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return JSON.stringify(message);
|
|
79
|
+
}
|
|
80
|
+
|
|
48
81
|
module.exports = {
|
|
49
82
|
writeSlackMessageFileToDisk,
|
|
50
83
|
createSlackMessageJson,
|
|
84
|
+
writeNoResultsSlackMessageFileToDisk,
|
|
85
|
+
createNoResultsSlackMessageJson,
|
|
51
86
|
};
|