pantry/.github/scripts/utils/gha.ts

23 lines
594 B
TypeScript
Raw Normal View History

2022-09-28 18:14:46 +03:00
const e = new TextEncoder()
const encode = e.encode.bind(e)
export async function set_output<T>(name: string, arr: T[], separator = " ") {
2022-09-28 18:14:46 +03:00
const value = arr.map(escape).join(separator)
const txt = `${name}=${value}`
const outfile = Deno.env.get("GITHUB_OUTPUT")
if (outfile) {
await Deno.writeTextFile(outfile, `${name}=${value}\n`, { append: true})
}
return await Deno.stdout.write(encode(`${txt}\n`))
2022-09-28 18:14:46 +03:00
}
//TODO HTML escapes probs
function escape<T>(input: T): string {
const out = `${input}`
if (/[<>~]/.test(out)) {
2022-09-28 18:14:46 +03:00
return `"${out}"`
} else {
return out
}
}