From c7cfd187f80f489e095aa2ab98811846e46e8b89 Mon Sep 17 00:00:00 2001 From: Arnau Orriols Date: Tue, 28 Nov 2023 15:36:46 +0100 Subject: [PATCH] use getMultilineInput --- .github/workflows/test.yml | 25 ++++++++++++++++++++++++- action/deps.js | 4 ++-- action/index.js | 8 ++++---- action/tests/hello.ts | 11 +++++++++++ action/tests/import_bomb1.ts | 1 + action/tests/import_bomb2.ts | 1 + action/tests/import_map.json | 5 +++++ action/tests/include_exclude.ts | 15 +++++++++++++++ 8 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 action/tests/hello.ts create mode 100644 action/tests/import_bomb1.ts create mode 100644 action/tests/import_bomb2.ts create mode 100644 action/tests/import_map.json create mode 100644 action/tests/include_exclude.ts diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c142091a..efebf7c8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,29 @@ jobs: uses: ./ with: project: happy-rat-64 - root: examples + root: action/tests entrypoint: hello.ts import-map: ./import_map.json + - name: Deploy with single include + uses: ./ + with: + project: happy-rat-64 + root: action/tests + entrypoint: include_exclude.ts + include: include_exclude.ts + - name: Deploy with comma-separated exclude + uses: ./ + with: + project: happy-rat-64 + root: action/tests + entrypoint: include_exclude.ts + exclude: import_bomb1.ts, import_bomb2.ts + - name: Deploy with multiline exclude + uses: ./ + with: + project: happy-rat-64 + root: action/tests + entrypoint: include_exclude.ts + exclude: | + import_bomb1.ts + import_bomb2.ts diff --git a/action/deps.js b/action/deps.js index 5484b01b..9a5c55e9 100644 --- a/action/deps.js +++ b/action/deps.js @@ -2584,10 +2584,10 @@ async function calculateGitSha1(bytes) { return hashHex; } function include(path, include, exclude) { - if (include && !include.some((pattern)=>path.startsWith(pattern))) { + if (include.length && !include.some((pattern)=>path.startsWith(pattern))) { return false; } - if (exclude && exclude.some((pattern)=>path.startsWith(pattern))) { + if (exclude.length && exclude.some((pattern)=>path.startsWith(pattern))) { return false; } return true; diff --git a/action/index.js b/action/index.js index 66fc4c92..77015841 100644 --- a/action/index.js +++ b/action/index.js @@ -18,8 +18,8 @@ async function main() { const projectId = core.getInput("project", { required: true }); const entrypoint = core.getInput("entrypoint", { required: true }); const importMap = core.getInput("import-map", {}); - const include = core.getInput("include", {}); - const exclude = core.getInput("exclude", {}); + const include = core.getMultilineInput("include", {}); + const exclude = core.getMultilineInput("exclude", {}); const cwd = resolve(process.cwd(), core.getInput("root", {})); if (github.context.eventName === "pull_request") { @@ -75,8 +75,8 @@ async function main() { core.debug(`Discovering assets in "${cwd}"`); const assets = new Map(); const entries = await walk(cwd, cwd, assets, { - include: include ? include.split(",").map(pattern => normalize(pattern)): undefined, - exclude: exclude ? exclude.split(",").map(pattern => normalize(pattern)): undefined, + include: include.split(",").map(pattern => normalize(pattern)), + exclude: exclude.split(",").map(pattern => normalize(pattern)), }); core.debug(`Discovered ${assets.size} assets`); diff --git a/action/tests/hello.ts b/action/tests/hello.ts new file mode 100644 index 00000000..805c71ca --- /dev/null +++ b/action/tests/hello.ts @@ -0,0 +1,11 @@ +import { serve } from "std/http/server.ts"; + +async function handler(_req: Request) { + const text = await Deno.readTextFile(new URL(import.meta.url)); + return new Response(text, { + headers: { "content-type": "text/plain; charset=utf8" }, + }); +} + +console.log("Listening on http://localhost:8000"); +serve(handler); diff --git a/action/tests/import_bomb1.ts b/action/tests/import_bomb1.ts new file mode 100644 index 00000000..04962fa8 --- /dev/null +++ b/action/tests/import_bomb1.ts @@ -0,0 +1 @@ +throw new Error("BOOM!"); diff --git a/action/tests/import_bomb2.ts b/action/tests/import_bomb2.ts new file mode 100644 index 00000000..04962fa8 --- /dev/null +++ b/action/tests/import_bomb2.ts @@ -0,0 +1 @@ +throw new Error("BOOM!"); diff --git a/action/tests/import_map.json b/action/tests/import_map.json new file mode 100644 index 00000000..62266803 --- /dev/null +++ b/action/tests/import_map.json @@ -0,0 +1,5 @@ +{ + "imports": { + "std/": "https://deno.land/std@0.128.0/" + } +} diff --git a/action/tests/include_exclude.ts b/action/tests/include_exclude.ts new file mode 100644 index 00000000..acb97b4f --- /dev/null +++ b/action/tests/include_exclude.ts @@ -0,0 +1,15 @@ +try { + const q = await import("./import_bomb1.ts"); +} catch (e) { + if (!(e instanceof Deno.errors.NotFound)) { + throw e; + } +} +try { + const q = await import("./import_bomb2.ts"); +} catch (e) { + if (!(e instanceof Deno.errors.NotFound)) { + throw e; + } +} +Deno.serve(() => new Response("Hello World"));