2019-05-15 22:09:52 +02:00
|
|
|
// Package cache helper for cache version
|
|
|
|
|
package cache
|
2019-05-13 22:36:24 +02:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"io/ioutil"
|
2019-06-15 23:03:27 +02:00
|
|
|
"path"
|
2019-05-13 22:36:24 +02:00
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
|
)
|
|
|
|
|
|
2019-06-15 23:16:30 +02:00
|
|
|
// ReleaseVersion struct
|
2019-06-15 23:03:27 +02:00
|
|
|
type ReleaseVersion struct {
|
|
|
|
|
Last ReleaseVersionEntry `yaml:"last"`
|
|
|
|
|
Next ReleaseVersionEntry `yaml:"next"`
|
|
|
|
|
Branch string `yaml:"branch"`
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-15 23:16:30 +02:00
|
|
|
//ReleaseVersionEntry struct
|
2019-06-15 23:03:27 +02:00
|
|
|
type ReleaseVersionEntry struct {
|
|
|
|
|
Commit string `yaml:"commit"`
|
|
|
|
|
Version string `yaml:"version"`
|
2019-05-13 22:36:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Write version into .version
|
2019-06-15 23:03:27 +02:00
|
|
|
func Write(repository string, versionFileContent ReleaseVersion) error {
|
|
|
|
|
completePath := path.Join(path.Dir(repository), ".version")
|
|
|
|
|
|
2019-05-13 22:36:24 +02:00
|
|
|
data, err := yaml.Marshal(&versionFileContent)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-15 23:03:27 +02:00
|
|
|
return ioutil.WriteFile(completePath, data, 0644)
|
2019-05-13 22:36:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read version into .version
|
2019-06-15 23:03:27 +02:00
|
|
|
func Read(repository string) (*ReleaseVersion, error) {
|
|
|
|
|
completePath := path.Join(path.Dir(repository), ".version")
|
2019-05-13 22:36:24 +02:00
|
|
|
|
2019-06-15 23:03:27 +02:00
|
|
|
content, err := ioutil.ReadFile(completePath)
|
2019-05-13 22:36:24 +02:00
|
|
|
if err != nil {
|
2019-06-15 23:03:27 +02:00
|
|
|
return &ReleaseVersion{}, err
|
2019-05-13 22:36:24 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-15 23:03:27 +02:00
|
|
|
var versionFileContent ReleaseVersion
|
2019-05-13 22:36:24 +02:00
|
|
|
err = yaml.Unmarshal(content, &versionFileContent)
|
|
|
|
|
if err != nil {
|
2019-06-15 23:03:27 +02:00
|
|
|
return &ReleaseVersion{}, err
|
2019-05-13 22:36:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &versionFileContent, nil
|
|
|
|
|
}
|