Skip to content

Commit

Permalink
Switch to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
sandhose committed Jul 1, 2024
1 parent f58ac89 commit a32ba96
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 53 deletions.
29 changes: 15 additions & 14 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26804,42 +26804,43 @@ module.exports = parseParams
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
(() => {
const core = __nccwpck_require__(2186);
"use strict";
var exports = __webpack_exports__;

Object.defineProperty(exports, "__esModule", ({ value: true }));
const core_1 = __nccwpck_require__(2186);
function parseJsonInput(param_name) {
const param_val = core.getInput(param_name);
const param_val = (0, core_1.getInput)(param_name);
try {
return JSON.parse(param_val);
} catch (error) {
}
catch (error) {
throw new Error(`Invalid '${param_name}' input ${param_val}: ${error.message}`);
}
}


function main() {
const needs = parseJsonInput('needs');
const skippable = core.getMultilineInput('skippable');

const needs = parseJsonInput("needs");
const skippable = (0, core_1.getMultilineInput)("skippable");
console.debug(`needs: ${JSON.stringify(needs)}`);
console.debug(`skippable: ${JSON.stringify(skippable)}`);
for (const job_id of Object.keys(needs)) {
const result = needs[job_id].result;
console.log(`Job ${job_id} returned ${result}`);
if (result == 'skipped' && skippable.includes(job_id)) {
if (result == "skipped" && skippable.includes(job_id)) {
continue;
}
if (result != 'success') {
if (result != "success") {
throw new Error(`Job ${job_id} returned ${result}`);
}
}
}

try {
main();
} catch (error) {
core.setFailed(error.message);
}
catch (error) {
(0, core_1.setFailed)(error.message);
}

})();
Expand Down
35 changes: 0 additions & 35 deletions index.js

This file was deleted.

36 changes: 36 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { getInput, getMultilineInput, setFailed } from "@actions/core";

function parseJsonInput(param_name: string) {
const param_val = getInput(param_name);
try {
return JSON.parse(param_val);
} catch (error) {
throw new Error(
`Invalid '${param_name}' input ${param_val}: ${(error as Error).message}`,
);
}
}

function main() {
const needs = parseJsonInput("needs");
const skippable = getMultilineInput("skippable");

console.debug(`needs: ${JSON.stringify(needs)}`);
console.debug(`skippable: ${JSON.stringify(skippable)}`);
for (const job_id of Object.keys(needs)) {
const result = needs[job_id].result;
console.log(`Job ${job_id} returned ${result}`);
if (result == "skipped" && skippable.includes(job_id)) {
continue;
}
if (result != "success") {
throw new Error(`Job ${job_id} returned ${result}`);
}
}
}

try {
main();
} catch (error) {
setFailed((error as Error).message);
}
66 changes: 65 additions & 1 deletion package-lock.json

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

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "done-action",
"version": "1.0.0",
"description": "",
"main": "index.js",
"main": "dist/index.js",
"scripts": {
"build": "ncc build index.js --license licenses.txt"
"build": "ncc build index.ts --license licenses.txt"
},
"repository": {
"type": "git",
Expand All @@ -21,6 +21,9 @@
"@actions/core": "^1.10.1"
},
"devDependencies": {
"@vercel/ncc": "^0.38.1"
"@tsconfig/node20": "^20.1.4",
"@types/node": "^20.14.9",
"@vercel/ncc": "^0.38.1",
"typescript": "^5.5.2"
}
}
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@tsconfig/node20/tsconfig.json"
}

0 comments on commit a32ba96

Please sign in to comment.