Skip to content

Commit 8c06437

Browse files
committed
Add force flag for integration testing
1 parent 0eba1a6 commit 8c06437

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

toolprovider/mise/install.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package mise
33
import (
44
"errors"
55
"fmt"
6+
"os"
67

78
"github.com/bitrise-io/bitrise/v2/log"
89
"github.com/bitrise-io/bitrise/v2/toolprovider/mise/execenv"
@@ -14,7 +15,7 @@ func installRequest(toolRequest provider.ToolRequest, useNix bool) provider.Tool
1415
if useNix {
1516
return provider.ToolRequest{
1617
// Use Mise's backend plugin convention of pluginID:toolID
17-
ToolName: provider.ToolID(fmt.Sprintf("%s:%s", nixpkgs.PluginName,toolRequest.ToolName)),
18+
ToolName: provider.ToolID(fmt.Sprintf("%s:%s", nixpkgs.PluginName, toolRequest.ToolName)),
1819
UnparsedVersion: toolRequest.UnparsedVersion,
1920
ResolutionStrategy: toolRequest.ResolutionStrategy,
2021
PluginURL: nil, // Not relevant when using nixpkgs backend plugin
@@ -24,29 +25,41 @@ func installRequest(toolRequest provider.ToolRequest, useNix bool) provider.Tool
2425
}
2526
}
2627

27-
func (m *MiseToolProvider) canBeInstalledWithNix(tool provider.ToolRequest) (bool, error) {
28+
func canBeInstalledWithNix(tool provider.ToolRequest, execEnv execenv.ExecEnv) bool {
2829
if !nixpkgs.ShouldUseBackend(tool) {
29-
return false, nil
30+
return false
3031
}
3132

32-
output, err := m.ExecEnv.RunMisePlugin("install", nixpkgs.PluginName, nixpkgs.PluginGitURL)
33+
// Force switch for integration testing. No fallback to regular install when this is active. This makes failures explicit.
34+
forceNix := os.Getenv("BITRISE_TOOLSETUP_FAST_INSTALL_FORCE") == "1"
35+
36+
_, err := execEnv.RunMisePlugin("install", nixpkgs.PluginName, nixpkgs.PluginGitURL)
3337
if err != nil {
34-
return false, fmt.Errorf("install %s: %s", nixpkgs.PluginGitURL, output)
38+
if forceNix {
39+
return true
40+
}
41+
log.Warnf("Error while installing nixpkgs plugin (%s). Falling back to core plugin installation.", nixpkgs.PluginGitURL, err)
42+
return false
3543
}
3644

3745
nameWithBackend := provider.ToolID(fmt.Sprintf("nixpkgs:%s", tool.ToolName))
38-
39-
available, err := m.versionExists(nameWithBackend, tool.UnparsedVersion)
46+
available, err := versionExists(execEnv, nameWithBackend, tool.UnparsedVersion)
4047
if err != nil {
48+
if forceNix {
49+
return true
50+
}
4151
log.Warnf("Error while checking nixpkgs index for %s@%s: %v. Falling back to core plugin installation.", tool.ToolName, tool.UnparsedVersion, err)
42-
return false, nil
52+
return false
4353
}
4454
if !available {
55+
if forceNix {
56+
return true
57+
}
4558
log.Warnf("%s@%s not found in nixpkgs index, doing a source build. This may take some time...", tool.ToolName, tool.UnparsedVersion)
46-
return false, nil
59+
return false
4760
}
4861

49-
return true, nil
62+
return true
5063
}
5164

5265
func (m *MiseToolProvider) installToolVersion(tool provider.ToolRequest) error {

0 commit comments

Comments
 (0)