forked from bitrise-steplib/steps-xcode-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresult_addon.go
More file actions
64 lines (55 loc) · 1.81 KB
/
Copy pathresult_addon.go
File metadata and controls
64 lines (55 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/bitrise-io/go-utils/command"
"github.com/bitrise-io/go-utils/log"
)
type addonCopy struct {
sourceTestOutputDir string
targetAddonPath string
targetAddonBundleName string
}
func copyAndSaveMetadata(info addonCopy) error {
info.targetAddonBundleName = replaceUnsupportedFilenameCharacters(info.targetAddonBundleName)
addonPerStepOutputDir := filepath.Join(info.targetAddonPath, info.targetAddonBundleName)
if err := copyDirectory(info.sourceTestOutputDir, addonPerStepOutputDir); err != nil {
return err
}
if err := saveBundleMetadata(addonPerStepOutputDir, info.targetAddonBundleName); err != nil {
return err
}
return nil
}
func copyDirectory(sourceBundle string, targetDir string) error {
if err := os.MkdirAll(targetDir, 0700); err != nil {
return fmt.Errorf("failed to create directory (%s), error: %s", targetDir, err)
}
// the leading `/` means to copy not the content but the whole dir
// -a means a better recursive, with symlinks handling and everything
cmd := command.New("cp", "-a", sourceBundle, targetDir+"/")
log.Donef("$ %s", cmd.PrintableCommandArgs())
if out, err := cmd.RunAndReturnTrimmedCombinedOutput(); err != nil {
return fmt.Errorf("copy failed, error: %s, output: %s", err, out)
}
return nil
}
func saveBundleMetadata(outputDir string, bundleName string) error {
// Save test bundle metadata
type testBundle struct {
BundleName string `json:"test-name"`
}
bytes, err := json.Marshal(testBundle{
BundleName: bundleName,
})
if err != nil {
return fmt.Errorf("could not encode metadata, error: %s", err)
}
if err = ioutil.WriteFile(filepath.Join(outputDir, "test-info.json"), bytes, 0600); err != nil {
return fmt.Errorf("failed to write file, error: %s", err)
}
return nil
}