mirror of
https://github.com/ivabus/pantry
synced 2025-06-08 08:20:32 +03:00
parent
e968bff3f1
commit
9b0cf3d92a
4 changed files with 46 additions and 58 deletions
7
.github/workflows/build.yml
vendored
7
.github/workflows/build.yml
vendored
|
@ -106,7 +106,10 @@ jobs:
|
|||
# TODO only upload when we merge
|
||||
# TODO upload to a staging location until we release new pantry versions
|
||||
- name: upload bottles
|
||||
run: scripts/upload.ts ${{ steps.bottle.outputs.bottles }}
|
||||
run: scripts/upload.ts
|
||||
--pkgs ${{ steps.build.outputs.pkgs }}
|
||||
--bottles ${{ steps.bottle.outputs.bottles }}
|
||||
--checksums ${{ steps.bottle.outputs.checksums }}
|
||||
env:
|
||||
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
|
||||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
|
@ -116,7 +119,7 @@ jobs:
|
|||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ${{ matrix.os }}
|
||||
path: ${{ steps.bottle.outputs.filenames }}
|
||||
path: ${{ steps.bottle.outputs.artifacts }}
|
||||
if-no-files-found: error
|
||||
|
||||
invalidate-cloudfront:
|
||||
|
|
|
@ -24,13 +24,7 @@ build:
|
|||
make --jobs {{ hw.concurrency }} install RUN_FC_CACHE_TEST=false
|
||||
rm -rf {{prefix}}/share/doc
|
||||
|
||||
sed -i.bak 's|<cachedir>{{prefix}}/var/cache/fontconfig</cachedir>|<cachedir prefix="relative">../../var/cache/fontconfig</cachedir>|' {{prefix}}/etc/fonts/fonts.conf
|
||||
|
||||
test:
|
||||
fc-list
|
||||
|
||||
#TODO
|
||||
# font_dirs = %w[
|
||||
# /System/Library/Fonts
|
||||
# /Library/Fonts
|
||||
# ~/Library/Fonts
|
||||
# ]
|
||||
# font_dirs << Dir["/System/Library/Assets{,V2}/com_apple_MobileAsset_Font*"].max if MacOS.version >= :sierra
|
||||
|
|
|
@ -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`))
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 })
|
||||
|
|
Loading…
Reference in a new issue