Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Support include/exclude in github action #135

Merged
merged 12 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (comma-separated)
required: false
exclude:
description: Exclude files that match this pattern (comma-separated)
required: false
root:
description: The path to the directory containing the code and assets to upload
required: false
Expand Down
2 changes: 1 addition & 1 deletion action/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2632,5 +2632,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 };

7 changes: 5 additions & 2 deletions action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
parseEntrypoint,
resolve,
walk,
normalize,
} from "./deps.js";

// The origin of the server to make Deploy requests to.
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.getInput("include", {});
const exclude = core.getInput("exclude", {});
const cwd = resolve(process.cwd(), core.getInput("root", {}));

if (github.context.eventName === "pull_request") {
Expand Down Expand Up @@ -72,8 +75,8 @@ 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 ? include.split(",").map(pattern => normalize(pattern)): undefined,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline separated strings is the defacto-standard workaround to express arrays in GH action parameters. core.getMultilineInput() handles splitting and trimming for you.

It's preferrable as there might be array parameters we want to add in the future that might not play as well with the comma-separated approach.

exclude: exclude ? exclude.split(",").map(pattern => normalize(pattern)): undefined,
});
core.debug(`Discovered ${assets.size} assets`);

Expand Down
2 changes: 1 addition & 1 deletion src/utils/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { parseEntrypoint } from "./entrypoint.ts";
export { API, APIError } from "./api.ts";
export { walk } from "./walk.ts";
export { fromFileUrl, resolve } from "../../deps.ts";
export { fromFileUrl, resolve, normalize } from "../../deps.ts";