Skip to content

Commit c215ead

Browse files
committed
WIP
1 parent b4b30ee commit c215ead

File tree

15 files changed

+186
-79
lines changed

15 files changed

+186
-79
lines changed

cmd/bindown/cli.go

+2
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ type wrapCmd struct {
324324
AllowMissingChecksum bool `kong:"name=allow-missing-checksum,help=${allow_missing_checksum}"`
325325
BindownExec string `kong:"name=bindown,help=${install_bindown_help}"`
326326
BindownTag string `kong:"hidden,default=${bootstrap_tag_default}"`
327+
BaseURL string `kong:"hidden,name='base-url',default='https://github.com'"`
327328
}
328329

329330
func (d *wrapCmd) Run(ctx *runContext) error {
@@ -339,6 +340,7 @@ func (d *wrapCmd) Run(ctx *runContext) error {
339340
AllDeps: d.All,
340341
BindownTag: d.BindownTag,
341342
BindownWrapped: os.Getenv("BINDOWN_WRAPPED"),
343+
BaseURL: d.BaseURL,
342344
})
343345
}
344346

cmd/bindown/cli_test.go

+53-31
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,7 @@ url_checksums:
417417
stdout: `installed foo to`,
418418
})
419419
wantBin := filepath.Join(runner.tmpDir, "bin", "foo")
420-
require.FileExists(t, wantBin)
421-
stat, err := os.Stat(wantBin)
422-
require.NoError(t, err)
423-
testutil.AssertExecutable(t, stat.Mode())
420+
testutil.AssertFile(t, wantBin, true, false)
424421
})
425422

426423
t.Run("link raw file", func(t *testing.T) {
@@ -441,11 +438,7 @@ url_checksums:
441438
stdout: `installed foo to`,
442439
})
443440
wantBin := filepath.Join(runner.tmpDir, "bin", "foo")
444-
require.FileExists(t, wantBin)
445-
stat, err := os.Lstat(wantBin)
446-
require.NoError(t, err)
447-
testutil.AssertExecutable(t, stat.Mode())
448-
require.True(t, stat.Mode()&os.ModeSymlink != 0)
441+
testutil.AssertFile(t, wantBin, true, true)
449442
})
450443

451444
t.Run("bin in root", func(t *testing.T) {
@@ -465,10 +458,7 @@ url_checksums:
465458
stdout: `installed foo to`,
466459
})
467460
wantBin := filepath.Join(runner.tmpDir, "bin", "foo")
468-
require.FileExists(t, wantBin)
469-
stat, err := os.Stat(wantBin)
470-
require.NoError(t, err)
471-
testutil.AssertExecutable(t, stat.Mode())
461+
testutil.AssertFile(t, wantBin, true, false)
472462
})
473463

