Skip to content

Commit

Permalink
Don't specify master if no git branch is provided (#796)
Browse files Browse the repository at this point in the history
* Don't specify master if no git branch is provided

* Revert "Don't specify master if no git branch is provided"

This reverts commit ba9dc47.

* Revert "Revert "Don't specify master if no git branch is provided""

This reverts commit 8a18343.

* Fix failing tests

* Handle no version

* Update dependencies

* Bump version to 1.50.0

* Add go mod tidy and vendor to dep update script, and run it

* Update stepman dependency to include new Swift models

* Update version number to 1.49.3

* Refactor creation of git clone command

* Retidy modules

* Remove dep-update workflow

* Resolve merge conflicts

* Fix vendoring

* Revert rename

Co-authored-by: Olivér Falvai <[email protected]>
Co-authored-by: lpusok <[email protected]>
  • Loading branch information
3 people authored Oct 7, 2022
1 parent 5554029 commit 69d337d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
9 changes: 8 additions & 1 deletion bitrise/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,16 @@ func removeStepDefaultsAndFillStepOutputs(stepListItem *models.StepListItemModel
return err
}

if err := repo.CloneTagOrBranch(stepIDData.IDorURI, stepIDData.Version).Run(); err != nil {
var cloneCmd *command.Model
if stepIDData.Version == "" {
cloneCmd = repo.Clone(stepIDData.IDorURI)
} else {
cloneCmd = repo.CloneTagOrBranch(stepIDData.IDorURI, stepIDData.Version)
}
if err := cloneCmd.Run(); err != nil {
return err
}

if err := command.CopyFile(filepath.Join(tempStepCloneDirPath, "step.yml"), tempStepYMLFilePath); err != nil {
return err
}
Expand Down
10 changes: 7 additions & 3 deletions cli/step_activator.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ func (a stepActivator) activateStep(
if err != nil {
return "", "", err
}
cloneCmd := repo.CloneTagOrBranch(stepIDData.IDorURI, stepIDData.Version)
out, err := cloneCmd.RunAndReturnTrimmedCombinedOutput()
if err != nil {
var cloneCmd *command.Model
if stepIDData.Version == "" {
cloneCmd = repo.Clone(stepIDData.IDorURI)
} else {
cloneCmd = repo.CloneTagOrBranch(stepIDData.IDorURI, stepIDData.Version)
}
if out, err := cloneCmd.RunAndReturnTrimmedCombinedOutput(); err != nil {
if strings.HasPrefix(stepIDData.IDorURI, "git@") {
log.Warnf(`Note: if the step's repository is an open source one,
you should probably use a "https://..." git clone URL,
Expand Down
3 changes: 0 additions & 3 deletions models/models_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -1130,9 +1130,6 @@ func CreateStepIDDataFromString(compositeVersionStr, defaultStepLibSource string
}

version := getStepVersion(compositeVersionStr)
if src == "git" && version == "" {
version = "master"
}

return StepIDData{
IDorURI: id,
Expand Down
4 changes: 2 additions & 2 deletions models/models_methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1637,13 +1637,13 @@ func TestCreateStepIDDataFromString(t *testing.T) {
{
name: "direct git uri, https, no branch",
composite: "git::https://github.com/bitrise-io/steps-timestamp.git", defaultSteplibSource: "default-steplib-src",
wantStepSrc: "git", wantStepID: "https://github.com/bitrise-io/steps-timestamp.git", wantVersion: "master",
wantStepSrc: "git", wantStepID: "https://github.com/bitrise-io/steps-timestamp.git", wantVersion: "",
wantErr: false,
},
{
name: "direct git uri, ssh, no branch",
composite: "git::[email protected]:bitrise-io/steps-timestamp.git", defaultSteplibSource: "default-steplib-src",
wantStepSrc: "git", wantStepID: "[email protected]:bitrise-io/steps-timestamp.git", wantVersion: "master",
wantStepSrc: "git", wantStepID: "[email protected]:bitrise-io/steps-timestamp.git", wantVersion: "",
wantErr: false,
},
}
Expand Down
6 changes: 4 additions & 2 deletions toolkits/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,10 @@ func stepBinaryFilename(sIDData models.StepIDData) string {
return ""
}

compositeStepID := fmt.Sprintf("%s-%s-%s",
sIDData.SteplibSource, sIDData.IDorURI, sIDData.Version)
compositeStepID := fmt.Sprintf("%s-%s", sIDData.SteplibSource, sIDData.IDorURI)
if sIDData.Version != "" {
compositeStepID += "-" + sIDData.Version
}

safeStepID := replaceRexp.ReplaceAllString(compositeStepID, "_")
//
Expand Down
7 changes: 6 additions & 1 deletion toolkits/golang_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ import (
func Test_stepBinaryFilename(t *testing.T) {
{
sIDData := models.StepIDData{SteplibSource: "path", IDorURI: "./", Version: ""}
require.Equal(t, "path-._-", stepBinaryFilename(sIDData))
require.Equal(t, "path-._", stepBinaryFilename(sIDData))
}

{
sIDData := models.StepIDData{SteplibSource: "git", IDorURI: "https://github.com/bitrise-steplib/steps-go-toolkit-hello-world.git", Version: "master"}
require.Equal(t, "git-https___github.com_bitrise-steplib_steps-go-toolkit-hello-world.git-master", stepBinaryFilename(sIDData))
}

{
sIDData := models.StepIDData{SteplibSource: "git", IDorURI: "https://github.com/bitrise-steplib/steps-go-toolkit-hello-world.git", Version: ""}
require.Equal(t, "git-https___github.com_bitrise-steplib_steps-go-toolkit-hello-world.git", stepBinaryFilename(sIDData))
}

{
sIDData := models.StepIDData{SteplibSource: "_", IDorURI: "https://github.com/bitrise-steplib/steps-go-toolkit-hello-world.git", Version: "master"}
require.Equal(t, "_-https___github.com_bitrise-steplib_steps-go-toolkit-hello-world.git-master", stepBinaryFilename(sIDData))
Expand Down

0 comments on commit 69d337d

Please sign in to comment.