From fa288b27399aa1a0803b504d38d59e01c26d8adf Mon Sep 17 00:00:00 2001 From: hugoalh Date: Mon, 23 Dec 2024 12:35:17 +0800 Subject: [PATCH] Manual merge branch `dev`, picked from commits: - 1f8af6860307aba42389bd853774868593a202bb - 1f21e2ffb52006102c014f77428cbc0fd2a85640 - 1a98d7fa7c57131292372f5437df4587820a410e - 9cd613a02f2c64c1628fd3073b64c43aabaf3320 - bf1b2e0c7d0afe3339f2c85031172b708d6e25a3 - f830f38ebffa969b6efaadc884108bb0e04b669d - 0102e597d7d4d1b824294219bc88feb4038ad6ea - ecfdd7cfe4b880049507ea5cf9eaa95bcfa81f26 - 33810f32f2af8cb3ca0d5003e5b78231cc18add4 --- Dockerfile | 4 ++-- _fswalk.ts | 67 ----------------------------------------------------- _payload.ts | 39 +++++++++++++------------------ action.yml | 2 +- deno.jsonc | 6 ++--- mod.ts | 2 +- 6 files changed, 23 insertions(+), 97 deletions(-) delete mode 100644 _fswalk.ts diff --git a/Dockerfile b/Dockerfile index 1ef70af9..946b984d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 # IMPORTANT: Do not create big size layer due to GitHub Packages have worse performance on this! -FROM denoland/deno:bin-2.0.6 AS stage-deno +FROM denoland/deno:bin-2.1.4 AS stage-deno FROM debian:12.8-slim ENV APP_ROOT=/opt/hugoalh/send-discord-webhook-ghaction ENV DEBIAN_FRONTEND=noninteractive @@ -8,6 +8,6 @@ ENV DENO_NO_PROMPT=1 ENV DENO_NO_UPDATE_CHECK=1 COPY --from=stage-deno /deno /opt/denoland/deno/deno RUN chmod +x /opt/denoland/deno/deno && ln -s /opt/denoland/deno/deno /usr/bin/deno -COPY _color_namespace_list.ts _fswalk.ts _payload.ts _random_integer.ts deno.jsonc mod.ts ${APP_ROOT}/ +COPY _color_namespace_list.ts _payload.ts _random_integer.ts deno.jsonc mod.ts ${APP_ROOT}/ RUN deno --version && deno info && cd $APP_ROOT && deno install --lock --vendor --entrypoint mod.ts CMD deno run --allow-env --allow-net=discord.com --allow-read --allow-write --config=$APP_ROOT/deno.jsonc --lock --vendor $APP_ROOT/mod.ts diff --git a/_fswalk.ts b/_fswalk.ts deleted file mode 100644 index fbdd6c07..00000000 --- a/_fswalk.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { - walk as fsWalk, - type WalkEntry, - type WalkOptions -} from "STD/fs/walk"; -import { isAbsolute as pathIsAbsolute } from "STD/path/is-absolute"; -import { join as pathJoin } from "STD/path/join"; -import { normalize as pathNormalize } from "STD/path/normalize"; -import { relative as pathRelative } from "STD/path/relative"; -export interface FSWalkOptions extends WalkOptions { - /** - * Whether the root should include in the yield entries. - * @default true - */ - includeRoot?: boolean; -} -export interface FSWalkEntry { - /** - * Whether entry is a regular directory. Mutually exclusive to {@linkcode isFile} and {@linkcode isSymlink}. - */ - isDirectory: boolean; - /** - * Whether entry is a regular file. Mutually exclusive to {@linkcode isDirectory} and {@linkcode isSymlink}. - */ - isFile: boolean; - /** - * Whether entry is a symlink. Mutually exclusive to {@linkcode isDirectory} and {@linkcode isFile}. - */ - isSymlink: boolean; - /** - * Name of the entry. - */ - name: string; - /** - * Absolute path of the entry. - */ - pathAbsolute: string; - /** - * Root based relative path of the entry. - */ - pathRelative: string; -} -async function* walkFSIterator(fsWalker: AsyncIterableIterator, pathRootAbsolute: string, includeRoot = true): AsyncGenerator { - for await (const { - isDirectory, - isFile, - isSymlink, - name, - path - } of fsWalker) { - if (isDirectory && path === pathRootAbsolute && !includeRoot) { - continue; - } - yield { - isDirectory, - isFile, - isSymlink, - name, - pathAbsolute: path, - pathRelative: pathRelative(pathRootAbsolute, path) - }; - } -} -export function walkFS(pathRoot: string, options: FSWalkOptions = {}): AsyncGenerator { - const pathRootAbsolute: string = pathNormalize(pathIsAbsolute(pathRoot) ? pathRoot : pathJoin(Deno.cwd(), pathRoot)); - return walkFSIterator(fsWalk(pathRootAbsolute, options), pathRootAbsolute, options.includeRoot); -} diff --git a/_payload.ts b/_payload.ts index cc4c1515..9b2c698f 100644 --- a/_payload.ts +++ b/_payload.ts @@ -1,4 +1,8 @@ import Color from "COLOR"; +import { + walk, + type FSWalkEntry +} from "FS/walk.ts"; import { isJSONArray, isJSONObject, @@ -16,10 +20,6 @@ import { globToRegExp } from "STD/path/glob-to-regexp"; import { join as pathJoin } from "STD/path/join"; import type { StringTruncator } from "STRINGOVERFLOW/mod.ts"; import { colorNamespaceList } from "./_color_namespace_list.ts"; -import { - walkFS, - type FSWalkEntry -} from "./_fswalk.ts"; import { generateRandomInteger } from "./_random_integer.ts"; const thresholdContent = 2000; const thresholdEmbeds = 10; @@ -362,29 +362,22 @@ async function resolveFilesFormData(workspace: string, files: string[]): Promise } export async function resolveFiles(files: string[], glob: boolean): Promise { const workspace: string = getRunnerWorkspacePath(); - const workspaceStat: Deno.FileInfo = await Deno.stat(workspace); - if (!workspaceStat.isDirectory) { + const workspaceStatL: Deno.FileInfo = await Deno.lstat(workspace); + if (!workspaceStatL.isDirectory) { throw new Deno.errors.NotADirectory(`Workspace \`${workspace}\` is not a directory!`); } if (files.length === 0) { return undefined; } if (glob) { - const matchers: RegExp[] = files.map((file: string): RegExp => { - return globToRegExp(file, { caseInsensitive: true }); - }); - const filesFmt: string[] = (await Array.fromAsync(walkFS(workspace, { - includeDirs: false, - includeRoot: false, - includeSymlinks: false - }))).filter(({ - pathAbsolute, - pathRelative - }: FSWalkEntry): boolean => { - return pathAbsolute.startsWith(workspace) && matchers.some((matcher: RegExp): boolean => { - return matcher.test(pathRelative); - }); - }).map(({ pathRelative }: FSWalkEntry): string => { + const filesFmt: string[] = await Array.fromAsync(await walk(workspace, { + includeDirectories: false, + includeSymlinkDirectories: false, + includeSymlinkFiles: false, + matches: files.map((file: string): RegExp => { + return globToRegExp(file, { caseInsensitive: true }); + }) + }), ({ pathRelative }: FSWalkEntry): string => { return pathRelative; }); if (filesFmt.length === 0) { @@ -396,8 +389,8 @@ export async function resolveFiles(files: string[], glob: boolean): Promise
): unknown => { diff --git a/action.yml b/action.yml index 87476be9..df3e4d0e 100644 --- a/action.yml +++ b/action.yml @@ -94,7 +94,7 @@ outputs: description: "{string} Request status text." runs: using: "docker" - image: "docker://ghcr.io/hugoalh/send-discord-webhook-ghaction:7.0.3" + image: "docker://ghcr.io/hugoalh/send-discord-webhook-ghaction:7.0.4" branding: icon: "send" color: "blue" diff --git a/deno.jsonc b/deno.jsonc index aa5cd3e1..95bfd373 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -12,12 +12,12 @@ "COLOR": "https://esm.sh/color@4.2.3", "COLORNAMESPACELISTCOMMUNITY": "https://esm.sh/color-name-list@10.28.0/dist/colornames.esm.js", "EXFETCH/": "https://raw.githubusercontent.com/hugoalh/exfetch-es/v0.5.1/", + "FS/": "https://raw.githubusercontent.com/hugoalh/fs-es/v0.2.0/", "GHACTIONS/": "https://raw.githubusercontent.com/hugoalh/github-actions-core-es/v0.4.2/", "ISJSON/": "https://raw.githubusercontent.com/hugoalh/is-json-es/v1.0.4/", "REGEXPURL": "https://esm.sh/url-regex-safe@4.0.0", - "STD/assert": "jsr:@std/assert@1.0.7", - "STD/fs": "jsr:@std/fs@1.0.5", - "STD/media-types": "jsr:@std/media-types@1.0.3", + "STD/assert": "jsr:@std/assert@1.0.8", + "STD/media-types": "jsr:@std/media-types@1.1.0", "STD/path": "jsr:@std/path@1.0.8", "STD/yaml": "jsr:@std/yaml@1.0.5", "STRINGOVERFLOW/": "https://raw.githubusercontent.com/hugoalh/string-overflow-es/v2.0.4/" diff --git a/mod.ts b/mod.ts index 330c8f93..fdbc32b1 100644 --- a/mod.ts +++ b/mod.ts @@ -33,7 +33,7 @@ import { } from "./_payload.ts"; console.log("Initialize."); const exfetch: ExFetch = new ExFetch({ - userAgent: `${userAgentDefault} SendDiscordWebhook.GitHubAction/7.0.3` + userAgent: `${userAgentDefault} SendDiscordWebhook.GitHubAction/7.0.4` }); const splitterNewLine = /\r?\n/g; const splitterCommonDelimiter = /,|\r?\n/g;