-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2a9b44
commit 32d5fd7
Showing
11 changed files
with
189 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
bootstrapper "github.com/willabides/bindown/v4/internal/build-bootstrapper" | ||
) | ||
|
||
func defaultBootstrapTag() string { | ||
if Version == "unknown" { | ||
return "" | ||
} | ||
return "v" + Version | ||
} | ||
|
||
type bootstrapCmd struct { | ||
Tag string `kong:"hidden,default=${bootstrap_tag_default}"` | ||
BaseURL string `kong:"hidden,name='base-url',default='https://github.com'"` | ||
Output string `kong:"help='output file, writes to stdout if not set',type='path'"` | ||
} | ||
|
||
func (c *bootstrapCmd) Run(ctx *runContext) error { | ||
if c.Tag == "" { | ||
return fmt.Errorf("version is required") | ||
} | ||
tag := c.Tag | ||
if !strings.HasPrefix(tag, "v") { | ||
tag = "v" + tag | ||
} | ||
opts := bootstrapper.BuildOpts{BaseURL: c.BaseURL} | ||
content, err := bootstrapper.Build(tag, &opts) | ||
if err != nil { | ||
return err | ||
} | ||
if c.Output == "" { | ||
fmt.Fprint(ctx.stdout, content) | ||
return nil | ||
} | ||
err = os.MkdirAll(filepath.Dir(c.Output), 0o755) | ||
if err != nil { | ||
return err | ||
} | ||
err = os.WriteFile(c.Output, []byte(content), 0o755) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/willabides/bindown/v4/internal/testutil" | ||
) | ||
|
||
func Test_bootstrapCmd(t *testing.T) { | ||
output := filepath.Join(t.TempDir(), "foo", "bootstrap.sh") | ||
runner := newCmdRunner(t) | ||
|
||
server := testutil.ServeFile( | ||
t, | ||
testdataPath("build-bootstrapper/checksums.txt"), | ||
"/WillAbides/bindown/releases/download/v4.8.0/checksums.txt", | ||
"", | ||
) | ||
want, err := os.ReadFile(testdataPath("build-bootstrapper/bootstrap-bindown.sh")) | ||
require.NoError(t, err) | ||
result := runner.run("bootstrap", "--output", output, "--tag", "4.8.0", "--base-url", server.URL) | ||
result.assertState(resultState{}) | ||
got, err := os.ReadFile(output) | ||
require.NoError(t, err) | ||
require.Equal(t, string(want), string(got)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
internal/bindown/testdata/build-bootstrapper/checksums.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
26fcbc738bf9bb910b070f236816b2dfe5bc9589be3a578135f37d950ebaf771 bindown_4.8.0_freebsd_amd64.tar.gz | ||
2fa6460ebe8d7c6be33576acf5b63f7208780af72d758e82313f6c5772e097d5 bindown_4.8.0_linux_386.tar.gz | ||
32e3fbfaecf41a1b2bced22c1842b3905f4e6de1e879a4db68402799c206415d bindown_4.8.0_windows_386.exe | ||
335802ed91fa6f040e10570479a6c817c7e42bd57fe98c959890a821099d3e1f bindown_4.8.0_freebsd_arm64 | ||
372846f7edd9d93df0cb17889790f595f17cb083e093f3e6437d34e3253fd378 bindown_4.8.0_windows_amd64.exe | ||
40acf94b7c69e5d4101cb46ea99641d302ff23579cd7ead29a5abfceb1a5d9ba bindown_4.8.0_linux_arm64.tar.gz | ||
66aca230d9aea549ecd3647082b63752f5bb5307ef6954a08cc0eaf9c70723f1 bindown_4.8.0_windows_amd64.tar.gz | ||
752c78a926be1287312eea3c831e841e223de4780d1e4a8a813432d0a73f890b bindown_4.8.0_linux_amd64.tar.gz | ||
7f1f1c883beceb6ec3919484511fb20c3ceb41088e814d6fc234b015e98b78d9 bindown_4.8.0_darwin_arm64 | ||
7fdfbc007c0c285a498bf251bd4ab7469f334752581b45fda5ad6450ddd23377 bindown_4.8.0_windows_arm64.exe | ||
95764bf76b54d5b13b9b8a801635d82447ee349c3545145ddd8a0a84246d66e2 bindown_4.8.0_freebsd_arm64.tar.gz | ||
966087f13a6cf82804456119289ab982f2eee3ad04d8d4fb6ce74bd7eabdf74e bindown_4.8.0_windows_386.tar.gz | ||
9b29e37ba273bc0dca9c8227ee4b58153289073ede7d900e9c84ae3c71f3dff5 bindown_4.8.0_windows_arm64.tar.gz | ||
a625900e52f4413bee3863062463cc24f9c0669841fd6bc9979ee599edd88f3e bindown_4.8.0_freebsd_amd64 | ||
ba09df557edc4499f41ddadc26369d7f70ed20bfb8310662f1290e6a355343e8 bindown_4.8.0_darwin_amd64.tar.gz | ||
cd7b917d2737fe9fa087aea172d9b581757e9b300fa1d1dbd83c1b765be05bdb bindown_4.8.0_freebsd_386.tar.gz | ||
d5d35274d4eab337c107940fc5b326c51f5bfd70d00924c79011684e2a0d4f22 bindown_4.8.0_freebsd_386 | ||
d71d6c436ad33bb3aa01468698b86d5423127a19f9b1c664e346cc502501d415 bindown_4.8.0_darwin_arm64.tar.gz | ||
d9361698bc1571c34915496da9c624e89fa12d87731711efd2cbbc9136c6fa85 bindown_4.8.0_darwin_amd64 | ||
d93eae8638b96682d0e9b55bcbe92fecb296afd442e0526cc94ce0160c108c13 bindown_4.8.0_linux_arm64 | ||
ec3d19abd00fbf099a98edb64c569842fa5b909222fb10da86d668f5597885be bindown_4.8.0_linux_amd64 | ||
fa7e87f49aa30e42485431bd9dd021a32924ab11e4d39065533e9bccce182de4 bindown_4.8.0_linux_386 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.