Skip to content

Commit

Permalink
fix: ci
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter committed Oct 10, 2023
1 parent a4acdc6 commit 5c58dfc
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 26 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
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
26 changes: 18 additions & 8 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -81,34 +81,44 @@
"shuffle": true,
"coverage": ".coverage",
"failFast": 1,
"lock": false,
"permissions": {
"env": [
// Metrics
"METRICS_GITHUB_TOKEN",
"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
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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
}
Expand Down
18 changes: 18 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion source/metrics/utils/browser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//Imports
import { Logger } from "@utils/log.ts"
import * as astral from "x/[email protected]/mod.ts"
import { env } from "@utils/io.ts"

const flags = [
//"--no-sandbox",
Expand Down Expand Up @@ -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)) {
Expand Down
35 changes: 20 additions & 15 deletions tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ========================================================================================================= */
Expand All @@ -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 */
Expand Down

0 comments on commit 5c58dfc

Please sign in to comment.