(outputDir string, release *ReleaseSpec, outputDirTemplate string)
| 3053 | } |
| 3054 | |
| 3055 | func (st *HelmState) GenerateOutputDir(outputDir string, release *ReleaseSpec, outputDirTemplate string) (string, error) { |
| 3056 | // get absolute path of state file to generate a hash |
| 3057 | // use this hash to write helm output in a specific directory by state file and release name |
| 3058 | // ie. in a directory named stateFileName-stateFileHash-releaseName |
| 3059 | stateAbsPath, err := filepath.Abs(st.FilePath) |
| 3060 | if err != nil { |
| 3061 | return stateAbsPath, err |
| 3062 | } |
| 3063 | |
| 3064 | hasher := sha1.New() |
| 3065 | _, err = io.WriteString(hasher, stateAbsPath) |
| 3066 | if err != nil { |
| 3067 | return "", err |
| 3068 | } |
| 3069 | |
| 3070 | var stateFileExtension = filepath.Ext(st.FilePath) |
| 3071 | var stateFileName = st.FilePath[0 : len(st.FilePath)-len(stateFileExtension)] |
| 3072 | |
| 3073 | sha1sum := hex.EncodeToString(hasher.Sum(nil))[:8] |
| 3074 | |
| 3075 | var sb strings.Builder |
| 3076 | sb.WriteString(stateFileName) |
| 3077 | sb.WriteString("-") |
| 3078 | sb.WriteString(sha1sum) |
| 3079 | sb.WriteString("-") |
| 3080 | sb.WriteString(release.Name) |
| 3081 | |
| 3082 | if outputDirTemplate == "" { |
| 3083 | outputDirTemplate = filepath.Join("{{ .OutputDir }}", "{{ .State.BaseName }}-{{ .State.AbsPathSHA1 }}-{{ .Release.Name}}") |
| 3084 | } |
| 3085 | |
| 3086 | t, err := template.New("output-dir").Parse(outputDirTemplate) |
| 3087 | if err != nil { |
| 3088 | return "", fmt.Errorf("parsing output-dir templmate") |
| 3089 | } |
| 3090 | |
| 3091 | buf := &bytes.Buffer{} |
| 3092 | |
| 3093 | type state struct { |
| 3094 | BaseName string |
| 3095 | Path string |
| 3096 | AbsPath string |
| 3097 | AbsPathSHA1 string |
| 3098 | } |
| 3099 | |
| 3100 | data := struct { |
| 3101 | OutputDir string |
| 3102 | State state |
| 3103 | Release *ReleaseSpec |
| 3104 | }{ |
| 3105 | OutputDir: outputDir, |
| 3106 | State: state{ |
| 3107 | BaseName: stateFileName, |
| 3108 | Path: st.FilePath, |
| 3109 | AbsPath: stateAbsPath, |
| 3110 | AbsPathSHA1: sha1sum, |
| 3111 | }, |
| 3112 | Release: release, |
no test coverage detected