Skip to content

Commit

Permalink
Merge pull request #202 from godrei/local_steplib
Browse files Browse the repository at this point in the history
local collection fix & tests
  • Loading branch information
godrei authored Jul 19, 2016
2 parents b2a4a26 + 086baf8 commit f49f77f
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 17 deletions.
151 changes: 151 additions & 0 deletions bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions cli/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
Expand Down
43 changes: 30 additions & 13 deletions cli/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"errors"
"fmt"
"strings"

log "github.com/Sirupsen/logrus"
"github.com/bitrise-io/go-utils/cmdex"
Expand All @@ -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)
Expand Down

0 comments on commit f49f77f

Please sign in to comment.