Correctly sort versions so the tea installer works

This commit is contained in:
Max Howell 2022-09-29 07:45:36 -04:00
parent 3e1b0a2505
commit 09a566cf58
2 changed files with 7 additions and 11 deletions

View file

@ -14,7 +14,7 @@ import { S3 } from "s3"
import { stringify as yaml } from "deno/encoding/yaml.ts" import { stringify as yaml } from "deno/encoding/yaml.ts"
import { stringify as csv } from "deno/encoding/csv.ts" import { stringify as csv } from "deno/encoding/csv.ts"
import { Inventory } from "hooks/useInventory.ts" import { Inventory } from "hooks/useInventory.ts"
import * as semver from "semver" import SemVer, * as semver from "semver"
const s3 = new S3({ const s3 = new S3({
accessKeyID: Deno.env.get("AWS_ACCESS_KEY_ID")!, accessKeyID: Deno.env.get("AWS_ACCESS_KEY_ID")!,
@ -30,7 +30,7 @@ const flat = []
for await (const pkg of bucket.listAllObjects({ batchSize: 200 })) { for await (const pkg of bucket.listAllObjects({ batchSize: 200 })) {
if (!/\.tar\.[gx]z$/.test(pkg.key ?? '')) { continue } if (!/\.tar\.[gx]z$/.test(pkg.key ?? '')) { continue }
const matches = pkg.key!.match(new RegExp(`^(.*)/(.*)/(.*)/v(${semver.regex})\.tar\.[xg]z$`)) const matches = pkg.key!.match(new RegExp(`^(.*)/(.*)/(.*)/v(${semver.regex.source})\.tar\.[xg]z$`))
if (!matches) { continue } if (!matches) { continue }
const [_, project, platform, arch, version] = matches const [_, project, platform, arch, version] = matches
@ -70,7 +70,9 @@ bucket.putObject("versions.csv", csvData)
for(const [project, platforms] of Object.entries(inventory)) { for(const [project, platforms] of Object.entries(inventory)) {
for (const [platform, archs] of Object.entries(platforms)) { for (const [platform, archs] of Object.entries(platforms)) {
for (const [arch, versions] of Object.entries(archs)) { for (const [arch, versions] of Object.entries(archs)) {
const txt = te.encode(versions.join("\n")) const v = versions.map(x => new SemVer(x)).sort(semver.compare)
const txt = te.encode(v.join("\n"))
console.log(project, platform, arch, v)
bucket.putObject(`${project}/${platform}/${arch}/versions.txt`, txt) bucket.putObject(`${project}/${platform}/${arch}/versions.txt`, txt)
} }
} }

View file

@ -99,13 +99,7 @@ async function get_versions(key: string, pkg: Package): Promise<SemVer[]> {
?? [] ?? []
// have to add pkg.version as put and get are not atomic // have to add pkg.version as put and get are not atomic
return [...new Set([...got, pkg.version])].sort() return [...new Set([...got, pkg.version])].sort(semver.compare)
}
// Somewhat hacky. We call the bottle on thing locally, and another on the server.
function fixup_checksum(data: Uint8Array, new_file_name: string) {
const checksum = new TextDecoder().decode(data).split(" ")[0]
return new TextEncoder().encode(`${checksum} ${new_file_name}`)
} }
function assert_pkg(pkg: Package | PackageRequirement) { function assert_pkg(pkg: Package | PackageRequirement) {
@ -117,4 +111,4 @@ function assert_pkg(pkg: Package | PackageRequirement) {
version: new SemVer(pkg.constraint) version: new SemVer(pkg.constraint)
} }
} }
} }