Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optionally put assets in separate dir
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Standley <[email protected]>
mstandley-tempus committed Feb 19, 2024
1 parent daa864f commit 0485362
Showing 4 changed files with 40 additions and 4 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -65,6 +65,10 @@ Fetches and creates versioned GitHub resources.
Selects whether to order releases by version (as extracted by `tag_filter`)
or by time. See `check` behavior described below for details.

* `asset_dir`: *Optional. Default `false`.* When set to `true`, downloaded assets
will be created in a separate directory called `assets`. Otherwise, they will be
created in the same directory as the other files.

### Example

``` yaml
@@ -135,7 +139,8 @@ Otherwise it returns the release with the latest version or time.

### `in`: Fetch assets from a release.

Fetches artifacts from the requested release.
Fetches artifacts from the requested release. If `asset_dir` source param is set to `true`,
artifacts will be created in a subdirectory called `assets`.

Also creates the following files:

16 changes: 13 additions & 3 deletions in_command.go
Original file line number Diff line number Diff line change
@@ -31,6 +31,16 @@ func (c *InCommand) Run(destDir string, request InRequest) (InResponse, error) {
return InResponse{}, err
}

// if AssetDir is true, create a separate directory for assets
assetDir := destDir
if request.Source.AssetDir {
assetDir = filepath.Join(destDir, "assets")
err = os.MkdirAll(assetDir, 0755)
if err != nil {
return InResponse{}, err
}
}

var foundRelease *github.RepositoryRelease
var commitSHA string

@@ -121,7 +131,7 @@ func (c *InCommand) Run(destDir string, request InRequest) (InResponse, error) {
continue
}

path := filepath.Join(destDir, *asset.Name)
path := filepath.Join(assetDir, *asset.Name)

var matchFound bool
if len(request.Params.Globs) == 0 {
@@ -158,7 +168,7 @@ func (c *InCommand) Run(destDir string, request InRequest) (InResponse, error) {
return InResponse{}, err
}
fmt.Fprintln(c.writer, "downloading source tarball to source.tar.gz")
if err := c.downloadFile(u.String(), filepath.Join(destDir, "source.tar.gz")); err != nil {
if err := c.downloadFile(u.String(), filepath.Join(assetDir, "source.tar.gz")); err != nil {
return InResponse{}, err
}
}
@@ -169,7 +179,7 @@ func (c *InCommand) Run(destDir string, request InRequest) (InResponse, error) {
return InResponse{}, err
}
fmt.Fprintln(c.writer, "downloading source zip to source.zip")
if err := c.downloadFile(u.String(), filepath.Join(destDir, "source.zip")); err != nil {
if err := c.downloadFile(u.String(), filepath.Join(assetDir, "source.zip")); err != nil {
return InResponse{}, err
}
}
20 changes: 20 additions & 0 deletions in_command_test.go
Original file line number Diff line number Diff line change
@@ -270,6 +270,16 @@ var _ = Describe("In Command", func() {
Expect(err).NotTo(HaveOccurred())
Expect(fContents).To(Equal("source-tar-file-contents"))
})

It("saves the source tarball in the assets directory, if desired", func() {
inRequest.Source.AssetDir = true
inResponse, inErr = command.Run(destDir, inRequest)

fileContents, err := ioutil.ReadFile(filepath.Join(destDir, "assets", "source.tar.gz"))
fContents := string(fileContents)
Expect(err).NotTo(HaveOccurred())
Expect(fContents).To(Equal("source-tar-file-contents"))
})
})

Context("when downloading the tarball fails", func() {
@@ -350,6 +360,16 @@ var _ = Describe("In Command", func() {
Expect(err).NotTo(HaveOccurred())
Expect(fContents).To(Equal("source-zip-file-contents"))
})

It("saves the source tarball in the assets directory, if desired", func() {
inRequest.Source.AssetDir = true
inResponse, inErr = command.Run(destDir, inRequest)

fileContents, err := ioutil.ReadFile(filepath.Join(destDir, "assets", "source.tar.gz"))
fContents := string(fileContents)
Expect(err).NotTo(HaveOccurred())
Expect(fContents).To(Equal("source-zip-file-contents"))
})
})

Context("when downloading the zip fails", func() {
1 change: 1 addition & 0 deletions resources.go
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ type Source struct {
PreRelease bool `json:"pre_release"`
Release bool `json:"release"`
Insecure bool `json:"insecure"`
AssetDir bool `json:"asset_dir"`

TagFilter string `json:"tag_filter"`
OrderBy string `json:"order_by"`

0 comments on commit 0485362

Please sign in to comment.