Skip to content

Commit

Permalink
add ignored-versions to package.yml, support {{ arch }} and {{ target }}
Browse files Browse the repository at this point in the history
  • Loading branch information
jhheider committed Jun 13, 2022
1 parent aad6723 commit 98cfd7f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/hooks/useGitHubAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { flatMap, GET } from "utils"
interface GetVersionsOptions {
user: string
repo: string
ignoredVersions?: RegExp[]
}

interface Response {
Expand All @@ -18,11 +19,13 @@ interface GHRelease {
}

export default function useGitHubAPI(): Response {
const getVersions = async ({ user, repo }: GetVersionsOptions) => {
const getVersions = async ({ user, repo, ignoredVersions }: GetVersionsOptions) => {
const releases = await GET<GHRelease[]>(`https://api.github.com/repos/${user}/${repo}/releases`)
return releases.compactMap(({ tag_name, name }) => {
//TODO should be explicit if you want coerce
return flatMap(tag_name ?? name, x => semver.coerce(x))
const raw_version = tag_name ?? name ?? ""
if (ignoredVersions?.some(v => raw_version.match(v))) { return undefined }
return flatMap(raw_version, x => semver.coerce(x))
}, { throws: true })
}
return { getVersions }
Expand Down
7 changes: 6 additions & 1 deletion src/hooks/usePantry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Package, PackageRequirement, Path, PlainObject, SemVer, semver } from "
import useGitHubAPI from "hooks/useGitHubAPI.ts"
import { run, flatMap, isNumber, isPlainObject, isString, isArray } from "utils"
import useCellar from "hooks/useCellar.ts"
import usePlatform from "hooks/usePlatform.ts"


interface GetDepsOptions {
Expand Down Expand Up @@ -49,9 +50,10 @@ export default function usePantry(): Response {

async function github(): Promise<boolean> {
const yml = await files.yml()
const ignoredVersions = yml['ignore-versions']?.map((v: string) => new RegExp(v))
try {
const { user, repo } = get()
rv = await useGitHubAPI().getVersions({ user, repo })
rv = await useGitHubAPI().getVersions({ user, repo, ignoredVersions })
return true
} catch (err) {
if (err === "not-github") return false
Expand Down Expand Up @@ -120,8 +122,11 @@ export default function usePantry(): Response {
const getBuildScript = async (pkg: Package) => {
const yml = await entry(pkg).yml()
const prefix = useCellar().mkpath(pkg)
const platform = usePlatform()
const raw = validateString(validatePlainObject(yml.build).script)
return raw
.replace(/{{\s*arch\s*}}/g, platform.arch)
.replace(/{{\s*target\s*}}/g, platform.target)
.replace(/{{\s*prefix\s*}}/g, prefix.string)
.replace(/{{\s*version\s*}}/g, pkg.version.toString())
.replace(/{{\s*jobs\s*}}/g, navigator.hardwareConcurrency.toString()) //TODO remove, only available with ts build scripts
Expand Down

0 comments on commit 98cfd7f

Please sign in to comment.