Skip to content

Commit 8c9ad51

Browse files
committed
make cache dir to prevent build failures
Some tools don’t think to `mkdir -p` directories that are usually there. Refs pkgxdev/pantry#4807
1 parent 749e90c commit 8c9ad51

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

bin/cmd/build

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { gum, rsync } from "brewkit/utils.ts"
55
import fix_up from "brewkit/porcelain/fix-up.ts"
66
import { Command } from "cliffy/command/mod.ts"
77
import fetch from "brewkit/porcelain/fetch.ts"
8-
import get_config from "brewkit/config.ts"
8+
import get_config, { platform_cache } from "brewkit/config.ts"
99
import { Path, hooks, utils } from "pkgx"
1010
import * as YAML from "deno/yaml/mod.ts"
1111
const { useConfig } = hooks
@@ -121,6 +121,8 @@ if (env['GITHUB_TOKEN']) {
121121
env['GH_TOKEN'] = env['GITHUB_TOKEN']
122122
}
123123

124+
platform_cache(() => config.path.home).mkdir('p') // we’ve indeed found things to break without this
125+
124126
const proc = new Deno.Command(script.string, {clearEnv: true, env}).spawn()
125127
const rv = await proc.status
126128
if (!rv.success) throw new Error(`${rv.code} ${rv.signal}`)

bin/cmd/test

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { Package, PackageRequirement, Path, hooks, utils } from "pkgx"
77
import { gum, find_pkgx, rsync, find_in_PATH } from "brewkit/utils.ts"
8-
import get_config from "brewkit/config.ts"
8+
import get_config, { platform_cache } from "brewkit/config.ts"
99
import * as YAML from "deno/yaml/mod.ts"
1010
import undent from "outdent"
1111
import useConfig from "libpkgx/hooks/useConfig.ts";
@@ -99,6 +99,8 @@ if (env['GITHUB_TOKEN']) {
9999
env['GH_TOKEN'] = env['GITHUB_TOKEN']
100100
}
101101

102+
platform_cache(() => config.path.home).mkdir('p') // we’ve indeed found things to break without this
103+
102104
const proc = new Deno.Command(script.string, {clearEnv: true, env}).spawn()
103105
const rv = await proc.status
104106
if (!rv.success) throw new Error(`${rv.code} ${rv.signal}`)

lib/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ export default async function config(arg?: string): Promise<Config> {
104104
}
105105
}
106106

107-
function platform_cache() {
107+
export function platform_cache(home = Path.home) {
108108
return flatmap(Deno.env.get('XDG_CACHE_HOME'), Path.abs) ?? (platform =>
109-
platform == 'darwin' ? Path.home().join('Library/Caches') : Path.home().join(".cache")
109+
platform == 'darwin' ? home().join('Library/Caches') : home().join(".cache")
110110
)(host().platform)
111111
}
112112

projects/version-transformer.com/package.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ build:
88
echo {{version}} > VERSION
99
1010
test:
11-
test $(cat {{prefix}}/VERSION) = {{version}}
11+
- test $(cat {{prefix}}/VERSION) = {{version}}
12+
13+
# test that cache directories are created in our sandbox
14+
- run: touch ~/.cache/foo
15+
if: linux
16+
- run: touch ~/Library/Caches/foo
17+
if: darwin

0 commit comments

Comments
 (0)