本文整理汇总了Golang中github.com/bitrise-io/go-utils/pathutil.NormalizedOSTempDirPath函数的典型用法代码示例。如果您正苦于以下问题:Golang NormalizedOSTempDirPath函数的具体用法?Golang NormalizedOSTempDirPath怎么用?Golang NormalizedOSTempDirPath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NormalizedOSTempDirPath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetStepFromNewSteplib
// GetStepFromNewSteplib ...
func GetStepFromNewSteplib(stepID, stepLibGitURI string) (stepmanModels.StepModel, string, error) {
// Activate step - get step.yml
tempStepCloneDirPath, err := pathutil.NormalizedOSTempDirPath("step_clone")
if err != nil {
return stepmanModels.StepModel{}, "", err
}
tempStepYMLDirPath, err := pathutil.NormalizedOSTempDirPath("step_yml")
if err != nil {
return stepmanModels.StepModel{}, "", err
}
tempStepYMLFilePath := path.Join(tempStepYMLDirPath, "step.yml")
// Stepman
if err := bitrise.StepmanSetup(stepLibGitURI); err != nil {
return stepmanModels.StepModel{}, "", err
}
stepInfo, err := bitrise.StepmanStepInfo(stepLibGitURI, stepID, "")
if err != nil {
// May StepLib should be updated
log.Info("Step info not found in StepLib (%s) -- Updating ...")
if err := bitrise.StepmanUpdate(stepLibGitURI); err != nil {
return stepmanModels.StepModel{}, "", err
}
stepInfo, err = bitrise.StepmanStepInfo(stepLibGitURI, stepID, "")
if err != nil {
return stepmanModels.StepModel{}, "", err
}
}
stepVersion := stepInfo.StepVersion
if err := bitrise.StepmanActivate(stepLibGitURI, stepID, "", tempStepCloneDirPath, tempStepYMLFilePath); err != nil {
return stepmanModels.StepModel{}, "", err
}
specStep, err := ReadSpecStep(tempStepYMLFilePath)
if err != nil {
return stepmanModels.StepModel{}, "", err
}
// Cleanup
if err := cmdex.RemoveDir(tempStepCloneDirPath); err != nil {
return stepmanModels.StepModel{}, "", errors.New(fmt.Sprint("Failed to remove step clone dir: ", err))
}
if err := cmdex.RemoveDir(tempStepYMLDirPath); err != nil {
return stepmanModels.StepModel{}, "", errors.New(fmt.Sprint("Failed to remove step clone dir: ", err))
}
return specStep, stepVersion, nil
}
示例2: TestClonePluginSrc
func TestClonePluginSrc(t *testing.T) {
t.Log("example plugin - latest version")
{
pluginSource := examplePluginGitURL
versionTag := ""
destinationDir, err := pathutil.NormalizedOSTempDirPath("TestClonePluginSrc")
require.NoError(t, err)
exist, err := pathutil.IsPathExists(destinationDir)
require.NoError(t, err)
if exist {
err := os.RemoveAll(destinationDir)
require.NoError(t, err)
}
version, hash, err := clonePluginSrc(pluginSource, versionTag, destinationDir)
require.NoError(t, err)
require.NotNil(t, version)
require.NotEmpty(t, hash)
exist, err = pathutil.IsPathExists(destinationDir)
require.NoError(t, err)
require.Equal(t, true, exist)
}
t.Log("example plugin - 0.9.0 version")
{
pluginSource := examplePluginGitURL
versionTag := "0.9.0"
destinationDir, err := pathutil.NormalizedOSTempDirPath("TestClonePluginSrc")
require.NoError(t, err)
exist, err := pathutil.IsPathExists(destinationDir)
require.NoError(t, err)
if exist {
err := os.RemoveAll(destinationDir)
require.NoError(t, err)
}
version, hash, err := clonePluginSrc(pluginSource, versionTag, destinationDir)
require.NoError(t, err)
require.NotNil(t, version)
require.Equal(t, "0.9.0", version.String())
require.NotEmpty(t, hash)
exist, err = pathutil.IsPathExists(destinationDir)
require.NoError(t, err)
require.Equal(t, true, exist)
}
}
示例3: TestDownloadPluginBin
func TestDownloadPluginBin(t *testing.T) {
t.Log("example plugin bin - ")
{
pluginBinURL := analyticsPluginBinURL
destinationDir, err := pathutil.NormalizedOSTempDirPath("TestDownloadPluginBin")
require.NoError(t, err)
exist, err := pathutil.IsPathExists(destinationDir)
require.NoError(t, err)
if exist {
err := os.RemoveAll(destinationDir)
require.NoError(t, err)
}
require.NoError(t, os.MkdirAll(destinationDir, 0777))
destinationPth := filepath.Join(destinationDir, "example")
require.NoError(t, downloadPluginBin(pluginBinURL, destinationPth))
exist, err = pathutil.IsPathExists(destinationPth)
require.NoError(t, err)
require.Equal(t, true, exist)
}
}
示例4: saveRawOutputToLogFile
func saveRawOutputToLogFile(rawXcodebuildOutput string, isRunSuccess bool) error {
tmpDir, err := pathutil.NormalizedOSTempDirPath("xcodebuild-output")
if err != nil {
return fmt.Errorf("Failed to create temp dir, error: %s", err)
}
logFileName := "raw-xcodebuild-output.log"
logPth := filepath.Join(tmpDir, logFileName)
if err := fileutil.WriteStringToFile(logPth, rawXcodebuildOutput); err != nil {
return fmt.Errorf("Failed to write xcodebuild output to file, error: %s", err)
}
if !isRunSuccess {
deployDir := os.Getenv("BITRISE_DEPLOY_DIR")
if deployDir == "" {
return errors.New("No BITRISE_DEPLOY_DIR found")
}
deployPth := filepath.Join(deployDir, logFileName)
if err := cmdex.CopyFile(logPth, deployPth); err != nil {
return fmt.Errorf("Failed to copy xcodebuild output log file from (%s) to (%s), error: %s", logPth, deployPth, err)
}
logPth = deployPth
}
if err := cmd.ExportEnvironmentWithEnvman("BITRISE_XCODE_RAW_TEST_RESULT_TEXT_PATH", logPth); err != nil {
log.Warn("Failed to export: BITRISE_XCODE_RAW_TEST_RESULT_TEXT_PATH, error: %s", err)
}
return nil
}
示例5: auditStepModelBeforeSharePullRequest
func auditStepModelBeforeSharePullRequest(step models.StepModel, stepID, version string) error {
if err := step.Audit(); err != nil {
return fmt.Errorf("Failed to audit step infos, error: %s", err)
}
pth, err := pathutil.NormalizedOSTempDirPath(stepID + version)
if err != nil {
return fmt.Errorf("Failed to create a temporary directory for the step's audit, error: %s", err)
}
if step.Source == nil {
return fmt.Errorf("Missing Source porperty")
}
err = retry.Times(2).Wait(3 * time.Second).Try(func(attempt uint) error {
return cmdex.GitCloneTag(step.Source.Git, pth, version)
})
if err != nil {
return fmt.Errorf("Failed to git-clone the step (url: %s) version (%s), error: %s",
step.Source.Git, version, err)
}
latestCommit, err := cmdex.GitGetLatestCommitHashOnHead(pth)
if err != nil {
return fmt.Errorf("Failed to get git-latest-commit-hash, error: %s", err)
}
if latestCommit != step.Source.Commit {
return fmt.Errorf("Step commit hash (%s) should be the latest commit hash (%s) on git tag", step.Source.Commit, latestCommit)
}
return nil
}
示例6: initBitriseWorkPaths
func initBitriseWorkPaths() error {
bitriseWorkDirPath, err := pathutil.NormalizedOSTempDirPath("bitrise")
if err != nil {
return err
}
if exist, err := pathutil.IsPathExists(bitriseWorkDirPath); err != nil {
return err
} else if !exist {
if err := os.MkdirAll(bitriseWorkDirPath, 0777); err != nil {
return err
}
}
BitriseWorkDirPath = bitriseWorkDirPath
bitriseWorkStepsDirPath, err := filepath.Abs(filepath.Join(BitriseWorkDirPath, "step_src"))
if err != nil {
return err
}
if exist, err := pathutil.IsPathExists(bitriseWorkStepsDirPath); err != nil {
return err
} else if !exist {
if err := os.MkdirAll(bitriseWorkStepsDirPath, 0777); err != nil {
return err
}
}
BitriseWorkStepsDirPath = bitriseWorkStepsDirPath
return nil
}
示例7: goBuildInIsolation
func goBuildInIsolation(packageName, srcPath, outputBinPath string) error {
log.Debugf("=> Installing package (%s) to path (%s) ...", packageName, srcPath)
workspaceRootPath, err := pathutil.NormalizedOSTempDirPath("bitrise-go-toolkit")
if err != nil {
return fmt.Errorf("Failed to create root directory of isolated workspace, error: %s", err)
}
log.Debugln("=> Using sandboxed workspace:", workspaceRootPath)
// origGOPATH := os.Getenv("GOPATH")
// if origGOPATH == "" {
// return fmt.Errorf("You don't have a GOPATH environment - please set it; GOPATH/bin will be symlinked")
// }
// log.Debugln("=> Symlink GOPATH/bin into sandbox ...")
// if err := gows.CreateGopathBinSymlink(origGOPATH, workspaceRootPath); err != nil {
// return fmt.Errorf("Failed to create GOPATH/bin symlink, error: %s", err)
// }
// log.Debugln(" [DONE]")
fullPackageWorkspacePath := filepath.Join(workspaceRootPath, "src", packageName)
log.Debugf("=> Creating Symlink: (%s) -> (%s)", srcPath, fullPackageWorkspacePath)
if err := gows.CreateOrUpdateSymlink(srcPath, fullPackageWorkspacePath); err != nil {
return fmt.Errorf("Failed to create Project->Workspace symlink, error: %s", err)
}
log.Debugf(" [DONE] Symlink is in place")
log.Debugln("=> Building package " + packageName + " ...")
{
isInstallRequired, _, goConfig, err := selectGoConfiguration()
if err != nil {
return fmt.Errorf("Failed to select an appropriate Go installation for compiling the step, error: %s", err)
}
if isInstallRequired {
return fmt.Errorf("Failed to select an appropriate Go installation for compiling the step, error: %s",
"Found Go version is older than required. Please run 'bitrise setup' to check and install the required version")
}
cmd := gows.CreateCommand(workspaceRootPath, workspaceRootPath,
goConfig.GoBinaryPath, "build", "-o", outputBinPath, packageName)
cmd.Env = append(cmd.Env, "GOROOT="+goConfig.GOROOT)
if err := cmd.Run(); err != nil {
return fmt.Errorf("Failed to install package, error: %s", err)
}
}
log.Debugln(" [DONE] Package successfully installed")
log.Debugln("=> Delete isolated workspace ...")
{
if err := os.RemoveAll(workspaceRootPath); err != nil {
return fmt.Errorf("Failed to delete temporary isolated workspace, error: %s", err)
}
}
log.Debugln(" [DONE]")
return nil
}
示例8: WritePlistToTmpFile
// WritePlistToTmpFile ...
func WritePlistToTmpFile(options map[string]interface{}) (string, error) {
tmpDir, err := pathutil.NormalizedOSTempDirPath("output")
if err != nil {
return "", fmt.Errorf("failed to create temp dir, error: %s", err)
}
pth := filepath.Join(tmpDir, "exportOptions.plist")
if err := WritePlistToFile(options, pth); err != nil {
return "", fmt.Errorf("failed to write to file options, error: %s", err)
}
return pth, nil
}
示例9: TestEnvmanJSONPrint
func TestEnvmanJSONPrint(t *testing.T) {
// Initialized envstore -- Err should empty, output filled
testDirPth, err := pathutil.NormalizedOSTempDirPath("test_env_store")
require.Equal(t, nil, err)
envstorePth := path.Join(testDirPth, "envstore.yml")
require.Equal(t, nil, EnvmanInitAtPath(envstorePth))
outStr, err := EnvmanJSONPrint(envstorePth)
require.Equal(t, nil, err)
require.NotEqual(t, "", outStr)
// Not initialized envstore -- Err should filled, output empty
testDirPth, err = pathutil.NormalizedOSTempDirPath("test_env_store")
require.Equal(t, nil, err)
envstorePth = path.Join("test_env_store", "envstore.yml")
outStr, err = EnvmanJSONPrint(envstorePth)
require.NotEqual(t, nil, err)
require.Equal(t, "", outStr)
}
示例10: InitPaths
// InitPaths ...
func InitPaths() error {
if err := initBitriseWorkPaths(); err != nil {
return fmt.Errorf("Failed to init bitrise paths: %s", err)
}
inputEnvstorePath, err := filepath.Abs(path.Join(BitriseWorkDirPath, "input_envstore.yml"))
if err != nil {
return fmt.Errorf("Failed to set envstore path: %s", err)
}
InputEnvstorePath = inputEnvstorePath
outputEnvstorePath, err := filepath.Abs(path.Join(BitriseWorkDirPath, "output_envstore.yml"))
if err != nil {
return fmt.Errorf("Failed to set envstore path: %s", err)
}
OutputEnvstorePath = outputEnvstorePath
formoutPath, err := filepath.Abs(path.Join(BitriseWorkDirPath, "formatted_output.md"))
if err != nil {
return fmt.Errorf("Failed to set formatted output path: %s", err)
}
FormattedOutputPath = formoutPath
currentDir, err := filepath.Abs("./")
if err != nil {
return fmt.Errorf("Failed to set current dir: %s", err)
}
CurrentDir = currentDir
// BITRISE_SOURCE_DIR
if os.Getenv(BitriseSourceDirEnvKey) == "" {
if err := os.Setenv(BitriseSourceDirEnvKey, currentDir); err != nil {
return fmt.Errorf("Failed to set BITRISE_SOURCE_DIR: %s", err)
}
}
// BITRISE_DEPLOY_DIR
if os.Getenv(BitriseDeployDirEnvKey) == "" {
deployDir, err := pathutil.NormalizedOSTempDirPath("deploy")
if err != nil {
return fmt.Errorf("Failed to set deploy dir: %s", err)
}
if err := os.Setenv(BitriseDeployDirEnvKey, deployDir); err != nil {
return fmt.Errorf("Failed to set BITRISE_DEPLOY_DIR: %s", err)
}
}
return nil
}
示例11: ExportOutputDirAsZip
// ExportOutputDirAsZip ...
func ExportOutputDirAsZip(sourceDirPth, destinationPth, envKey string) error {
tmpDir, err := pathutil.NormalizedOSTempDirPath("__export_tmp_dir__")
if err != nil {
return err
}
base := filepath.Base(sourceDirPth)
tmpZipFilePth := filepath.Join(tmpDir, base+".zip")
if err := zip(sourceDirPth, tmpZipFilePth); err != nil {
return err
}
return ExportOutputFile(tmpZipFilePth, destinationPth, envKey)
}
示例12: TestNewHelper
func TestNewHelper(t *testing.T) {
t.Log("it fails if destinationDir empty")
{
helper, err := NewHelper("", "https://github.com/bitrise-samples/git-clone-test.git", false)
require.Error(t, err)
require.Equal(t, "", helper.destinationDir)
require.Equal(t, "", helper.remoteURI)
}
t.Log("it fails if remote URI empty")
{
helper, err := NewHelper("./", "", false)
require.Error(t, err)
require.Equal(t, "", helper.destinationDir)
require.Equal(t, "", helper.remoteURI)
}
t.Log("it fails if remote URI empty")
{
helper, err := NewHelper("./", "", false)
require.Error(t, err)
require.Equal(t, "", helper.destinationDir)
require.Equal(t, "", helper.remoteURI)
}
t.Log("it creates destination dir if not exist")
{
tmpDir, err := pathutil.NormalizedOSTempDirPath("__test__")
require.NoError(t, err)
destinationDir := filepath.Join(tmpDir, "dst")
exist, err := pathutil.IsDirExists(destinationDir)
require.NoError(t, err)
require.Equal(t, false, exist)
helper, err := NewHelper(destinationDir, "https://github.com/bitrise-samples/git-clone-test.git", false)
require.NoError(t, err)
require.Equal(t, destinationDir, helper.destinationDir)
require.Equal(t, "https://github.com/bitrise-samples/git-clone-test.git", helper.remoteURI)
exist, err = pathutil.IsDirExists(destinationDir)
require.NoError(t, err)
require.Equal(t, true, exist)
require.NoError(t, os.RemoveAll(tmpDir))
}
}
示例13: Test_ValidateTestJSON
func Test_ValidateTestJSON(t *testing.T) {
tmpDir, err := pathutil.NormalizedOSTempDirPath("__validate_test__")
require.NoError(t, err)
defer func() {
require.NoError(t, os.RemoveAll(tmpDir))
}()
t.Log("valid bitrise.yml")
{
cmd := cmdex.NewCommand(binPath(), "validate", "-c", "trigger_params_test_bitrise.yml", "--format", "json")
out, err := cmd.RunAndReturnTrimmedCombinedOutput()
require.NoError(t, err)
require.Equal(t, "{\"data\":{\"config\":{\"is_valid\":true}}}", out)
}
t.Log("valid - warning test - `-p` flag is deprecated")
{
cmd := cmdex.NewCommand(binPath(), "validate", "-p", "trigger_params_test_bitrise.yml", "--format", "json")
out, err := cmd.RunAndReturnTrimmedCombinedOutput()
require.NoError(t, err)
require.Equal(t, "{\"data\":{\"config\":{\"is_valid\":true}},\"warnings\":[\"'path' key is deprecated, use 'config' instead!\"]}", out)
}
t.Log("valid - invalid workflow id")
{
configPth := filepath.Join(tmpDir, "bitrise.yml")
require.NoError(t, fileutil.WriteStringToFile(configPth, invalidWorkflowIDBitriseYML))
cmd := cmdex.NewCommand(binPath(), "validate", "-c", configPth, "--format", "json")
out, err := cmd.RunAndReturnTrimmedCombinedOutput()
require.NoError(t, err)
expected := "{\"data\":{\"config\":{\"is_valid\":true,\"warnings\":[\"invalid workflow ID (invalid:id): doesn't conform to: [A-Za-z0-9-_.]\"]}}}"
require.Equal(t, expected, out)
}
t.Log("invalid - empty bitrise.yml")
{
configPth := filepath.Join(tmpDir, "bitrise.yml")
require.NoError(t, fileutil.WriteStringToFile(configPth, emptyBitriseYML))
cmd := cmdex.NewCommand(binPath(), "validate", "-c", configPth, "--format", "json")
out, err := cmd.RunAndReturnTrimmedCombinedOutput()
require.Error(t, err, out)
expected := fmt.Sprintf("{\"data\":{\"config\":{\"is_valid\":false,\"error\":\"Config (path:%s) is not valid: empty config\"}}}", configPth)
require.Equal(t, expected, out)
}
}
示例14: Test_ValidateTest
func Test_ValidateTest(t *testing.T) {
tmpDir, err := pathutil.NormalizedOSTempDirPath("__validate_test__")
require.NoError(t, err)
defer func() {
require.NoError(t, os.RemoveAll(tmpDir))
}()
t.Log("valid bitrise.yml")
{
cmd := cmdex.NewCommand(binPath(), "validate", "-c", "trigger_params_test_bitrise.yml")
out, err := cmd.RunAndReturnTrimmedCombinedOutput()
require.NoError(t, err)
require.Equal(t, "Config is valid: \x1b[32;1mtrue\x1b[0m", out)
}
t.Log("valid - warning test - `-p` flag is deprecated")
{
cmd := cmdex.NewCommand(binPath(), "validate", "-p", "trigger_params_test_bitrise.yml")
out, err := cmd.RunAndReturnTrimmedCombinedOutput()
require.NoError(t, err)
require.Equal(t, "Config is valid: \x1b[32;1mtrue\x1b[0m\nWarning(s):\n- 'path' key is deprecated, use 'config' instead!", out)
}
t.Log("valid - invalid workflow id")
{
configPth := filepath.Join(tmpDir, "bitrise.yml")
require.NoError(t, fileutil.WriteStringToFile(configPth, invalidWorkflowIDBitriseYML))
cmd := cmdex.NewCommand(binPath(), "validate", "-c", configPth)
out, err := cmd.RunAndReturnTrimmedCombinedOutput()
require.NoError(t, err)
expected := "Config is valid: \x1b[32;1mtrue\x1b[0m\nWarning(s):\n- invalid workflow ID (invalid:id): doesn't conform to: [A-Za-z0-9-_.]"
require.Equal(t, expected, out)
}
t.Log("invalid - empty bitrise.yml")
{
configPth := filepath.Join(tmpDir, "bitrise.yml")
require.NoError(t, fileutil.WriteStringToFile(configPth, emptyBitriseYML))
cmd := cmdex.NewCommand(binPath(), "validate", "-c", configPth)
out, err := cmd.RunAndReturnTrimmedCombinedOutput()
require.Error(t, err, out)
expected := fmt.Sprintf("Config is valid: \x1b[31;1mfalse\x1b[0m\nError: \x1b[31;1mConfig (path:%s) is not valid: empty config\x1b[0m", configPth)
require.Equal(t, expected, out)
}
}
示例15: TestSetupForVersionChecks
func TestSetupForVersionChecks(t *testing.T) {
fakeHomePth, err := pathutil.NormalizedOSTempDirPath("_FAKE_HOME")
require.Equal(t, nil, err)
originalHome := os.Getenv("HOME")
defer func() {
require.Equal(t, nil, os.Setenv("HOME", originalHome))
require.Equal(t, nil, os.RemoveAll(fakeHomePth))
}()
require.Equal(t, nil, os.Setenv("HOME", fakeHomePth))
require.Equal(t, false, CheckIsSetupWasDoneForVersion("0.9.7"))
require.Equal(t, nil, SaveSetupSuccessForVersion("0.9.7"))
require.Equal(t, true, CheckIsSetupWasDoneForVersion("0.9.7"))
require.Equal(t, false, CheckIsSetupWasDoneForVersion("0.9.8"))
}