diff --git a/Dockerfile b/Dockerfile index 4f909ea5cf2..7c7ce65a093 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,5 +47,8 @@ RUN apk add --no-cache git \ # Metrics USER metrics WORKDIR /metrics -COPY source /metrics -CMD [ "deno", "run", "/metrics/run/cli/mod.ts" ] \ No newline at end of file +COPY source /metrics/source +COPY deno.jsonc /metrics/deno.jsonc +COPY deno.lock /metrics/deno.lock +COPY LICENSE /metrics/LICENSE +COPY tasks.ts /metrics/tasks.ts diff --git a/deno.jsonc b/deno.jsonc index efe8a619614..7c093710074 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -81,6 +81,7 @@ "shuffle": true, "coverage": ".coverage", "failFast": 1, + "lock": false, "permissions": { "env": [ // Metrics @@ -88,27 +89,36 @@ "METRICS_GITHUB_APP_SECRET", // Environment "DENO_DEPLOYMENT_ID", + "CHROME_BIN", // Cache "CWD", "USERPROFILE", - "CACHE_DIR" + "CACHE_DIR", + "HOME" ], "read": [ // Environment "deno.jsonc", "$CWD", // Cache - "$USERPROFILE/.astral" + "$USERPROFILE/.astral", + "$HOME/.astral" ], "write": [ // Cache "$USERPROFILE/.astral", + "$HOME/.astral", // Tests - "$CWD/.test" + "$CWD/.test", + // Puppeteer + "$HOME/.config/chromium/SingletonLock" ], "run": [ // Cache - "$USERPROFILE/.astral/**/chrome.exe" + "$USERPROFILE/.astral/**/chrome.exe", + "$HOME/.astral/**/chrome", + // Puppeteer + "/usr/bin/chromium-browser" ], "net": [ // Server bindings @@ -148,10 +158,10 @@ }, "ci:test": { "task": [ - "deno task btr test", - "deno task btr coverage" + "deno task btr docker:build", + "docker run metrics:dev sh -c 'deno task btr test && deno task btr coverage'" ], - "description": "🤖 Run tests, collect coverage and print coverage (CI)", + "description": "🤖 Build container and run tests and coverage inside the image (CI)", "lock": false }, "deploy:deno": { @@ -190,7 +200,7 @@ } }, "docker:build": { - "task": "docker build --tag lowlighter/metrics:4.0.0 .", + "task": "docker build --tag metrics:dev .", "description": "🐋 Build docker image", "lock": false } diff --git a/deno.lock b/deno.lock index 1f0433f1b52..3a9ebebd3c2 100644 --- a/deno.lock +++ b/deno.lock @@ -360,6 +360,7 @@ "https://deno.land/x/zod@v3.21.4/types.ts": "b5d061babea250de14fc63764df5b3afa24f2b088a1d797fc060ba49a0ddff28", "https://esm.sh/@actions/github@5.1.1": "78cad9d60ae3cdb764360f8eee1e2ed1358f90d39b8af01814da191488e8bdb9", "https://esm.sh/@faker-js/faker@8.0.2": "4cd8d861f446522d0811d5f4a501bb082a31b30046733ea39ad39e5cbbcb7712", + "https://esm.sh/@octokit/app@14.0.0": "45bb494eeed35628bd85aadc1abb34bf3739a813408cd954addc6e8182bed34a", "https://esm.sh/@octokit/plugin-paginate-graphql@4.0.0": "e6afc9cb1c47fd29797b947329ae0b71a88507876d3f0d572cefa9a1478d98d3", "https://esm.sh/@octokit/rest@20.0.1": "712b542e635e5559c688d02dab40be563bdbece31cd3c041fb4487d5542bcc50", "https://esm.sh/@octokit/types@11.1.0": "fabf6997a3adf11e45d11e3c4d58d0634ab98f9d72f3116f3694123818ccd457", @@ -412,10 +413,19 @@ "https://esm.sh/v131/universal-user-agent@6.0.0/denonext/universal-user-agent.mjs": "2969647abd054007e6d838dd2ecc7de9c513c18c43322dfa3de57eec8d2d6447", "https://esm.sh/v131/wrappy@1.0.2/denonext/wrappy.mjs": "3c31e4782e0307cf56b319fcec6110f925dafe6cb47a8fa23350d480f5fa8b06", "https://esm.sh/v132/@faker-js/faker@8.0.2/denonext/faker.mjs": "870def5d50e632211a71722109fae486a00080a14a2329589ea4a83f878b6699", + "https://esm.sh/v132/@octokit/app@14.0.0/denonext/app.mjs": "660db7abb5831110a12017a317fa1fe45b303c3a61d299a12c5f4dfb972990db", + "https://esm.sh/v132/@octokit/auth-app@6.0.0/denonext/auth-app.mjs": "5833c3fdd9249d53d1c33652eb6f4a3b238ed21f303fa7cd4475e9342dcb8ea2", + "https://esm.sh/v132/@octokit/auth-oauth-app@7.0.0/denonext/auth-oauth-app.mjs": "d24f9baa219f4da5828f7395f3b149d0529eff900eed456efeef752e18314a63", + "https://esm.sh/v132/@octokit/auth-oauth-device@6.0.0/denonext/auth-oauth-device.mjs": "3e398998f4e34a4beccf9e71ff89f01cae0191ebf6c57926479af430174a1419", + "https://esm.sh/v132/@octokit/auth-oauth-user@4.0.0/denonext/auth-oauth-user.mjs": "314e2b8a9c5e844f43ef551b487a4fe7cc096245155b7bfc11788c6706878e86", "https://esm.sh/v132/@octokit/auth-token@4.0.0/denonext/auth-token.mjs": "ab9285959f2bc3ca7942bfb81df3e2f15f5895c829455156647faa403b75703b", + "https://esm.sh/v132/@octokit/auth-unauthenticated@5.0.0/denonext/auth-unauthenticated.mjs": "5c2690a2af409c0e9abe13b6188fee74bd157f787ebbe8d2377813b696b2a74e", "https://esm.sh/v132/@octokit/core@5.0.0/denonext/core.mjs": "3ba35fb190fc3296e0359f34314aa7ae5a5795dbd72d7068a74c553533191959", "https://esm.sh/v132/@octokit/endpoint@9.0.0/denonext/endpoint.mjs": "e12041e99a773321b0d175a860b81b7c39708de6dbadddfe3398ee159b8c9e9e", "https://esm.sh/v132/@octokit/graphql@7.0.1/denonext/graphql.mjs": "51816b6e7188dce0e3d7435251e7310157ad20658673def6e9fa47e816654dfc", + "https://esm.sh/v132/@octokit/oauth-app@6.0.0/denonext/oauth-app.mjs": "0b448785123ee4fe3e2bf1a08e74964100aaaefb0507e99d5563b057d05cb1a9", + "https://esm.sh/v132/@octokit/oauth-authorization-url@6.0.2/denonext/oauth-authorization-url.mjs": "c4a3809c1092ab4135bbb65ba82e885b915a3e0b68e8c9554c98766388baa399", + "https://esm.sh/v132/@octokit/oauth-methods@4.0.0/denonext/oauth-methods.mjs": "fd10083bf9e2ed4beeccdab7a40ba3181cd1cc76958521cdc0c395c63cdb665e", "https://esm.sh/v132/@octokit/plugin-paginate-graphql@4.0.0/denonext/plugin-paginate-graphql.mjs": "6d2abafdadec31dc3afb9308c18a44b51b834357011d67dce611817196ac032f", "https://esm.sh/v132/@octokit/plugin-paginate-rest@8.0.0/denonext/plugin-paginate-rest.mjs": "8ed6e17dcb65d460c99fe3c3133c20b566fa2c7c4aedcf931e795ea2ca46e24f", "https://esm.sh/v132/@octokit/plugin-request-log@4.0.0/denonext/plugin-request-log.mjs": "8683bc54297e4657259a0edc6abe2c8cf9953c1b044faa8cfb1a9bc0970b54a3", @@ -423,11 +433,16 @@ "https://esm.sh/v132/@octokit/request-error@5.0.0/denonext/request-error.mjs": "dfc75ef3272174505d06ccd7bb0128ccc81603bf6c3d45d4089bcf57de956fc2", "https://esm.sh/v132/@octokit/request@8.1.1/denonext/request.mjs": "9188b4e13c35b697fd9a61c164d3e3f9fe01c8c70a8807a01f2f790cf8baf06f", "https://esm.sh/v132/@octokit/rest@20.0.1/denonext/rest.mjs": "682fd99ba3a3a08099fbdf228c740b9ba962f9929ea3b179e94864f10a0b7e61", + "https://esm.sh/v132/@octokit/webhooks-methods@4.0.0/denonext/webhooks-methods.mjs": "b44d80a07e6e698c95a2fc2789e2caf10b4ff821300e947b2e79c449453a7a19", + "https://esm.sh/v132/@octokit/webhooks@12.0.3/denonext/webhooks.mjs": "0cfd18152589f098ba5d8bde4bd0e884c51e61ae814f93dd77707682291706f1", "https://esm.sh/v132/@primer/octicons@19.7.0/denonext/octicons.mjs": "fac114048b389625024008b8e689aa47590a2d7d399dd968de699b9942c2c1bd", "https://esm.sh/v132/@twemoji/parser@14.1.0/denonext/parser.mjs": "49be06f8aace91c31d62ab861d019657bdbed8fac3491a2ec2521ebada375139", + "https://esm.sh/v132/aggregate-error@3.1.0/denonext/aggregate-error.mjs": "b28a9c083fba80c73d235f2ef8869695ac288af1fb371469aa218ea9128a209a", "https://esm.sh/v132/balanced-match@1.0.2/denonext/balanced-match.mjs": "b2f9737a6fb330aedd4a444eb85ba127d757c49032a528400fc0e2efb70ddca3", "https://esm.sh/v132/before-after-hook@2.2.3/denonext/before-after-hook.mjs": "f4262d059d899d7fcaa8d903bcf352df38ac1c040bb45273d79de200ffdad267", "https://esm.sh/v132/brace-expansion@2.0.1/denonext/brace-expansion.mjs": "d6952fb4f0cee3ad87c36030f0128b23bf50a566625678207e9fde8b9a30326d", + "https://esm.sh/v132/btoa-lite@1.0.0/denonext/btoa-lite.mjs": "5f8ecdf77c8824225e30cf84b62ded0fa667ef51fe1a8b772b1ddf46410bf78f", + "https://esm.sh/v132/clean-stack@2.2.0/denonext/clean-stack.mjs": "8a2732fd195c0663d9f8a3957932215f3d4cb45dbe2f4747c9f39a966a4f067b", "https://esm.sh/v132/css-tree@2.2.1/denonext/css-tree.mjs": "029fb11a6dc01851e2010d82011c0c982718df39b8205ab001ca680d100da977", "https://esm.sh/v132/cssesc@3.0.0/denonext/cssesc.mjs": "8e1441106b9e0d6a2b1c5f012f9f22962fbd8661490c06e7d0f602dd2b65864f", "https://esm.sh/v132/csso@5.0.5/denonext/csso.mjs": "2636ff0820a385e131cb80d50be52fa7495ddad6ed67f2e904d51ce17bd0f40c", @@ -438,9 +453,11 @@ "https://esm.sh/v132/glob@8.1.0/denonext/glob.mjs": "5231076466f6a71b3fac965f8b9cc216c8165868bec7ef17ebad935710d7a439", "https://esm.sh/v132/html-escaper@3.0.3/denonext/html-escaper.mjs": "c51d972a3e0a4560b4f2e81b42a71b68d986461c809d576c56d00e729d08258e", "https://esm.sh/v132/human-format@1.2.0/denonext/human-format.mjs": "d767edbf69b662936013c764c680b80180e26b7851d633bbf5c0f28090bad4e6", + "https://esm.sh/v132/indent-string@4.0.0/denonext/indent-string.mjs": "de4038b836a42fe2a7c453bd0b44cdae706a9560bbef99b1857c13f9d55ace14", "https://esm.sh/v132/inflight@1.0.6/denonext/inflight.mjs": "05e2dc32d0f09a76d2072d10e53a3341cd1b72a60e0ae5344b3ff8ccaea769e1", "https://esm.sh/v132/inherits@2.0.4/denonext/inherits.mjs": "8095f3d6aea060c904fb24ae50f2882779c0acbe5d56814514c8b5153f3b4b3b", "https://esm.sh/v132/is-plain-object@5.0.0/denonext/is-plain-object.mjs": "6d9568ddc8b90de99a46c63e14984810280b6b021dc4e478803b3c240811985f", + "https://esm.sh/v132/lru-cache@10.0.1/denonext/lru-cache.mjs": "0bf693a0bedd7806c7bf2f336f83ec6dd1933b881703cf59bee326573473aa35", "https://esm.sh/v132/minimatch@5.1.6/denonext/minimatch.mjs": "7307d9f0864dce7f8b413d69c070077f1863517df3c84b7b439578cbcb3fe71d", "https://esm.sh/v132/nanoid@3.3.6/denonext/non-secure.js": "9339526d48828770370eba72bf719a40b74de0e1197d8a582c15fbd9ab837d3d", "https://esm.sh/v132/once@1.4.0/denonext/once.mjs": "afcb39a581b8e3b52af3ce15acb08b0f6a162478c68dab3526ee68b9295a8ddf", @@ -454,6 +471,7 @@ "https://esm.sh/v132/source-map-js@1.0.2/denonext/lib/source-map-generator.js": "8aff2603c0b8e01a585cd0d43582e6bc2787071fd68c4eb7a4dfe03da9cab69e", "https://esm.sh/v132/source-map-js@1.0.2/denonext/source-map-js.mjs": "81ed2d1f28bd08a762f6819d5b366285a1bacf4b5c3757d866c79e4950529bfd", "https://esm.sh/v132/string-argv@0.3.2/denonext/string-argv.mjs": "a797792ada1d72bf89b1db36d2c24fdfa82df6ce4f6c2b59a930b641a6ba9b37", + "https://esm.sh/v132/universal-github-app-jwt@1.1.1/denonext/universal-github-app-jwt.mjs": "546280ef9d50e167172bc039c0c2f4348a728ae1732f467af726b08491d2ea18", "https://esm.sh/v132/universal-user-agent@6.0.0/denonext/universal-user-agent.mjs": "2969647abd054007e6d838dd2ecc7de9c513c18c43322dfa3de57eec8d2d6447", "https://esm.sh/v132/util-deprecate@1.0.2/denonext/util-deprecate.mjs": "f69f67cf655c38428b0934e0f7c865c055834a87cc3866b629d6b2beb21005e9", "https://esm.sh/v132/wrappy@1.0.2/denonext/wrappy.mjs": "3c31e4782e0307cf56b319fcec6110f925dafe6cb47a8fa23350d480f5fa8b06", diff --git a/source/metrics/utils/browser.ts b/source/metrics/utils/browser.ts index f48e1b239f7..a465c36d6bc 100644 --- a/source/metrics/utils/browser.ts +++ b/source/metrics/utils/browser.ts @@ -1,6 +1,7 @@ //Imports import { Logger } from "@utils/log.ts" import * as astral from "x/astral@0.2.6/mod.ts" +import { env } from "@utils/io.ts" const flags = [ //"--no-sandbox", @@ -57,7 +58,7 @@ export class Browser { //TODO(@lowlighter): this.instance = await puppeteer.connect({ browserWSEndpoint: this.endpoint }) log.io("connected to browser") } else { - instance = await astral.launch({ headless: true, args: flags }) + instance = await astral.launch({ headless: true, args: flags, path: env.get("CHROME_BIN") || undefined }) log.io("started browser") } if ((this.shared) && (!this.instance)) { diff --git a/tasks.ts b/tasks.ts index e9a2b30a288..e69b8be48a9 100644 --- a/tasks.ts +++ b/tasks.ts @@ -123,7 +123,7 @@ const meta = is.object({ function expandGlob(pattern: string) { pattern = pattern.replaceAll(/\$(\w+)/g, (match, name) => Deno.env.get(name) ?? (name === "CWD" ? Deno.cwd() : match)) const expanded = [...expandGlobSync(pattern, { includeDirs: false, caseInsensitive: true })] - return expanded.length ? expanded.map(({ path }) => path) : [pattern] + return expanded.length ? expanded.map(({ path }) => path) : !pattern.includes("*") ? [pattern] : [] } /** Tasks ========================================================================================================= */ @@ -148,24 +148,29 @@ class Task { /** Command */ get command() { - const argv = stringArgv(this.meta.task.join(" && ")) const args = [] - let isDeno = false - for (let i = 0; i < argv.length; i++) { - const arg = argv[i] - args.push(arg) - if (arg === "deno") { - isDeno = true - continue - } - if (isDeno && (["test", "run"].includes(arg))) { - args.push(...this.flags) + for (const task of this.meta.task) { + const argv = stringArgv(task) + const argc = [] + let isDeno = false + for (let i = 0; i < argv.length; i++) { + const arg = argv[i] + argc.push(arg) + if (arg === "deno") { + isDeno = true + continue + } + if (isDeno && (["test", "run"].includes(arg))) { + argc.push(...this.flags) + isDeno = false + continue + } isDeno = false - continue } - isDeno = false + //TODO(@lowlighter): is bad + args.push(argc.map((a) => a.includes(" ") ? `'${a}'` : a).join(" ")) } - return args.join(" ") + return args.join(" && ") } /** Run task */