[in] create /version file based on git tag name
This commit is contained in:
@@ -28,7 +28,10 @@ Fetches artifacts from the given release version. If the version is not
|
||||
specified, the latest version is chosen using [semver](http://semver.org)
|
||||
semantics.
|
||||
|
||||
Creates a file `tag` containing the tag name/version of the release being fetched.
|
||||
Also creates the following files:
|
||||
|
||||
* `tag` containing the git tag name of the release being fetched.
|
||||
* `version` containing the version determined by the git tag of the release being fetched.
|
||||
|
||||
#### Parameters
|
||||
|
||||
|
@@ -65,6 +65,13 @@ func (c *InCommand) Run(destDir string, request InRequest) (InResponse, error) {
|
||||
return InResponse{}, err
|
||||
}
|
||||
|
||||
version := determineVersionFromTag(*foundRelease.TagName)
|
||||
versionPath := filepath.Join(destDir, "version")
|
||||
err = ioutil.WriteFile(versionPath, []byte(version), 0644)
|
||||
if err != nil {
|
||||
return InResponse{}, err
|
||||
}
|
||||
|
||||
assets, err := c.github.ListReleaseAssets(foundRelease)
|
||||
if err != nil {
|
||||
return InResponse{}, err
|
||||
|
@@ -236,7 +236,7 @@ var _ = Describe("In Command", func() {
|
||||
))
|
||||
})
|
||||
|
||||
It("stores tag in a file", func() {
|
||||
It("stores git tag in a file", func() {
|
||||
_, err := os.Stat(filepath.Join(destDir, "tag"))
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
|
||||
@@ -246,6 +246,16 @@ var _ = Describe("In Command", func() {
|
||||
Ω(string(tag)).Should(Equal("v0.35.0"))
|
||||
})
|
||||
|
||||
It("stores version in a file", func() {
|
||||
_, err := os.Stat(filepath.Join(destDir, "version"))
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
|
||||
version, err := ioutil.ReadFile(filepath.Join(destDir, "version"))
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
|
||||
Ω(string(version)).Should(Equal("0.35.0"))
|
||||
})
|
||||
|
||||
It("fetches from the latest release", func() {
|
||||
_, err := os.Stat(filepath.Join(destDir, "example.txt"))
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
|
10
versions.go
Normal file
10
versions.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package resource
|
||||
|
||||
import "regexp"
|
||||
|
||||
// determineVersionFromTag converts git tags v1.2.3 into semver 1.2.3 values
|
||||
func determineVersionFromTag(tag string) string {
|
||||
re := regexp.MustCompile("v?([^v].*)")
|
||||
matches := re.FindStringSubmatch(tag)
|
||||
return matches[1]
|
||||
}
|
Reference in New Issue
Block a user