Skip to content

Commit

Permalink
Add Exe matcher for Windows releases. (#46)
Browse files Browse the repository at this point in the history
* Add Exe matcher for Windows releases.

* fix docker sh command on Windows

* initialize sample scenarios based on OS

* add comments to cases definition
Ignore the vscode devcontainer configuration

* Revert "add comments to cases definition"

This reverts commit 94cb6e6.

* Revert "initialize sample scenarios based on OS"

This reverts commit 0b639e1.

* Allow to mock OS and Arch for asset filtering tests

* Remove binaries by name (#48)

* Remove binaries by name

* Reuse logic for finding binary path

* make getBinPath check if arg is a path

Co-authored-by: Cristian Dominguez <cristiand391@users.noreply.github.com>

* add resolvers and test cases

* Add Exe matcher for Windows releases.

* fix docker sh command on Windows

* add resolvers and test cases

Co-authored-by: Roberto Ferrer <r.ferrer@innovation.es>
Co-authored-by: Marcos Lilljedahl <marcosnils@gmail.com>
Co-authored-by: Cristian Dominguez <6853656+cristiand391@users.noreply.github.com>
Co-authored-by: Cristian Dominguez <cristiand391@users.noreply.github.com>
Co-authored-by: Sune Keller <sune.keller+github@gmail.com>
  • Loading branch information
6 people authored Mar 15, 2021
1 parent 02a0be2 commit 27cc957
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func processZip(name string, r io.Reader) (string, io.Reader, error) {
func isSupportedExt(filename string) bool {
if ext := strings.TrimPrefix(filepath.Ext(filename), "."); len(ext) > 0 {
switch filetype.GetType(ext) {
case matchers.TypeGz, types.Unknown, matchers.TypeZip, matchers.TypeXz, matchers.TypeTar:
case matchers.TypeGz, types.Unknown, matchers.TypeZip, matchers.TypeXz, matchers.TypeTar, matchers.TypeExe:
break
default:
return false
Expand Down
22 changes: 16 additions & 6 deletions pkg/assets/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@ func (m *mockOSResolver) GetArch() []string {
}

func TestSanitizeName(t *testing.T) {
linuxAMDResolver := &mockOSResolver{OS: []string{"linux"}, Arch: []string{"amd64"}}
windowsAMDResolver := &mockOSResolver{OS: []string{"windows"}, Arch: []string{"amd64"}}
cases := []struct {
in string
v string
out string
resolver platformResolver
}{
{"bin_amd64_linux", "v0.0.1", "bin"},
{"bin_0.0.1_amd64_linux", "0.0.1", "bin"},
{"bin_0.0.1_amd64_linux", "v0.0.1", "bin"},
{"gitlab-runner-linux-amd64", "v13.2.1", "gitlab-runner"},
{"jq-linux64", "jq-1.5", "jq"},
{"bin_amd64_linux", "v0.0.1", "bin",linuxAMDResolver},
{"bin_0.0.1_amd64_linux", "0.0.1", "bin",linuxAMDResolver},
{"bin_0.0.1_amd64_linux", "v0.0.1", "bin",linuxAMDResolver},
{"gitlab-runner-linux-amd64", "v13.2.1", "gitlab-runner",linuxAMDResolver},
{"jq-linux64", "jq-1.5", "jq",linuxAMDResolver},
{"bin_0.0.1_Windows_x86_64.exe","0.0.1","bin.exe",windowsAMDResolver},
}

for _, c := range cases {
resolver = c.resolver
if n := SanitizeName(c.in, c.v); n != c.out {
t.Fatalf("Error replacing %s: %s does not match %s", c.in, n, c.out)
}
Expand All @@ -40,7 +45,7 @@ func TestSanitizeName(t *testing.T) {

func TestFilterAssets(t *testing.T) {
linuxAMDResolver := &mockOSResolver{OS: []string{"linux"}, Arch: []string{"amd64"}}

windowsAMDResolver := &mockOSResolver{OS: []string{"windows"}, Arch: []string{"amd64"}}
type args struct {
repoName string
as []*Asset
Expand Down Expand Up @@ -80,6 +85,11 @@ func TestFilterAssets(t *testing.T) {
{Name: "jq-linux64", URL: "https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64"},
{Name: "jq-osx-amd64", URL: "https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64"},
}}, "jq-linux64", linuxAMDResolver},
{args{"bin", []*Asset{
{Name: "bin_0.0.1_Windows_x86_64.exe", URL: "https://github.com/marcosnils/bin/releases/download/v0.0.1/bin_0.0.1_Windows_x86_64.exe"},
{Name: "bin_0.1.0_Linux_x86_64", URL: "https://github.com/marcosnils/bin/releases/download/v0.0.1/bin_0.1.0_Linux_x86_64"},
{Name: "bin_0.1.0_Darwin_x86_64", URL: "https://github.com/marcosnils/bin/releases/download/v0.0.1/bin_0.1.0_Darwin_x86_64"},
}}, "bin_0.0.1_windows_x86_64.exe", windowsAMDResolver},
}

for _, c := range cases {
Expand Down
4 changes: 3 additions & 1 deletion pkg/providers/docker_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const (
// TODO: there might be a way were users can configure a template for the
// actual execution since some CLIs require some other folders to be mounted
// or networks to be shared
sh = `@docker run --rm -i -t -v %%cd%%:/tmp/cmd -w /tmp/cmd %s:%s "$@"`
sh = `@echo off
docker run --rm -i -t -v %%cd%%:/tmp/cmd -w /tmp/cmd %s:%s %%*
`
)

// getImageName gets the name of the image from the image repo.
Expand Down

0 comments on commit 27cc957

Please sign in to comment.