-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proof of Concept: First class support for steps written in Swift. (#795)
* Getting started with swift. * Running swift steps in release mode. * Adding support for binary swift packages. * Commenting out tests in order to preserve the example. * Adding config for more complete test step. * Cleaning up. * Pointing to bin. * Removed test code.
- Loading branch information
Showing
4 changed files
with
95 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package toolkits | ||
|
||
import ( | ||
"github.com/bitrise-io/bitrise/models" | ||
"github.com/bitrise-io/bitrise/utils" | ||
stepmanModels "github.com/bitrise-io/stepman/models" | ||
"io" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// SwiftToolkit ... | ||
type SwiftToolkit struct { | ||
} | ||
|
||
// Bootstrap ... | ||
func (toolkit SwiftToolkit) Bootstrap() error { | ||
return nil | ||
} | ||
|
||
// Install ... | ||
func (toolkit SwiftToolkit) Install() error { | ||
return nil | ||
} | ||
|
||
// ToolkitName ... | ||
func (toolkit SwiftToolkit) ToolkitName() string { | ||
return "swift" | ||
} | ||
|
||
// Check ... | ||
func (toolkit SwiftToolkit) Check() (bool, ToolkitCheckResult, error) { | ||
return false, ToolkitCheckResult{}, nil | ||
} | ||
|
||
// IsToolAvailableInPATH ... | ||
func (toolkit SwiftToolkit) IsToolAvailableInPATH() bool { | ||
binPath, err := utils.CheckProgramInstalledPath("swift") | ||
if err != nil { | ||
return false | ||
} | ||
return len(binPath) > 0 | ||
} | ||
|
||
// PrepareForStepRun ... | ||
func (toolkit SwiftToolkit) PrepareForStepRun(step stepmanModels.StepModel, sIDData models.StepIDData, stepAbsDirPath string) error { | ||
binaryLocation := step.Toolkit.Swift.BinaryLocation | ||
if binaryLocation == "" { | ||
return nil | ||
} | ||
|
||
resp, err := http.Get(binaryLocation) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
executablePath := filepath.Join(stepAbsDirPath, step.Toolkit.Swift.ExecutableName) | ||
out, err := os.Create(executablePath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = io.Copy(out, resp.Body) | ||
err = os.Chmod(executablePath, 0777) | ||
|
||
err = resp.Body.Close() | ||
err = out.Close() | ||
return err | ||
} | ||
|
||
// StepRunCommandArguments ... | ||
func (toolkit SwiftToolkit) StepRunCommandArguments(step stepmanModels.StepModel, sIDData models.StepIDData, stepAbsDirPath string) ([]string, error) { | ||
binaryLocation := step.Toolkit.Swift.BinaryLocation | ||
if binaryLocation == "" { | ||
return []string{"swift", "run", "--package-path", stepAbsDirPath, "-c", "release"}, nil | ||
} | ||
executablePath := filepath.Join(stepAbsDirPath, step.Toolkit.Swift.ExecutableName) | ||
return []string{executablePath}, 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.