Skip to content

Commit

Permalink
Merge pull request #3 from datatheorem/convert-to-js-action
Browse files Browse the repository at this point in the history
Convert to JS action for cross platform compatibility
  • Loading branch information
victowang committed Jun 3, 2022
2 parents 5d6ce97 + cd2a30d commit 9634593
Show file tree
Hide file tree
Showing 376 changed files with 1,105,065 additions and 63 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.apk
*.ipa
.idea
7 changes: 0 additions & 7 deletions Dockerfile

This file was deleted.

15 changes: 3 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,9 @@ jobs:
java-version: 1.8
- name: Build debug APK
run: bash ./gradlew assembleDebug
- name: Upload APK artifact
uses: actions/upload-artifact@v2
with:
name: app
path: app/build/outputs/apk/debug/app-debug.apk
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: app
- name: Upload to Data Theorem
uses: datatheorem/datatheorem-mobile-secure-action@v1
uses: datatheorem/datatheorem-mobile-secure-action@v2
with:
UPLOAD_BINARY_PATH: "./app-debug.apk"
UPLOAD_BINARY_PATH: "./app/build/outputs/apk/debug/app-debug.apk"
DT_UPLOAD_API_KEY: ${{ secrets.DT_UPLOAD_API_KEY }}
```
```
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ inputs:
description: 'Path to the app to upload'
required: true
runs:
using: 'docker'
image: 'Dockerfile'
using: 'node16'
main: 'main.js'
branding:
color: 'blue'
icon: 'arrow-up-circle'
42 changes: 0 additions & 42 deletions entrypoint.sh

This file was deleted.

80 changes: 80 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = require("@actions/core");
const fetch = require('node-fetch');
const FormData = require("form-data");
const fs = require("fs");
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
// Get inputs
const dt_upload_api_key = core.getInput("DT_UPLOAD_API_KEY");
const input_binary_path = core.getInput("UPLOAD_BINARY_PATH");
core.setSecret(dt_upload_api_key);
if (!fs.existsSync(input_binary_path)) {
throw new Error("Input file does not exist at " + input_binary_path);
}
// retry upload 3 times
for (let loop_idx = 0; loop_idx < 3; loop_idx++) {
// Send the auth request to get the upload URL
const auth_response = yield fetch("https://api.securetheorem.com/uploadapi/v1/upload_init", {
method: 'POST',
headers: {
Authorization: "APIKey " + dt_upload_api_key,
Accept: "application/json",
"Content-Type": "application/json",
},
});
let auth_json;
try {
auth_json = yield auth_response.json();
}
catch (err) {
core.setFailed(err);
}
if (auth_response.status !== 200) {
// handles auth failure
core.setFailed(auth_json);
break;
}
const form = new FormData();
form.append('file', fs.createReadStream(input_binary_path));
// Send the scan request with file
const response = yield fetch(auth_json.upload_url, {
method: 'POST',
body: form,
});
let jsonformat;
try {
jsonformat = yield response.json();
}
catch (err) {
core.setFailed(err);
}
// Check the response
console.log(jsonformat);
if (response.status === 200) {
core.setOutput('response', jsonformat);
;
break;
}
else if (loop_idx == 2) {
core.setFailed(jsonformat);
}
}
}
catch (err) {
core.setFailed(err.message);
}
});
}
run();
79 changes: 79 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import core = require('@actions/core');
const fetch = require('node-fetch');
import FormData = require('form-data');
import fs = require('fs');


async function run() {
try {
// Get inputs
const dt_upload_api_key: string = core.getInput("DT_UPLOAD_API_KEY");
const input_binary_path: string = core.getInput("UPLOAD_BINARY_PATH");
core.setSecret(dt_upload_api_key)

if (!fs.existsSync(input_binary_path)) {
throw new Error("Input file does not exist at :" + input_binary_path);
}

// retry upload 3 times
for (let loop_idx = 0; loop_idx < 3; loop_idx++) {

// Send the auth request to get the upload URL
const auth_response = await fetch(
"https://api.securetheorem.com/uploadapi/v1/upload_init",
{
method: 'POST',
headers: {
Authorization: "APIKey " + dt_upload_api_key,
Accept: "application/json",
"Content-Type": "application/json",
},
}
);

let auth_json
try {
auth_json = await auth_response.json()
} catch (err) {core.setFailed(err);}

if (auth_response.status !== 200) {
// handles auth failure
core.setFailed(auth_json);
break;
}

const form = new FormData();
form.append('file', fs.createReadStream(input_binary_path));

// Send the scan request with file
const response = await fetch(
auth_json.upload_url,
{
method: 'POST',
body: form,
}
);

let jsonformat

try{
jsonformat = await response.json();
} catch (err) {core.setFailed(err)}

// Check the response
console.log(jsonformat);
if (response.status === 200) {
core.setOutput('response', jsonformat);;
break;
} else if (loop_idx == 2) {
core.setFailed(jsonformat);
}
}

} catch (err) {
core.setFailed(err.message);
}
}

run();

1 change: 1 addition & 0 deletions node_modules/.bin/tsc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/tsserver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions node_modules/@actions/core/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9634593

Please sign in to comment.