Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of Concept: First class support for steps written in Swift. #795

Merged
merged 8 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ workflows:
- integration-test
title: Runs tests
steps:
- go-list:
- golint:
- errcheck:
- go-list: {}
- golint: {}
- errcheck: {}
- script:
title: Go test
inputs:
Expand Down
80 changes: 80 additions & 0 deletions toolkits/swift.go
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
}
13 changes: 6 additions & 7 deletions toolkits/toolkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,19 @@ type Toolkit interface {

// ToolkitForStep ...
func ToolkitForStep(step stepmanModels.StepModel) Toolkit {
var toolkit Toolkit = BashToolkit{}
if step.Toolkit != nil {
stepToolkit := step.Toolkit
if stepToolkit.Go != nil {
return GoToolkit{}
} else if stepToolkit.Bash != nil {
return BashToolkit{}
toolkit = GoToolkit{}
} else if stepToolkit.Swift != nil {
toolkit = SwiftToolkit{}
}
}

// default
return BashToolkit{}
return toolkit
}

// AllSupportedToolkits ...
func AllSupportedToolkits() []Toolkit {
return []Toolkit{GoToolkit{}, BashToolkit{}}
return []Toolkit{GoToolkit{}, BashToolkit{}, SwiftToolkit{}}
}
6 changes: 6 additions & 0 deletions vendor/github.com/bitrise-io/stepman/models/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.