Skip to content

Commit

Permalink
Feat: Support include/exclude in github action (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
osdiab authored Nov 29, 2023
1 parent c5f895d commit 013e2c2
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 6 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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,import_bomb2
- name: Deploy with multiline exclude
uses: ./
with:
project: happy-rat-64
root: action/tests
entrypoint: include_exclude.ts
exclude: |
import_bomb1
import_bomb2
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ inputs:
import-map:
description: The path or URL to an import map file
required: false
include:
description: Only upload files that match this pattern (multiline and/or comma-separated)
required: false
exclude:
description: Exclude files that match this pattern (multiline and/or comma-separated)
required: false
root:
description: The path to the directory containing the code and assets to upload
required: false
Expand Down
6 changes: 3 additions & 3 deletions action/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -4006,10 +4006,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;
Expand Down Expand Up @@ -4054,5 +4054,5 @@ async function walk(cwd, dir, files, options) {
export { parseEntrypoint as parseEntrypoint };
export { API as API, APIError as APIError };
export { walk as walk };
export { fromFileUrl2 as fromFileUrl, resolve2 as resolve };
export { fromFileUrl2 as fromFileUrl, resolve2 as resolve, normalize3 as normalize };

11 changes: 9 additions & 2 deletions action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
API,
APIError,
fromFileUrl,
normalize,
parseEntrypoint,
resolve,
walk,
Expand All @@ -17,6 +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.getMultilineInput("include", {});
const exclude = core.getMultilineInput("exclude", {});
const cwd = resolve(process.cwd(), core.getInput("root", {}));

if (github.context.eventName === "pull_request") {
Expand Down Expand Up @@ -72,8 +75,12 @@ async function main() {
core.debug(`Discovering assets in "${cwd}"`);
const assets = new Map();
const entries = await walk(cwd, cwd, assets, {
include: undefined,
exclude: undefined,
include: include.flatMap((i) => i.split(",")).map((pattern) =>
normalize(pattern)
),
exclude: exclude.flatMap((e) => e.split(",")).map((pattern) =>
normalize(pattern)
),
});
core.debug(`Discovered ${assets.size} assets`);

Expand Down
11 changes: 11 additions & 0 deletions action/tests/hello.ts
Original file line number Diff line number Diff line change
@@ -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);
Empty file added action/tests/import_bomb1
Empty file.
Empty file added action/tests/import_bomb2
Empty file.
5 changes: 5 additions & 0 deletions action/tests/import_map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"imports": {
"std/": "https://deno.land/[email protected]/"
}
}
17 changes: 17 additions & 0 deletions action/tests/include_exclude.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
try {
await Deno.lstat("import_bomb1");
throw new Error("BOOM!");
} catch (e) {
if (!(e instanceof Deno.errors.NotFound)) {
throw e;
}
}
try {
await Deno.lstat("import_bomb2");
throw new Error("BOOM!");
} catch (e) {
if (!(e instanceof Deno.errors.NotFound)) {
throw e;
}
}
Deno.serve(() => new Response("Hello World"));

0 comments on commit 013e2c2

Please sign in to comment.