Skip to content

Commit

Permalink
Merge pull request #9 from kumada626/enable_channel_option
Browse files Browse the repository at this point in the history
fix: Install from the specified release channel
  • Loading branch information
tkyi authored Nov 8, 2017
2 parents bb74653 + da29a8b commit a47692a
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 83 deletions.
65 changes: 64 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,64 @@
# sd-step
# sd-step
[![Build Status][build-image]][build-url]
[![Latest Release][version-image]][version-url]
[![Go Report Card][goreport-image]][goreport-url]

> Wrapper command of habitat for Screwdriver
## Usage

```bash
$ go get github.com/screwdriver-cd/sd-step
$ cd $GOPATH/src/github.com/screwdriver-cd/sd-step
$ go build -a -o sd-step
$ ./sd-step --help
NAME:
sd-step - wrapper command of habitat for Screwdriver

USAGE:
sd-step command arguments [options]

VERSION:
0.0.0

COMMANDS:
exec Install and exec habitat package with pkg_name and command...
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
--pkg-version value Package version which also accepts semver expression
--hab-channel value Install from the specified release channel (default: "stable")
--help, -h show help
--version, -v print the version

COPYRIGHT:
(c) 2017 Yahoo Inc.
$ ./sd-step exec core/node "node -v"
v8.9.0
$ ./sd-step exec --pkg-version "~6.11.0" core/node "node -v"
v6.11.5
$ ./sd-step exec --pkg-version "^6.0.0" core/node "node -v"
v6.11.5
$ ./sd-step exec --pkg-version "4.2.6" core/node "node -v"
v4.2.6
$ ./sd-step exec --pkg-version "~6.9.0" --hab-channel "unstable" core/node "node -v"
v6.9.5
```

## Testing

```bash
$ go get github.com/screwdriver-cd/sd-step
$ go test -cover github.com/screwdriver-cd/sd-step/...
```

## License

Code licensed under the BSD 3-Clause license. See LICENSE file for terms.

[version-image]: https://img.shields.io/github/tag/screwdriver-cd/sd-step.svg
[version-url]: https://github.com/screwdriver-cd/sd-step/releases
[build-image]: https://cd.screwdriver.cd/pipelines/150/badge
[build-url]: https://cd.screwdriver.cd/pipelines/150
[goreport-image]: https://goreportcard.com/badge/github.com/Screwdriver-cd/sd-step
[goreport-url]: https://goreportcard.com/report/github.com/Screwdriver-cd/sd-step
22 changes: 14 additions & 8 deletions hab/hab.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ type PackagesInfo struct {

// PackageInfo is package info in pkgs response
type PackageInfo struct {
Origin string `json:"origin"`
Name string `json:"name"`
Version string `json:"version"`
Release string `json:"release"`
Origin string `json:"origin"`
Name string `json:"name"`
Version string `json:"version"`
Release string `json:"release"`
Channels []string `json:"channels"`
}

// Depot for hab
type Depot interface {
PackageVersionsFromName(pkgName string) ([]string, error)
PackageVersionsFromName(pkgName string, habChannel string) ([]string, error)
}

type depot struct {
Expand Down Expand Up @@ -67,7 +68,7 @@ func (depo *depot) packagesInfo(pkgName string, from int) (PackagesInfo, error)
}

// PackageVersionsFromName fetch all versions from depot
func (depo *depot) PackageVersionsFromName(pkgName string) ([]string, error) {
func (depo *depot) PackageVersionsFromName(pkgName string, habChannel string) ([]string, error) {
var packages []PackageInfo

offset := 0
Expand All @@ -93,8 +94,13 @@ func (depo *depot) PackageVersionsFromName(pkgName string) ([]string, error) {
if foundVersions[pkg.Version] {
continue
}
versions = append(versions, pkg.Version)
foundVersions[pkg.Version] = true
for _, channel := range pkg.Channels {
if channel == habChannel {
versions = append(versions, pkg.Version)
foundVersions[pkg.Version] = true
break
}
}
}

return versions, nil
Expand Down
Loading

0 comments on commit a47692a

Please sign in to comment.