Skip to content

Commit

Permalink
fix Atmos binary name on Windows (like Terragrunt) (#171)
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Vaumoron <[email protected]>
  • Loading branch information
dvaumoron authored Jun 13, 2024
1 parent 59933f3 commit dcd10d8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
34 changes: 34 additions & 0 deletions pkg/winbin/winbin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
*
* Copyright 2024 tofuutils authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package winbin

import "runtime"

const (
WinBinSuffix = ".exe"
WinOsName = "windows"
)

func GetBinaryName(execName string) string {
if runtime.GOOS == WinOsName {
return execName + WinBinSuffix
}

return execName
}
7 changes: 4 additions & 3 deletions versionmanager/retriever/atmos/atmosretriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
sha256check "github.com/tofuutils/tenv/pkg/check/sha256"
"github.com/tofuutils/tenv/pkg/download"
"github.com/tofuutils/tenv/pkg/github"
"github.com/tofuutils/tenv/pkg/winbin"
htmlretriever "github.com/tofuutils/tenv/versionmanager/retriever/html"
)

Expand Down Expand Up @@ -110,7 +111,7 @@ func (r AtmosRetriever) InstallRelease(versionStr string, targetPath string) err
return err
}

return os.WriteFile(filepath.Join(targetPath, config.AtmosName), data, 0755)
return os.WriteFile(filepath.Join(targetPath, winbin.GetBinaryName(config.AtmosName)), data, 0755)
}

func (r AtmosRetriever) ListReleases() ([]string, error) {
Expand Down Expand Up @@ -149,8 +150,8 @@ func buildAssetNames(version string, arch string) (string, string) {
nameBuilder.WriteString(runtime.GOOS)
nameBuilder.WriteByte('_')
nameBuilder.WriteString(arch)
if runtime.GOOS == "windows" {
nameBuilder.WriteString(".exe")
if runtime.GOOS == winbin.WinOsName {
nameBuilder.WriteString(winbin.WinBinSuffix)
}

return nameBuilder.String(), sumsAssetName
Expand Down
12 changes: 4 additions & 8 deletions versionmanager/retriever/terragrunt/terragruntretriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
sha256check "github.com/tofuutils/tenv/pkg/check/sha256"
"github.com/tofuutils/tenv/pkg/download"
"github.com/tofuutils/tenv/pkg/github"
"github.com/tofuutils/tenv/pkg/winbin"
htmlretriever "github.com/tofuutils/tenv/versionmanager/retriever/html"
)

Expand Down Expand Up @@ -107,12 +108,7 @@ func (r TerragruntRetriever) InstallRelease(versionStr string, targetPath string
return err
}

terragruntBinaryName := config.TerragruntName
if runtime.GOOS == "windows" {
terragruntBinaryName = terragruntBinaryName + ".exe"
}

return os.WriteFile(filepath.Join(targetPath, terragruntBinaryName), data, 0755)
return os.WriteFile(filepath.Join(targetPath, winbin.GetBinaryName(config.TerragruntName)), data, 0755)
}

func (r TerragruntRetriever) ListReleases() ([]string, error) {
Expand Down Expand Up @@ -147,8 +143,8 @@ func buildAssetNames(arch string) (string, string) {
nameBuilder.WriteString(runtime.GOOS)
nameBuilder.WriteByte('_')
nameBuilder.WriteString(arch)
if runtime.GOOS == "windows" {
nameBuilder.WriteString(".exe")
if runtime.GOOS == winbin.WinOsName {
nameBuilder.WriteString(winbin.WinBinSuffix)
}

return nameBuilder.String(), "SHA256SUMS"
Expand Down

0 comments on commit dcd10d8

Please sign in to comment.