474464
t.Run("wrong checksum", func(t *testing.T) {
@@ -491,29 +481,61 @@ url_checksums:
491481
}
492482

493483
func Test_wrapCmd(t *testing.T) {
494-
runner := newCmdRunner(t)
495-
servePath := testdataPath("downloadables/runnable.tar.gz")
496-
ts := testutil.ServeFile(t, servePath, "/runnable/runnable.tar.gz", "")
497-
depURL := ts.URL + "/runnable/runnable.tar.gz"
498-
runner.writeConfigYaml(fmt.Sprintf(`
484+
t.Run("bindown path", func(t *testing.T) {
485+
runner := newCmdRunner(t)
486+
servePath := testdataPath("downloadables/runnable.tar.gz")
487+
ts := testutil.ServeFile(t, servePath, "/runnable/runnable.tar.gz", "")
488+
depURL := ts.URL + "/runnable/runnable.tar.gz"
489+
runner.writeConfigYaml(fmt.Sprintf(`
499490
dependencies:
500491
runnable:
501492
archive_path: bin/runnable.sh
502493
url: %s
503494
url_checksums:
504495
%s: fb2fe41a34b77ee180def0cb9a222d8776a6e581106009b64f35983da291ab6e
505496
`, depURL, depURL))
506-
outputDir := filepath.Join(runner.tmpDir, "output")
507-
result := runner.run("wrap", "runnable", "bindown", "--bindown-tag", "v4.10.0", "--output", outputDir)
508-
testutil.CheckGoldenDir(t, outputDir, filepath.FromSlash("testdata/golden/wrap"))
509-
wantRunnable := filepath.Join(outputDir, "runnable")
510-
wantBindown := filepath.Join(outputDir, "bindown")
511-
result.assertState(resultState{stdout: wantBindown + "\n" + wantRunnable})
512-
info, err := os.Stat(wantRunnable)
513-
require.NoError(t, err)
514-
testutil.AssertExecutable(t, info.Mode())
515-
cmd := exec.Command("sh", "-c", filepath.ToSlash(wantRunnable))
516-
out, err := cmd.Output()
517-
require.NoError(t, err)
518-
require.Equal(t, "Hello world", strings.TrimSpace(string(out)))
497+
outputDir := filepath.Join(runner.tmpDir, "output")
498+
runnable := filepath.Join(outputDir, "runnable")
499+
result := runner.run("wrap", "runnable", "--bindown", testutil.BindownBin(), "--output", runnable)
500+
result.assertState(resultState{stdout: runnable})
501+
testutil.AssertFile(t, runnable, true, false)
502+
testutil.CheckGoldenDir(t, outputDir, filepath.FromSlash("testdata/golden/wrap/bindown-path"))
503+
504+
// make sure it runs
505+
cmd := exec.Command("sh", "-c", filepath.ToSlash(runnable))
506+
out, err := cmd.Output()
507+
require.NoError(t, err)
508+
require.Equal(t, "Hello world", strings.TrimSpace(string(out)))
509+
})
510+
511+
t.Run("wrap bindown", func(t *testing.T) {
512+
runner := newCmdRunner(t)
513+
servePath := testdataPath("downloadables/runnable.tar.gz")
514+
ts := testutil.ServeFiles(t, map[string]string{
515+
"/runnable/runnable.tar.gz": servePath,
516+
"/WillAbides/bindown/releases/download/v4.8.0/checksums.txt": "testdata/bootstrap/checksums.txt",
517+
})
518+
depURL := ts.URL + "/runnable/runnable.tar.gz"
519+
runner.writeConfigYaml(fmt.Sprintf(`
520+
dependencies:
521+
runnable:
522+
archive_path: bin/runnable.sh
523+
url: %s
524+
url_checksums:
525+
%s: fb2fe41a34b77ee180def0cb9a222d8776a6e581106009b64f35983da291ab6e
526+
`, depURL, depURL))
527+
outputDir := filepath.Join(runner.tmpDir, "output")
528+
runnable := filepath.Join(outputDir, "runnable")
529+
bindown := filepath.Join(outputDir, "bindown")
530+
result := runner.run(
531+
"wrap", "runnable", "bindown",
532+
"--bindown-tag", "v4.8.0",
533+
"--output", outputDir,
534+
"--base-url", ts.URL,
535+
)
536+
result.assertState(resultState{stdout: bindown + "\n" + runnable})
537+
testutil.AssertFile(t, runnable, true, false)
538+
testutil.AssertFile(t, bindown, true, false)
539+
testutil.CheckGoldenDir(t, outputDir, filepath.FromSlash("testdata/golden/wrap/wrap-bindown"))
540+
})
519541
}

cmd/bindown/testdata/golden/bootstrap/bootstrap.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,11 @@ install_bindown() {
226226
checksums="$2"
227227
bindir="$3"
228228
use_checksum_path="$4"
229+
repo_url="$5"
229230

230231
version=${tag#v}
231232
tarball="bindown_${version}_$(uname_os)_$(uname_arch).tar.gz"
232-
tarball_url="https://github.com/WillAbides/bindown/releases/download/${tag}/${tarball}"
233+
tarball_url="$repo_url/releases/download/${tag}/${tarball}"
233234

234235
if [ -n "$use_checksum_path" ]; then
235236
tarball_checksum="$(echo "$checksums" | grep "$tarball" | tr '\t' ' ' | cut -d ' ' -f 1)"
@@ -256,6 +257,8 @@ install_bindown() {
256257

257258
bindown_bindir="./bin"
258259

260+
BINDOWN_REPO_URL="${BINDOWN_REPO_URL:-"https://github.com/WillAbides/bindown"}"
261+
259262
if [ -n "$BINDIR" ]; then
260263
bindown_bindir="$BINDIR"
261264
fi
@@ -277,4 +280,4 @@ while getopts "b:cdh?x" arg; do
277280
esac
278281
done
279282

280-
install_bindown "${bindown_tag:?}" "${bindown_checksums:?}" "$bindown_bindir" "$opt_use_checksum_path" > /dev/null
283+
install_bindown "${bindown_tag:?}" "${bindown_checksums:?}" "$bindown_bindir" "$opt_use_checksum_path" "$BINDOWN_REPO_URL" > /dev/null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
# Code generated by bindown. DO NOT EDIT.
3+
4+
set -e
5+
6+
bindown_bin="$(
7+
CDPATH="" cd -- "$(dirname -- "$0")"
8+
9+
"../../bindown" install "runnable" \
10+
--to-cache \
11+
--configfile "../.bindown.yaml" \
12+
--cache "../cache"
13+
)"
14+
15+
exec "$bindown_bin" "$@"

cmd/bindown/testdata/golden/wrap/bindown renamed to cmd/bindown/testdata/golden/wrap/wrap-bindown/bindown

+28-25
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@
22

33
set -e
44

5-
bindown_tag="v4.10.0"
5+
bindown_tag="v4.8.0"
66

77
bindown_checksums="
8-
01e791222daf976faf7392f67062a50f5fcd9e0f7b6260ebf0f3e992c034370e bindown_4.10.0_linux_386
9-
19b383ffadaaabee67a890b743a729a605ecbb520a76ed9221f66313642e023f bindown_4.10.0_darwin_amd64.tar.gz
10-
2564c8ba3b959e8d60dbb4ab9688872d2fd121af1c92d73d174f8a163c0edda0 bindown_4.10.0_freebsd_386
11-
2cdaa446fdd5b4d3d3f31fc337f926dc53a59b4653d893727fb15e51ef32e37f bindown_4.10.0_linux_arm64.tar.gz
12-
39161acbcd353df5d36b36c778a59d57b4c1932afb61c6d44c2b7dddeb3e5c9a bindown_4.10.0_freebsd_amd64
13-
3dcbd154b90820da88b1ef1229a38ed5d729235e75f8ad653aeee33c937d93ff bindown_4.10.0_freebsd_amd64.tar.gz
14-
412e4808f59c718817c22efd3633797d0095e172a96ea4917bdfe07f853b6599 bindown_4.10.0_windows_386.tar.gz
15-
5da178b2f88b9c753a3f1995c3a65541b080d2d18a681ed14676ca83fc2ea188 bindown_4.10.0_darwin_arm64.tar.gz
16-
707b4e20364f2edde076e31c4a2aeefdbaadb3aa33ffc6ae5b2f50c3b46d36d6 bindown_4.10.0_darwin_amd64
17-
795e4b052eb3aeadf29f3abd52c764a2150126c7ec19201c1f2cae669c545e0d bindown_4.10.0_linux_amd64
18-
7fd50b8e29fa92f33def27f8bc1ef6d3a45a3e903372d96e3a5714eef187f87d bindown_4.10.0_linux_amd64.tar.gz
19-
82a06d8543386b113931808652357014406d3c9feb98c1b8d7e3c3a301116c72 bindown_4.10.0_windows_386.exe
20-
8316987b6d54fba9eda9ddaf19cfaf8bb6e99fe4218ffbc716feb64956ea7113 bindown_4.10.0_windows_amd64.exe
21-
83e76a3c3452add87ab5fac2278de3aeba13403449d0a174ae38cc5e5bd7edfc bindown_4.10.0_freebsd_arm64
22-
95e1b14057ada57875387a3355c0574a86cf3724863ff0d1e289b00d80443c49 bindown_4.10.0_windows_arm64.tar.gz
23-
a0cdbe93ae7b3d182cbb5d73d05ac675e371f9b5062e4b68fd0860720e4f9eaf bindown_4.10.0_windows_amd64.tar.gz
24-
ab5b6e62f7ed8cd4cd6c86d05d604fcc3f86de45aea13a8ba32641fa239ac901 bindown_4.10.0_freebsd_386.tar.gz
25-
ac3430d7847faf7ac573fbce890b2c7ffee12b37fdd0dd41300f9d24dcd24aee bindown_4.10.0_darwin_arm64
26-
c79be0ecdb590faf6b830af2856d5a3e72e80fe4dabcff63cc5d8b372dcc3d81 bindown_4.10.0_linux_386.tar.gz
27-
cbee4f7ff608f057b36f17624bc3a266ca09819e6450933c392763dd92a2cfe3 bindown_4.10.0_linux_arm64
28-
d711ebab02ef95b8b4e14cb0ede6a82ad8d796dae49281b2bf38e99e96d39dba bindown_4.10.0_windows_arm64.exe
29-
e454053e1e222490da3c558b971c4f4db92aa566cd87be28860c9947228f6b84 bindown_4.10.0_freebsd_arm64.tar.gz
8+
26fcbc738bf9bb910b070f236816b2dfe5bc9589be3a578135f37d950ebaf771 bindown_4.8.0_freebsd_amd64.tar.gz
9+
2fa6460ebe8d7c6be33576acf5b63f7208780af72d758e82313f6c5772e097d5 bindown_4.8.0_linux_386.tar.gz
10+
32e3fbfaecf41a1b2bced22c1842b3905f4e6de1e879a4db68402799c206415d bindown_4.8.0_windows_386.exe
11+
335802ed91fa6f040e10570479a6c817c7e42bd57fe98c959890a821099d3e1f bindown_4.8.0_freebsd_arm64
12+
372846f7edd9d93df0cb17889790f595f17cb083e093f3e6437d34e3253fd378 bindown_4.8.0_windows_amd64.exe
13+
40acf94b7c69e5d4101cb46ea99641d302ff23579cd7ead29a5abfceb1a5d9ba bindown_4.8.0_linux_arm64.tar.gz
14+
66aca230d9aea549ecd3647082b63752f5bb5307ef6954a08cc0eaf9c70723f1 bindown_4.8.0_windows_amd64.tar.gz
15+
752c78a926be1287312eea3c831e841e223de4780d1e4a8a813432d0a73f890b bindown_4.8.0_linux_amd64.tar.gz
16+
7f1f1c883beceb6ec3919484511fb20c3ceb41088e814d6fc234b015e98b78d9 bindown_4.8.0_darwin_arm64
17+
7fdfbc007c0c285a498bf251bd4ab7469f334752581b45fda5ad6450ddd23377 bindown_4.8.0_windows_arm64.exe
18+
95764bf76b54d5b13b9b8a801635d82447ee349c3545145ddd8a0a84246d66e2 bindown_4.8.0_freebsd_arm64.tar.gz
19+
966087f13a6cf82804456119289ab982f2eee3ad04d8d4fb6ce74bd7eabdf74e bindown_4.8.0_windows_386.tar.gz
20+
9b29e37ba273bc0dca9c8227ee4b58153289073ede7d900e9c84ae3c71f3dff5 bindown_4.8.0_windows_arm64.tar.gz
21+
a625900e52f4413bee3863062463cc24f9c0669841fd6bc9979ee599edd88f3e bindown_4.8.0_freebsd_amd64
22+
ba09df557edc4499f41ddadc26369d7f70ed20bfb8310662f1290e6a355343e8 bindown_4.8.0_darwin_amd64.tar.gz
23+
cd7b917d2737fe9fa087aea172d9b581757e9b300fa1d1dbd83c1b765be05bdb bindown_4.8.0_freebsd_386.tar.gz
24+
d5d35274d4eab337c107940fc5b326c51f5bfd70d00924c79011684e2a0d4f22 bindown_4.8.0_freebsd_386
25+
d71d6c436ad33bb3aa01468698b86d5423127a19f9b1c664e346cc502501d415 bindown_4.8.0_darwin_arm64.tar.gz
26+
d9361698bc1571c34915496da9c624e89fa12d87731711efd2cbbc9136c6fa85 bindown_4.8.0_darwin_amd64
27+
d93eae8638b96682d0e9b55bcbe92fecb296afd442e0526cc94ce0160c108c13 bindown_4.8.0_linux_arm64
28+
ec3d19abd00fbf099a98edb64c569842fa5b909222fb10da86d668f5597885be bindown_4.8.0_linux_amd64
29+
fa7e87f49aa30e42485431bd9dd021a32924ab11e4d39065533e9bccce182de4 bindown_4.8.0_linux_386
3030
"
3131

3232
cat /dev/null << EOF
@@ -226,10 +226,11 @@ install_bindown() {
226226
checksums="$2"
227227
bindir="$3"
228228
use_checksum_path="$4"
229+
repo_url="$5"
229230

230231
version=${tag#v}
231232
tarball="bindown_${version}_$(uname_os)_$(uname_arch).tar.gz"
232-
tarball_url="https://github.com/WillAbides/bindown/releases/download/${tag}/${tarball}"
233+
tarball_url="$repo_url/releases/download/${tag}/${tarball}"
233234

234235
if [ -n "$use_checksum_path" ]; then
235236
tarball_checksum="$(echo "$checksums" | grep "$tarball" | tr '\t' ' ' | cut -d ' ' -f 1)"
@@ -256,12 +257,14 @@ install_bindown() {
256257

257258
bindown_bindir="../cache/bootstrapped"
258259

260+
BINDOWN_REPO_URL="${BINDOWN_REPO_URL:-"https://github.com/WillAbides/bindown"}"
261+
259262
script_dir="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"
260263
bindown_bindir="$script_dir/$bindown_bindir"
261264

262265
log_set_priority 3 # log at error level
263266

264-
bindown_exec="$(install_bindown "${bindown_tag:?}" "${bindown_checksums:?}" "$bindown_bindir" "1")"
267+
bindown_exec="$(install_bindown "${bindown_tag:?}" "${bindown_checksums:?}" "$bindown_bindir" "1" "$BINDOWN_REPO_URL")"
265268

266269
BINDOWN_WRAPPED="${BINDOWN_WRAPPED:-"$script_dir/$(basename "$0")"}"
267270
export BINDOWN_WRAPPED

internal/bindown/config.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ type ConfigWrapDependenciesOpts struct {
500500
BindownExec string
501501
BindownTag string
502502
BindownWrapped string
503+
BaseURL string
503504
AllowMissingChecksum bool
504505
AllDeps bool
505506
Stdout io.Writer
@@ -539,7 +540,7 @@ func (c *Config) WrapDependencies(deps []string, opts *ConfigWrapDependenciesOpt
539540
if outputIsDir {
540541
target = filepath.Join(output, "bindown")
541542
}
542-
out, err := createBindownWrapper(target, c.Cache, opts.BindownTag)
543+
out, err := createBindownWrapper(target, c.Cache, opts.BindownTag, opts.BaseURL)
543544
if err != nil {
544545
return err
545546
}

internal/bindown/config_test.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,7 @@ dependencies:
220220
})
221221
require.NoError(t, err)
222222
require.Equal(t, wantStdout, stdout.String())
223-
require.True(t, FileExists(wantBin))
224-
stat, err := os.Stat(wantBin)
225-
require.NoError(t, err)
226-
require.False(t, stat.IsDir())
227-
testutil.AssertExecutable(t, stat.Mode())
223+
testutil.AssertFile(t, wantBin, true, false)
228224
})
229225

230226
t.Run("bin in root", func(t *testing.T) {

internal/bindown/install.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func createWrapper(name, target, bindownExec, cacheDir, configFile string, missi
172172
return target, nil
173173
}
174174

175-
func createBindownWrapper(target, cacheDir, tag string) (string, error) {
175+
func createBindownWrapper(target, cacheDir, tag, baseURL string) (string, error) {
176176
wrapperDir := filepath.Dir(target)
177177
err := os.MkdirAll(wrapperDir, 0o750)
178178
if err != nil {
@@ -188,8 +188,9 @@ func createBindownWrapper(target, cacheDir, tag string) (string, error) {
188188
return "", err
189189
}
190190
content, err := bootstrapper.Build(tag, &bootstrapper.BuildOpts{
191-
BinDir: binDir,
192-
Wrap: true,
191+
BinDir: binDir,
192+
Wrap: true,
193+
BaseURL: baseURL,
193194
})
194195
if err != nil {
195196
return "", err

internal/build-bootstrapper/assets/bootstrap-main.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
BINDOWN_REPO_URL="${BINDOWN_REPO_URL:-"https://github.com/WillAbides/bindown"}"
2+
13
if [ -n "$BINDIR" ]; then
24
bindown_bindir="$BINDIR"
35
fi
@@ -19,4 +21,4 @@ while getopts "b:cdh?x" arg; do
1921
esac
2022
done
2123

22-
install_bindown "${bindown_tag:?}" "${bindown_checksums:?}" "$bindown_bindir" "$opt_use_checksum_path" > /dev/null
24+
install_bindown "${bindown_tag:?}" "${bindown_checksums:?}" "$bindown_bindir" "$opt_use_checksum_path" "$BINDOWN_REPO_URL" > /dev/null

internal/build-bootstrapper/assets/lib.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ install_bindown() {
2222
checksums="$2"
2323
bindir="$3"
2424
use_checksum_path="$4"
25+
repo_url="$5"
2526

2627
version=${tag#v}
2728
tarball="bindown_${version}_$(uname_os)_$(uname_arch).tar.gz"
28-
tarball_url="https://github.com/WillAbides/bindown/releases/download/${tag}/${tarball}"
29+
tarball_url="$repo_url/releases/download/${tag}/${tarball}"
2930

3031
if [ -n "$use_checksum_path" ]; then
3132
tarball_checksum="$(echo "$checksums" | grep "$tarball" | tr '\t' ' ' | cut -d ' ' -f 1)"

internal/build-bootstrapper/assets/wrap-main.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
BINDOWN_REPO_URL="${BINDOWN_REPO_URL:-"https://github.com/WillAbides/bindown"}"
2+
13
script_dir="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"
24
bindown_bindir="$script_dir/$bindown_bindir"
35

46
log_set_priority 3 # log at error level
57

6-
bindown_exec="$(install_bindown "${bindown_tag:?}" "${bindown_checksums:?}" "$bindown_bindir" "1")"
8+
bindown_exec="$(install_bindown "${bindown_tag:?}" "${bindown_checksums:?}" "$bindown_bindir" "1" "$BINDOWN_REPO_URL")"
79

810
BINDOWN_WRAPPED="${BINDOWN_WRAPPED:-"$script_dir/$(basename "$0")"}"
911
export BINDOWN_WRAPPED

internal/build-bootstrapper/build.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ func Build(tag string, opts *BuildOpts) (_ string, errOut error) {
3030
if baseURL == "" {
3131
baseURL = "https://github.com"
3232
}
33-
checksumsURL := fmt.Sprintf(
34-
`%s/WillAbides/bindown/releases/download/%s/checksums.txt`,
35-
baseURL, tag,
36-
)
33+
repoURL := fmt.Sprintf("%s/WillAbides/bindown", baseURL)
34+
checksumsURL := fmt.Sprintf(`%s/releases/download/%s/checksums.txt`, repoURL, tag)
3735
resp, err := http.Get(checksumsURL)
3836
if err != nil {
3937
return "", err
@@ -70,6 +68,7 @@ func Build(tag string, opts *BuildOpts) (_ string, errOut error) {
7068
"lib": assetContent("lib.sh"),
7169
"main": mainSh,
7270
"bindir": binDir,
71+
"repo_url": repoURL,
7372
})
7473
if err != nil {
7574
return "", err

0 commit comments

Comments
 (0)