diff --git a/bitrise.yml b/bitrise.yml index 2c0569d3..5b8f4e76 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -75,6 +75,7 @@ workflows: 1, Err Check 2, Go Lint 3, Go Test + 4, Integration tests steps: - script: title: Print infos for the test @@ -164,6 +165,156 @@ workflows: if [ $? -eq 0 ] ; then exit 1 fi + - script: + title: Cleanup test StepLib + inputs: + - content: | + #!/bin/bash + set -ex + + rm -rf "_tmp/steplib" + - git-clone: + title: Git clone test StepLib + run_if: true + inputs: + - repository_url: https://github.com/bitrise-io/bitrise-steplib.git + - commit: "" + - tag: "" + - branch: master + - pull_request_id: "" + - clone_into_dir: _tmp/steplib + - auth_ssh_private_key: "" + - clone_depth: "" + - script: + title: Setup test + inputs: + - content: | + #!/bin/bash + set -x + + # Cleanup remote StepLib + $CURRENT_STEPMAN delete -c https://github.com/bitrise-samples/sample-steplib.git + if [ $? -ne 0 ] ; then + exit 1 + fi + + # Setup remote StepLib + $CURRENT_STEPMAN setup -c https://github.com/bitrise-samples/sample-steplib.git + if [ $? -ne 0 ] ; then + exit 1 + fi + + # Cleanup remote StepLib + $CURRENT_STEPMAN delete -c https://github.com/bitrise-samples/sample-steplib.git + if [ $? -ne 0 ] ; then + exit 1 + fi + + echo + + # Cleanup local StepLib + $CURRENT_STEPMAN delete -c _tmp/steplib + if [ $? -ne 0 ] ; then + exit 1 + fi + + # Setup local StepLib - deprecated --local flag + $CURRENT_STEPMAN setup --local -c _tmp/steplib + if [ $? -ne 0 ] ; then + exit 1 + fi + + # Cleanup local StepLib + $CURRENT_STEPMAN delete -c file://_tmp/steplib + if [ $? -ne 0 ] ; then + exit 1 + fi + + echo + + # Setup local StepLib - deprecated --local flag && file:// prefix + $CURRENT_STEPMAN setup --local -c file://_tmp/steplib + if [ $? -ne 0 ] ; then + exit 1 + fi + + # Cleanup local StepLib + $CURRENT_STEPMAN delete -c file://_tmp/steplib + if [ $? -ne 0 ] ; then + exit 1 + fi + + echo + + # Setup local StepLib - with file:// prefix + $CURRENT_STEPMAN setup -c file://_tmp/steplib + if [ $? -ne 0 ] ; then + exit 1 + fi + + # Cleanup local StepLib + $CURRENT_STEPMAN delete -c file://_tmp/steplib + if [ $? -ne 0 ] ; then + exit 1 + fi + - script: + title: Update test + inputs: + - content: | + #!/bin/bash + set -x + + # Cleanup remote StepLib + $CURRENT_STEPMAN delete -c https://github.com/bitrise-samples/sample-steplib.git + if [ $? -ne 0 ] ; then + exit 1 + fi + + # Setup remote StepLib + $CURRENT_STEPMAN setup -c https://github.com/bitrise-samples/sample-steplib.git + if [ $? -ne 0 ] ; then + exit 1 + fi + + # Update remote StepLib + $CURRENT_STEPMAN update -c https://github.com/bitrise-samples/sample-steplib.git + if [ $? -ne 0 ] ; then + exit 1 + fi + + echo + + # Cleanup local StepLib + $CURRENT_STEPMAN delete -c file://_tmp/steplib + if [ $? -ne 0 ] ; then + exit 1 + fi + + # Setup local StepLib - with file:// prefix + $CURRENT_STEPMAN setup -c file://_tmp/steplib + if [ $? -ne 0 ] ; then + exit 1 + fi + + # Update local StepLib - fail - missing file:// prefix + $CURRENT_STEPMAN update -c _tmp/steplib + if [ $? -eq 0 ] ; then + exit 1 + fi + + echo + + # Update local StepLib - success + $CURRENT_STEPMAN update -c file://_tmp/steplib + if [ $? -ne 0 ] ; then + exit 1 + fi + + # Cleanup local StepLib + $CURRENT_STEPMAN delete -c file://_tmp/steplib + if [ $? -ne 0 ] ; then + exit 1 + fi # ---------------------------------------------------------------- # --- workflows for Releasing diff --git a/cli/setup.go b/cli/setup.go index 30ca87f9..9ad62a1a 100644 --- a/cli/setup.go +++ b/cli/setup.go @@ -72,8 +72,12 @@ func setupSteplib(steplibURI string, silent bool) error { } logger.Info("Collection dir created - OK") - if err := cmdex.CopyDir(steplibURI, pth, true); err != nil { - return fmt.Errorf("Failed to setup local step spec:", err) + stepLibPth := steplibURI + if strings.HasPrefix(steplibURI, "file://") { + stepLibPth = strings.TrimPrefix(steplibURI, "file://") + } + if err := cmdex.CopyDir(stepLibPth, pth, true); err != nil { + return fmt.Errorf("Failed to copy dir (%s) to (%s), error: %s", stepLibPth, pth, err) } } @@ -103,19 +107,22 @@ func setup(c *cli.Context) error { if c.IsSet(LocalCollectionKey) { log.Warn("'local' flag is deprecated") - log.Warn("use 'file://' suffix in steplib path instead") + log.Warn("use 'file://' prefix in steplib path instead") fmt.Println() } if c.Bool(LocalCollectionKey) { if !strings.HasPrefix(steplibURI, "file://") { + log.Warnf("Appending file path prefix (file://) to StepLib (%s)", steplibURI) steplibURI = "file://" + steplibURI + log.Warnf("From now you can refer to this StepLib with URI: %s", steplibURI) + log.Warnf("For example, to delete StepLib call: `stepman delete --collection %s`", steplibURI) } } // Setup if err := setupSteplib(steplibURI, false); err != nil { - log.Fatalf("Steup failed, error: %s", err) + log.Fatalf("Setup failed, error: %s", err) } // Copy spec.json diff --git a/cli/update.go b/cli/update.go index d82094bf..8d5b96f8 100644 --- a/cli/update.go +++ b/cli/update.go @@ -3,6 +3,7 @@ package cli import ( "errors" "fmt" + "strings" log "github.com/Sirupsen/logrus" "github.com/bitrise-io/go-utils/cmdex" @@ -15,23 +16,39 @@ import ( func updateCollection(steplibSource string) (models.StepCollectionModel, error) { route, found := stepman.ReadRoute(steplibSource) if !found { - return models.StepCollectionModel{}, - fmt.Errorf("No collection found for lib, call 'stepman delete -c %s' for cleanup", steplibSource) + log.Warnf("No route found for collection: %s, cleaning up routing..", steplibSource) + if err := stepman.CleanupDanglingLib(steplibSource); err != nil { + log.Errorf("Error cleaning up lib: %s", steplibSource) + } + log.Infof("Call 'stepman setup -c %s' for a clean setup", steplibSource) + return models.StepCollectionModel{}, fmt.Errorf("No route found for StepLib: %s", steplibSource) } - pth := stepman.GetCollectionBaseDirPath(route) - if exists, err := pathutil.IsPathExists(pth); err != nil { - return models.StepCollectionModel{}, err - } else if !exists { - return models.StepCollectionModel{}, errors.New("Not initialized") - } + isLocalSteplib := strings.HasPrefix(steplibSource, "file://") - if err := cmdex.GitPull(pth); err != nil { - return models.StepCollectionModel{}, err - } + if isLocalSteplib { + if err := stepman.CleanupRoute(route); err != nil { + return models.StepCollectionModel{}, fmt.Errorf("Failed to cleanup route for StepLib: %s", steplibSource) + } - if err := stepman.ReGenerateStepSpec(route); err != nil { - return models.StepCollectionModel{}, err + if err := setupSteplib(steplibSource, false); err != nil { + return models.StepCollectionModel{}, fmt.Errorf("Failed to setup StepLib: %s", steplibSource) + } + } else { + pth := stepman.GetCollectionBaseDirPath(route) + if exists, err := pathutil.IsPathExists(pth); err != nil { + return models.StepCollectionModel{}, err + } else if !exists { + return models.StepCollectionModel{}, errors.New("Not initialized") + } + + if err := cmdex.GitPull(pth); err != nil { + return models.StepCollectionModel{}, err + } + + if err := stepman.ReGenerateStepSpec(route); err != nil { + return models.StepCollectionModel{}, err + } } return stepman.ReadStepSpec(steplibSource)