diff --git a/scripts/bottle.ts b/scripts/bottle.ts index a154421a..dd711909 100755 --- a/scripts/bottle.ts +++ b/scripts/bottle.ts @@ -65,7 +65,7 @@ export async function bottle({ path: kegdir, pkg }: Installation, compression: ' return tarball } -async function sha256(file: Path): Promise { +export async function sha256(file: Path): Promise { return await Deno.open(file.string, { read: true }) .then(file => crypto.subtle.digest("SHA-256", file.readable)) .then(buf => new TextDecoder().decode(encode(new Uint8Array(buf)))) diff --git a/scripts/build.ts b/scripts/build.ts index 9540bc43..0eb6d3f7 100755 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -16,13 +16,14 @@ args: - --import-map={{ srcroot }}/import-map.json ---*/ -import { usePantry } from "hooks" +import { useCache, usePantry } from "hooks" import { Installation } from "types" import { pkg as pkgutils } from "utils" import { useFlags, usePrefix } from "hooks" import { set_output } from "./utils/gha.ts" import build from "./build/build.ts" import * as ARGV from "./utils/args.ts" +import Path from "path" useFlags() @@ -30,7 +31,7 @@ const pantry = usePantry() const dry = await ARGV.toArray(ARGV.pkgs()) const gha = !!Deno.env.get("GITHUB_ACTIONS") const group_it = gha && dry.length > 1 -const rv: Installation[] = [] +const rv: InstallationPlus[] = [] if (usePrefix().string != "/opt") { console.error({ TEA_PREFIX: usePrefix().string }) @@ -47,7 +48,10 @@ for (const rq of dry) { } const install = await build(pkg) - rv.push(install) + const { url } = await pantry.getDistributable(pkg) + const extname = url.path().extname() + const src = useCache().path({ pkg, type: "src", extname }) + rv.push({...install, src }) if (group_it) { console.log("::endgroup::") @@ -57,3 +61,8 @@ for (const rq of dry) { await set_output("pkgs", rv.map(x => pkgutils.str(x.pkg))) await set_output("paths", rv.map(x => x.path), '%0A') await set_output("relative-paths", rv.map(x => x.path.relative({ to: usePrefix() }))) +await set_output("srcs", rv.map(x => x.src.relative({ to: usePrefix() }))) + +interface InstallationPlus extends Installation { + src: Path +} \ No newline at end of file diff --git a/scripts/ls-aws-s3.ts b/scripts/ls-aws-s3.ts index 695ede18..47b65192 100755 --- a/scripts/ls-aws-s3.ts +++ b/scripts/ls-aws-s3.ts @@ -56,7 +56,9 @@ interface FileInfo { function produceMatrix(objects: FileInfo[]): void { const matrix = new Map() for (const { key, lastModified } of objects) { - const [_, project, _platform, _arch, _v] = key.match(new RegExp("(.*)/(darwin|linux)/(aarch64|x86-64)/v(.*)\.tar\.(x|g)z"))! + const match = key.match(new RegExp("(.*)/(darwin|linux)/(aarch64|x86-64)/v(.*)\.tar\.(x|g)z")) + if (!match) continue + const [_, project, _platform, _arch, _v] = match const flavor = `${_platform}/${_arch}` const version = semver.parse(_v) if (!version) continue diff --git a/scripts/upload.ts b/scripts/upload.ts index 525894b7..b67b22d5 100755 --- a/scripts/upload.ts +++ b/scripts/upload.ts @@ -12,12 +12,13 @@ args: import { S3 } from "s3" import { pkg as pkgutils } from "utils" -import { useFlags, useOffLicense, useCache } from "hooks" +import { useFlags, useOffLicense, useCache, usePrefix } from "hooks" import { Package, PackageRequirement } from "types" import SemVer, * as semver from "semver" import { dirname, basename } from "deno/path/mod.ts" import Path from "path" import { set_output } from "./utils/gha.ts" +import { sha256 } from "./bottle.ts" useFlags() @@ -34,6 +35,7 @@ const encode = (() => { const e = new TextEncoder(); return e.encode.bind(e) })( const cache = useCache() const pkgs = args_get("pkgs").map(pkgutils.parse).map(assert_pkg) +const srcs = args_get("srcs") const bottles = args_get("bottles") const checksums = args_get("checksums") @@ -77,6 +79,19 @@ for (const [index, pkg] of pkgs.entries()) { await put(key, bottle) await put(`${key}.sha256sum`, `${checksum} ${basename(key)}`) await put(`${dirname(key)}/versions.txt`, versions.join("\n")) + + // Store sources + const src = usePrefix().join(srcs[index]) + const srcKey = useOffLicense('s3').key({ + pkg: stowed.pkg, + type: "src", + extname: src.extname() + }) + const srcChecksum = await sha256(src) + const srcVersions = await get_versions(srcKey, pkg) + await put(srcKey, src) + await put(`${srcKey}.sha256sum`, `${srcChecksum} ${basename(srcKey)}`) + await put(`${dirname(srcKey)}/versions.txt`, srcVersions.join("\n")) } await set_output('cf-invalidation-paths', rv)