+portable fontconfig (#134)

Only changes the cache location
This commit is contained in:
Max Howell 2022-09-14 15:48:36 -04:00 committed by GitHub
parent 16678e8833
commit f6756ac2d0
2 changed files with 39 additions and 48 deletions

View file

@ -31,13 +31,15 @@ if (import.meta.main) {
useFlags()
const bottles: Path[] = []
const fileLists: Path[] = []
const checksums: Path[] = []
const artifacts: Path[] = []
for (const pkg of Deno.args.map(parsePackageRequirement)) {
console.log({ bottling: { pkg } })
const installation = await cellar.resolve(pkg)
const path = await bottle(installation)
const checksum = await sha256(path)
artifacts.push(installation.path.join(filesListName))
if (!path) throw new Error("wtf: bottle already exists")
if (!checksum) throw new Error("failed to compute checksum")
@ -45,19 +47,22 @@ if (import.meta.main) {
console.log({ bottled: { path } })
bottles.push(path)
bottles.push(checksum)
fileLists.push(installation.path.join(filesListName))
checksums.push(checksum)
}
if (bottles.length === 0) throw new Error("no input provided")
const encode = (() => { const e = new TextEncoder(); return e.encode.bind(e) })()
const bottleList = bottles.map(x => x.string).join(" ")
await Deno.stdout.write(encode(`::set-output name=bottles::${bottleList}\n`))
const bottles_out = bottles.map(x => x.string).join(' ')
await Deno.stdout.write(encode(`::set-output name=bottles::${bottles_out}\n`))
const paths = [...bottles, ...fileLists].map(x => x.string).join('%0A')
await Deno.stdout.write(encode(`::set-output name=filenames::${paths}\n`))
const checksums_out = checksums.map(x => x.string).join(' ')
await Deno.stdout.write(encode(`::set-output name=checksums::${checksums_out}\n`))
// newline separated for the upload-artifact action
artifacts.push(...bottles, ...checksums)
await Deno.stdout.write(encode(`::set-output name=artifacts::${artifacts.join('%0A')}\n`))
}

View file

@ -11,10 +11,11 @@ args:
---*/
import { S3 } from "s3"
import { PackageRequirement, Path } from "types"
import { parsePackage, Path } from "types"
import useCache from "hooks/useCache.ts"
import { Package, parsePackageRequirement, SemVer, semver } from "types"
import { Package, SemVer, semver } from "types"
import useFlags from "hooks/useFlags.ts"
import { dirname, basename } from "deno/path/mod.ts"
useFlags()
@ -30,62 +31,47 @@ const bucket = s3.getBucket(Deno.env.get("AWS_S3_BUCKET")!)
const encode = (() => { const e = new TextEncoder(); return e.encode.bind(e) })()
const bottles = new Set<PackageRequirement>()
const checksums = new Set<string>()
const pkgs = args_get("pkgs").map(parsePackage)
const bottles = args_get("bottles")
const checksums = args_get("checksums")
for (const filename of Deno.args) {
const path = new Path(filename).isFile()
if (!path) { throw new Error(`${filename} is missing`)}
if (path.basename() == "files.txt") { continue } // We don't need to upload this
const match = path.basename().match(/(.*)-([0-9]+\.[0-9]+\.[0-9]+)\+.*\.tar\.gz.*/)
if (!match) { throw new Error(`${filename} doesn't appear to be our bottle/checksum`) }
const req = parsePackageRequirement(`${match[1]}@${match[2]}`)
if (path.basename().match(/\.sha256sum$/)) {
checksums.add(`${req.project}@${req.constraint.raw}`)
} else {
bottles.add(req)
function args_get(key: string): string[] {
const it = Deno.args[Symbol.iterator]()
while (true) {
const { value, done } = it.next()
if (done) throw new Error()
if (value === `--${key}`) break
}
const rv: string[] = []
while (true) {
const { value, done } = it.next()
if (done) return rv
if (value.startsWith('--')) return rv
rv.push(value)
}
}
// Ensure our sets are the same:
if (bottles.size !== checksums.size || ![...bottles].every(b => checksums.has(`${b.project}@${b.constraint.raw}`))) {
throw new Error("bottles and checksums don't align")
}
for (const rq of bottles) {
// Packages should be a fixed version, so this should be fine:
const version = semver.parse(rq.constraint.raw)
if (!version) { throw new Error(`Incomplete package version: ${rq.constraint.raw}`)}
const pkg = { project: rq.project, version }
for (const [index, pkg] of pkgs.entries()) {
const bottle = bottles[index]
const checksum = checksums[index]
const key = useCache().s3Key(pkg)
const bottle = useCache().bottle(pkg)
const checksum = new Path(`${bottle.string}.sha256sum`)
console.log({ key });
//FIXME stream it to S3
const [basename, dirname] = (split => [split.pop(), split.join("/")])(key.split("/"))
const bottle_contents = await Deno.readFile(bottle.string)
const checksum_contents = fixup_checksum(await Deno.readFile(checksum.string), basename!)
const bottle_contents = await Deno.readFile(bottle)
const checksum_contents = fixup_checksum(await Deno.readFile(checksum), basename(bottle))
const versions = await get_versions(pkg)
console.log({ uploading: key })
await bucket.putObject(key, bottle_contents)
await bucket.putObject(`${key}.sha256sum`, checksum_contents)
await bucket.putObject(`${dirname}/versions.txt`, encode(versions.join("\n")))
await bucket.putObject(`${dirname(key)}/versions.txt`, encode(versions.join("\n")))
console.log({ uploaded: key })
}
//end
import { dirname, basename } from "deno/path/mod.ts"
async function get_versions(pkg: Package): Promise<SemVer[]> {
const prefix = dirname(useCache().s3Key(pkg))
const rsp = await bucket.listObjects({ prefix })