Skip to content

Commit 72d0cfb

Browse files
authored
Merge pull request #7 from datatheorem/SASB-5115-support-sourcemap-uploads
Sasb 5115 support sourcemap uploads
2 parents e26a4f4 + 0e6846c commit 72d0cfb

File tree

3 files changed

+209
-166
lines changed

3 files changed

+209
-166
lines changed

action.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ inputs:
99
UPLOAD_BINARY_PATH:
1010
description: >
1111
Path to the app to upload.
12-
12+
1313
You can use a glob pattern to indicate variable parts of the build's file name (for example, if the app's version number or build date is in the file name).
1414
Examples of glob patterns:
1515
- `app-*.apk` : search for any apk starting with `app-` in workspace root directory
1616
- `**/app-*.ipa` : search for any ipa starting with `app-` in any subdirectory of the workspace
1717
- `{,**/}app-debug*.*` : search for any file containing `app-debug` in root the directory or in any subdirectory of the workspace
18-
18+
1919
If multiple files match the provided pattern all matching files will be uploaded. The pattern should not match more than 3 files.
2020
required: true
21+
SOURCEMAP_FILE_PATH:
22+
description: >
23+
Path to the sourcemap file used to map obfuscated symbols to their original code name
24+
required: false
2125
USERNAME:
2226
description: >
2327
Username to be used for authenticated testing of the application. If provided, will override the previosly provided value.
@@ -32,22 +36,22 @@ inputs:
3236
required: false
3337
RELEASE_ID:
3438
description: >
35-
A custom ID associated with the binary being submitted, since the app version may not change very often.
39+
A custom ID associated with the binary being submitted, since the app version may not change very often.
3640
It is recommended that you use a unique value for this, such as the CI/CD job ID.
3741
If not set, Data Theorem will assign the binary a release_id.
3842
required: false
3943
PLATFORM_VARIANT:
4044
description: >
41-
The variant of the platform to use for scanning; Currently, the accepted value is
45+
The variant of the platform to use for scanning; Currently, the accepted value is
4246
IOS_ON_MAC (scan an iOS build on an Apple Silicon Mac instead of on an iOS device, in order to exercise code paths that are specific to Macs.)
4347
required: false
4448
EXTERNAL_ID:
4549
description: >
4650
The external_id field represents your organization’s custom identifier for the app, if any.
47-
required: false
51+
required: false
4852
runs:
4953
using: 'node16'
5054
main: 'main.js'
5155
branding:
5256
color: 'blue'
53-
icon: 'arrow-up-circle'
57+
icon: 'arrow-up-circle'

