store sources from build pipeline

Use relative-path srcs only
This commit is contained in:
Jacob Heider 2022-10-03 13:22:25 -04:00 committed by Jacob Heider
parent 22dcff66c7
commit 6277d70bba
4 changed files with 32 additions and 6 deletions

View file

@ -65,7 +65,7 @@ export async function bottle({ path: kegdir, pkg }: Installation, compression: '
return tarball return tarball
} }
async function sha256(file: Path): Promise<string> { export async function sha256(file: Path): Promise<string> {
return await Deno.open(file.string, { read: true }) return await Deno.open(file.string, { read: true })
.then(file => crypto.subtle.digest("SHA-256", file.readable)) .then(file => crypto.subtle.digest("SHA-256", file.readable))
.then(buf => new TextDecoder().decode(encode(new Uint8Array(buf)))) .then(buf => new TextDecoder().decode(encode(new Uint8Array(buf))))

View file

@ -16,13 +16,14 @@ args:
- --import-map={{ srcroot }}/import-map.json - --import-map={{ srcroot }}/import-map.json
---*/ ---*/
import { usePantry } from "hooks" import { useCache, usePantry } from "hooks"
import { Installation } from "types" import { Installation } from "types"
import { pkg as pkgutils } from "utils" import { pkg as pkgutils } from "utils"
import { useFlags, usePrefix } from "hooks" import { useFlags, usePrefix } from "hooks"
import { set_output } from "./utils/gha.ts" import { set_output } from "./utils/gha.ts"
import build from "./build/build.ts" import build from "./build/build.ts"
import * as ARGV from "./utils/args.ts" import * as ARGV from "./utils/args.ts"
import Path from "path"
useFlags() useFlags()
@ -30,7 +31,7 @@ const pantry = usePantry()
const dry = await ARGV.toArray(ARGV.pkgs()) const dry = await ARGV.toArray(ARGV.pkgs())
const gha = !!Deno.env.get("GITHUB_ACTIONS") const gha = !!Deno.env.get("GITHUB_ACTIONS")
const group_it = gha && dry.length > 1 const group_it = gha && dry.length > 1
const rv: Installation[] = [] const rv: InstallationPlus[] = []
if (usePrefix().string != "/opt") { if (usePrefix().string != "/opt") {
console.error({ TEA_PREFIX: usePrefix().string }) console.error({ TEA_PREFIX: usePrefix().string })
@ -47,7 +48,10 @@ for (const rq of dry) {
} }
const install = await build(pkg) 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) { if (group_it) {
console.log("::endgroup::") 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("pkgs", rv.map(x => pkgutils.str(x.pkg)))
await set_output("paths", rv.map(x => x.path), '%0A') 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("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
}

View file

@ -56,7 +56,9 @@ interface FileInfo {
function produceMatrix(objects: FileInfo[]): void { function produceMatrix(objects: FileInfo[]): void {
const matrix = new Map() const matrix = new Map()
for (const { key, lastModified } of objects) { 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 flavor = `${_platform}/${_arch}`
const version = semver.parse(_v) const version = semver.parse(_v)
if (!version) continue if (!version) continue

View file

@ -12,12 +12,13 @@ args:
import { S3 } from "s3" import { S3 } from "s3"
import { pkg as pkgutils } from "utils" 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 { Package, PackageRequirement } from "types"
import SemVer, * as semver from "semver" import SemVer, * as semver from "semver"
import { dirname, basename } from "deno/path/mod.ts" import { dirname, basename } from "deno/path/mod.ts"
import Path from "path" import Path from "path"
import { set_output } from "./utils/gha.ts" import { set_output } from "./utils/gha.ts"
import { sha256 } from "./bottle.ts"
useFlags() useFlags()
@ -34,6 +35,7 @@ const encode = (() => { const e = new TextEncoder(); return e.encode.bind(e) })(
const cache = useCache() const cache = useCache()
const pkgs = args_get("pkgs").map(pkgutils.parse).map(assert_pkg) const pkgs = args_get("pkgs").map(pkgutils.parse).map(assert_pkg)
const srcs = args_get("srcs")
const bottles = args_get("bottles") const bottles = args_get("bottles")
const checksums = args_get("checksums") const checksums = args_get("checksums")
@ -77,6 +79,19 @@ for (const [index, pkg] of pkgs.entries()) {
await put(key, bottle) await put(key, bottle)
await put(`${key}.sha256sum`, `${checksum} ${basename(key)}`) await put(`${key}.sha256sum`, `${checksum} ${basename(key)}`)
await put(`${dirname(key)}/versions.txt`, versions.join("\n")) 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) await set_output('cf-invalidation-paths', rv)