Skip to content

Commit a47692a

Browse files
authored
Merge pull request #9 from kumada626/enable_channel_option
fix: Install from the specified release channel
2 parents bb74653 + da29a8b commit a47692a

File tree

5 files changed

+268
-83
lines changed

5 files changed

+268
-83
lines changed

README.md

+64-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,64 @@
1-
# sd-step
1+
# sd-step
2+
[![Build Status][build-image]][build-url]
3+
[![Latest Release][version-image]][version-url]
4+
[![Go Report Card][goreport-image]][goreport-url]
5+
6+
> Wrapper command of habitat for Screwdriver
7+
8+
## Usage
9+
10+
```bash
11+
$ go get github.com/screwdriver-cd/sd-step
12+
$ cd $GOPATH/src/github.com/screwdriver-cd/sd-step
13+
$ go build -a -o sd-step
14+
$ ./sd-step --help
15+
NAME:
16+
sd-step - wrapper command of habitat for Screwdriver
17+
18+
USAGE:
19+
sd-step command arguments [options]
20+
21+
VERSION:
22+
0.0.0
23+
24+
COMMANDS:
25+
exec Install and exec habitat package with pkg_name and command...
26+
help, h Shows a list of commands or help for one command
27+
28+
GLOBAL OPTIONS:
29+
--pkg-version value Package version which also accepts semver expression
30+
--hab-channel value Install from the specified release channel (default: "stable")
31+
--help, -h show help
32+
--version, -v print the version
33+
34+
COPYRIGHT:
35+
(c) 2017 Yahoo Inc.
36+
$ ./sd-step exec core/node "node -v"
37+
v8.9.0
38+
$ ./sd-step exec --pkg-version "~6.11.0" core/node "node -v"
39+
v6.11.5
40+
$ ./sd-step exec --pkg-version "^6.0.0" core/node "node -v"
41+
v6.11.5
42+
$ ./sd-step exec --pkg-version "4.2.6" core/node "node -v"
43+
v4.2.6
44+
$ ./sd-step exec --pkg-version "~6.9.0" --hab-channel "unstable" core/node "node -v"
45+
v6.9.5
46+
```
47+
48+
## Testing
49+
50+
```bash
51+
$ go get github.com/screwdriver-cd/sd-step
52+
$ go test -cover github.com/screwdriver-cd/sd-step/...
53+
```
54+
55+
## License
56+
57+
Code licensed under the BSD 3-Clause license. See LICENSE file for terms.
58+
59+
[version-image]: https://img.shields.io/github/tag/screwdriver-cd/sd-step.svg
60+
[version-url]: https://github.com/screwdriver-cd/sd-step/releases
61+
[build-image]: https://cd.screwdriver.cd/pipelines/150/badge
62+
[build-url]: https://cd.screwdriver.cd/pipelines/150
63+
[goreport-image]: https://goreportcard.com/badge/github.com/Screwdriver-cd/sd-step
64+
[goreport-url]: https://goreportcard.com/report/github.com/Screwdriver-cd/sd-step

hab/hab.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ type PackagesInfo struct {
1818

1919
// PackageInfo is package info in pkgs response
2020
type PackageInfo struct {
21-
Origin string `json:"origin"`
22-
Name string `json:"name"`
23-
Version string `json:"version"`
24-
Release string `json:"release"`
21+
Origin string `json:"origin"`
22+
Name string `json:"name"`
23+
Version string `json:"version"`
24+
Release string `json:"release"`
25+
Channels []string `json:"channels"`
2526
}
2627

2728
// Depot for hab
2829
type Depot interface {
29-
PackageVersionsFromName(pkgName string) ([]string, error)
30+
PackageVersionsFromName(pkgName string, habChannel string) ([]string, error)
3031
}
3132

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

6970
// PackageVersionsFromName fetch all versions from depot
70-
func (depo *depot) PackageVersionsFromName(pkgName string) ([]string, error) {
71+
func (depo *depot) PackageVersionsFromName(pkgName string, habChannel string) ([]string, error) {
7172
var packages []PackageInfo
7273

7374
offset := 0
@@ -93,8 +94,13 @@ func (depo *depot) PackageVersionsFromName(pkgName string) ([]string, error) {
9394
if foundVersions[pkg.Version] {
9495
continue
9596
}
96-
versions = append(versions, pkg.Version)
97-
foundVersions[pkg.Version] = true
97+
for _, channel := range pkg.Channels {
98+
if channel == habChannel {
99+
versions = append(versions, pkg.Version)
100+
foundVersions[pkg.Version] = true
101+
break
102+
}
103+
}
98104
}
99105

100106
return versions, nil

0 commit comments

Comments
 (0)