main.js

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
99
});
1010
};
1111
var __generator = (this && this.__generator) || function (thisArg, body) {
12-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1414
function verb(n) { return function (v) { return step([n, v]); }; }
1515
function step(op) {
1616
if (f) throw new TypeError("Generator is already executing.");
17-
while (_) try {
17+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
1818
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1919
if (y = 0, t) op = [op[0] & 2, t.value];
2020
switch (op[0]) {
@@ -35,7 +35,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
3535
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
3636
}
3737
};
38-
exports.__esModule = true;
38+
Object.defineProperty(exports, "__esModule", { value: true });
3939
var core = require("@actions/core");
4040
var fetch = require("node-fetch");
4141
var glob = require("glob");
@@ -44,15 +44,32 @@ var fs = require("fs");
4444
// Global constants
4545
var maxUploadFiles = 3; // no more than 3 files can be uploaded at a time
4646
var maxRetries = 3; // max number of uploads to retry
47+
function upload_step_init(dt_upload_api_key) {
48+
return __awaiter(this, void 0, void 0, function () {
49+
return __generator(this, function (_a) {
50+
switch (_a.label) {
51+
case 0: return [4 /*yield*/, fetch("https://api.securetheorem.com/uploadapi/v1/upload_init", {
52+
"headers": {
53+
"Accept": "application/json",
54+
"Authorization": "APIKey " + dt_upload_api_key,
55+
"Content-Type": "application/json",
56+
},
57+
"method": "POST",
58+
})];
59+
case 1: return [2 /*return*/, _a.sent()];
60+
}
61+
});
62+
});
63+
}
4764
function run() {
4865
return __awaiter(this, void 0, void 0, function () {
49-
var dt_upload_api_key, input_binary_path, username, password, comments, release_id, platform_variant, external_id, files, file_idx, output, _i, files_1, file_path, form, loop_idx, auth_response, auth_json, err_1, response, jsonformat, err_2, err_3;
66+
var dt_upload_api_key, input_binary_path, sourcemap_file_path, username, password, comments, release_id, platform_variant, external_id, files, file_idx, output, _i, files_1, file_path, form, loop_idx, auth_response, auth_json, err_1, response, jsonformat, err_2;
5067
return __generator(this, function (_a) {
5168
switch (_a.label) {
5269
case 0:
53-
_a.trys.push([0, 16, , 17]);
5470
dt_upload_api_key = core.getInput("DT_UPLOAD_API_KEY");
5571
input_binary_path = core.getInput("UPLOAD_BINARY_PATH");
72+
sourcemap_file_path = core.getInput("SOURCEMAP_FILE_PATH");
5673
username = core.getInput("USERNAME");
5774
password = core.getInput("PASSWORD");
5875
comments = core.getInput("COMMENTS");
@@ -90,7 +107,19 @@ function run() {
90107
console.log("Processing file " + file_path + " (" + file_idx + " of " + files.length + ").");
91108
form = new FormData();
92109
form.append("file", fs.createReadStream(file_path));
93-
// only append optional fields if explicitly set
110+
if (sourcemap_file_path) {
111+
if (!fs.existsSync(sourcemap_file_path)) {
112+
throw new Error("Could not access file:" + sourcemap_file_path);
113+
}
114+
try {
115+
form.append("sourcemap", fs.createReadStream(sourcemap_file_path));
116+
}
117+
catch (err) {
118+
core.setFailed(err);
119+
return [2 /*return*/];
120+
}
121+
}
122+
// only append optional fields if explicitly set
94123
if (username) {
95124
form.append("username", username);
96125
console.log("DAST username set to: " + username);
@@ -119,14 +148,7 @@ function run() {
119148
_a.label = 2;
120149
case 2:
121150
if (!(loop_idx < maxRetries)) return [3 /*break*/, 14];
122-
return [4 /*yield*/, fetch("https://api.securetheorem.com/uploadapi/v1/upload_init", {
123-
method: "POST",
124-
headers: {
125-
Authorization: "APIKey " + dt_upload_api_key,
126-
Accept: "application/json",
127-
"Content-Type": "application/json"
128-
}
129-
})];
151+
return [4 /*yield*/, upload_step_init(dt_upload_api_key)];
130152
case 3:
131153
auth_response = _a.sent();
132154
auth_json = void 0;
@@ -150,8 +172,8 @@ function run() {
150172
// Send the scan request with file
151173
console.log("Starting upload...");
152174
return [4 /*yield*/, fetch(auth_json.upload_url, {
153-
method: "POST",
154-
body: form
175+
"method": "POST",
176+
"body": form,
155177
})];
156178
case 8:
157179
response = _a.sent();
@@ -170,10 +192,10 @@ function run() {
170192
return [3 /*break*/, 12];
171193
case 12:
172194
output.push(jsonformat);
173-
console.log("Response: HHTP/" + response.status);
195+
console.log("Response: HTTP/" + response.status);
174196
console.log(jsonformat);
175197
// Check the response
176-
// If we receive 409 (ownership conflict) or if this is the last try, bail out
198+
// If we receive 409 (ownership conflict) or if this is the last try, bail out
177199
if (response.status === 200) {
178200
return [3 /*break*/, 14];
179201
}
@@ -194,14 +216,14 @@ function run() {
194216
case 15:
195217
core.setOutput("responses", output);
196218
core.setOutput("response", output[0]); // keep the `response` output as the response of the first file upload to maintain compatibility
197-
return [3 /*break*/, 17];
198-
case 16:
199-
err_3 = _a.sent();
200-
core.setFailed(err_3.message);
201-
return [3 /*break*/, 17];
202-
case 17: return [2 /*return*/];
219+
return [2 /*return*/];
203220
}
204221
});
205222
});
206223
}
207-
run();
224+
try {
225+
run();
226+
}
227+
catch (err) {
228+
core.setFailed(err.message);
229+
}

0 commit comments

Comments
 (0)