Merge pull request #4 from drnic/in-tag-file
[in] creates file 'tag' and 'version' containing git tag/version for the release being fetched
This commit is contained in:
@@ -28,6 +28,11 @@ Fetches artifacts from the given release version. If the version is not
|
|||||||
specified, the latest version is chosen using [semver](http://semver.org)
|
specified, the latest version is chosen using [semver](http://semver.org)
|
||||||
semantics.
|
semantics.
|
||||||
|
|
||||||
|
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
|
#### Parameters
|
||||||
|
|
||||||
* `globs`: *Optional.* A list of globs for files that will be downloaded from
|
* `globs`: *Optional.* A list of globs for files that will be downloaded from
|
||||||
|
@@ -72,12 +72,12 @@ func (r byVersion) Less(i, j int) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
first, err := semver.New(dropLeadingAlpha(*r[i].TagName))
|
first, err := semver.New(determineVersionFromTag(*r[i].TagName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
second, err := semver.New(dropLeadingAlpha(*r[j].TagName))
|
second, err := semver.New(determineVersionFromTag(*r[j].TagName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -58,6 +59,19 @@ func (c *InCommand) Run(destDir string, request InRequest) (InResponse, error) {
|
|||||||
return InResponse{}, fmt.Errorf("could not find release with tag: %s", request.Version.Tag)
|
return InResponse{}, fmt.Errorf("could not find release with tag: %s", request.Version.Tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tagPath := filepath.Join(destDir, "tag")
|
||||||
|
err = ioutil.WriteFile(tagPath, []byte(*foundRelease.TagName), 0644)
|
||||||
|
if err != nil {
|
||||||
|
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)
|
assets, err := c.github.ListReleaseAssets(foundRelease)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return InResponse{}, err
|
return InResponse{}, err
|
||||||
|
@@ -236,6 +236,26 @@ var _ = Describe("In Command", func() {
|
|||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("stores git tag in a file", func() {
|
||||||
|
_, err := os.Stat(filepath.Join(destDir, "tag"))
|
||||||
|
Ω(err).ShouldNot(HaveOccurred())
|
||||||
|
|
||||||
|
tag, err := ioutil.ReadFile(filepath.Join(destDir, "tag"))
|
||||||
|
Ω(err).ShouldNot(HaveOccurred())
|
||||||
|
|
||||||
|
Ω(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() {
|
It("fetches from the latest release", func() {
|
||||||
_, err := os.Stat(filepath.Join(destDir, "example.txt"))
|
_, err := os.Stat(filepath.Join(destDir, "example.txt"))
|
||||||
Ω(err).ShouldNot(HaveOccurred())
|
Ω(err).ShouldNot(HaveOccurred())
|
||||||
|
13
strings.go
13
strings.go
@@ -1,13 +0,0 @@
|
|||||||
package resource
|
|
||||||
|
|
||||||
import "unicode"
|
|
||||||
|
|
||||||
func dropLeadingAlpha(s string) string {
|
|
||||||
for i, r := range s {
|
|
||||||
if !unicode.IsLetter(r) {
|
|
||||||
return s[i:]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ""
|
|
||||||
}
|
|
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