Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
H
heroku-buildpack-nodejs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
heroku-buildpack-nodejs
Commits
58078fcb
Unverified
Commit
58078fcb
authored
Apr 19, 2019
by
Jeremy Morrell
Committed by
GitHub
Apr 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add CLI interface and resolve Yarn versions (#654)
parent
d9867fee
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
105 additions
and
4 deletions
+105
-4
main.go
cmd/resolve-version/main.go
+48
-4
main_test.go
cmd/resolve-version/main_test.go
+57
-0
No files found.
cmd/resolve-version/main.go
View file @
58078fcb
...
...
@@ -7,6 +7,7 @@ import (
"io/ioutil"
"net/http"
"net/url"
"os"
"regexp"
"sort"
"time"
...
...
@@ -47,6 +48,53 @@ type matchResult struct {
matched
bool
}
func
main
()
{
if
len
(
os
.
Args
)
<
3
{
printUsage
()
os
.
Exit
(
0
)
}
binary
:=
os
.
Args
[
1
]
versionRequirement
:=
os
.
Args
[
2
]
if
binary
==
"yarn"
{
objects
,
err
:=
listS3Objects
(
"heroku-nodebin"
,
"yarn"
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
Exit
(
1
)
}
result
,
err
:=
resolveYarn
(
objects
,
versionRequirement
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
Exit
(
1
)
}
if
result
.
matched
{
fmt
.
Printf
(
"%s %s
\n
"
,
result
.
release
.
version
.
String
(),
result
.
release
.
url
)
}
else
{
fmt
.
Println
(
"No result"
)
os
.
Exit
(
1
)
}
}
}
func
printUsage
()
{
fmt
.
Println
(
"resolve-version binary version-requirement"
)
}
func
resolveYarn
(
objects
[]
s3Object
,
versionRequirement
string
)
(
matchResult
,
error
)
{
releases
:=
[]
release
{}
for
_
,
obj
:=
range
objects
{
release
,
err
:=
parseObject
(
obj
.
Key
)
if
err
!=
nil
{
continue
}
releases
=
append
(
releases
,
release
)
}
return
matchReleaseSemver
(
releases
,
versionRequirement
)
}
func
matchReleaseSemver
(
releases
[]
release
,
versionRequirement
string
)
(
matchResult
,
error
)
{
constraints
,
err
:=
semver
.
NewConstraint
(
versionRequirement
)
if
err
!=
nil
{
...
...
@@ -193,7 +241,3 @@ func listS3Objects(bucketName string, prefix string) ([]s3Object, error) {
return
out
,
nil
}
func
main
()
{
fmt
.
Println
(
"hello world"
)
}
cmd/resolve-version/main_test.go
View file @
58078fcb
package
main
import
(
"fmt"
"testing"
"time"
"github.com/Masterminds/semver"
...
...
@@ -122,3 +124,58 @@ func TestMatchReleaseSemver(t *testing.T) {
assert
.
False
(
t
,
result
.
matched
)
assert
.
Equal
(
t
,
result
.
versionRequirement
,
"99.x"
)
}
func
genYarnS3ObjectList
(
versions
[]
string
)
[]
s3Object
{
out
:=
[]
s3Object
{}
for
_
,
version
:=
range
versions
{
out
=
append
(
out
,
s3Object
{
Key
:
fmt
.
Sprintf
(
"yarn/release/yarn-v%s.tar.gz"
,
version
),
LastModified
:
time
.
Time
{},
ETag
:
"abcdef"
,
Size
:
0
,
StorageClass
:
"normal"
,
})
}
return
out
}
func
TestResolveYarn
(
t
*
testing
.
T
)
{
// yarn releases as of 4/18/2019
objects
:=
genYarnS3ObjectList
([]
string
{
"0.16.0"
,
"0.16.1"
,
"0.17.0"
,
"0.17.10"
,
"0.17.2"
,
"0.17.3"
,
"0.17.4"
,
"0.17.5"
,
"0.17.6"
,
"0.17.7"
,
"0.17.8"
,
"0.17.9"
,
"0.18.0"
,
"0.18.1"
,
"0.18.2"
,
"0.19.0"
,
"0.19.1"
,
"0.20.0"
,
"0.20.3"
,
"0.20.4"
,
"0.21.0"
,
"0.21.1"
,
"0.21.2"
,
"0.21.3"
,
"0.22.0"
,
"0.23.0"
,
"0.23.2"
,
"0.23.3"
,
"0.23.4"
,
"0.24.0"
,
"0.24.1"
,
"0.24.2"
,
"0.24.3"
,
"0.24.4"
,
"0.24.5"
,
"0.24.6"
,
"0.25.1"
,
"0.25.2"
,
"0.25.3"
,
"0.25.4"
,
"0.26.1"
,
"0.27.0"
,
"0.27.1"
,
"0.27.2"
,
"0.27.3"
,
"0.27.4"
,
"0.27.5"
,
"0.28.1"
,
"0.28.4"
,
"1.0.0"
,
"1.0.1"
,
"1.0.2"
,
"1.1.0"
,
"1.10.0"
,
"1.10.1"
,
"1.11.0"
,
"1.11.1"
,
"1.12.0"
,
"1.12.1"
,
"1.12.3"
,
"1.13.0"
,
"1.14.0"
,
"1.15.0"
,
"1.15.1"
,
"1.15.2"
,
"1.2.0"
,
"1.2.1"
,
"1.3.2"
,
"1.4.0"
,
"1.5.1"
,
"1.6.0"
,
"1.7.0"
,
"1.8.0"
,
"1.9.1"
,
"1.9.2"
,
"1.9.4"
,
})
cases
:=
[]
Case
{
Case
{
input
:
"1.13.0"
,
output
:
"1.13.0"
},
Case
{
input
:
"1.15.2"
,
output
:
"1.15.2"
},
Case
{
input
:
"1.x"
,
output
:
"1.15.2"
},
Case
{
input
:
"*"
,
output
:
"1.15.2"
},
Case
{
input
:
"^1.12.1"
,
output
:
"1.15.2"
},
Case
{
input
:
"^1.9.4"
,
output
:
"1.15.2"
},
Case
{
input
:
">= 1.0.0"
,
output
:
"1.15.2"
},
Case
{
input
:
"^1.0"
,
output
:
"1.15.2"
},
Case
{
input
:
"0.24.6 - 1.x"
,
output
:
"1.15.2"
},
Case
{
input
:
"1.*.*"
,
output
:
"1.15.2"
},
Case
{
input
:
"^v1.0.1"
,
output
:
"1.15.2"
},
Case
{
input
:
"1.13 - 1.16"
,
output
:
"1.15.2"
},
// TODO: these fail to parse with the library
// Case{input: ">=1.9.4 <2.0.0", output: "1.15.2"},
}
for
_
,
c
:=
range
cases
{
result
,
err
:=
resolveYarn
(
objects
,
c
.
input
)
if
assert
.
Nil
(
t
,
err
)
{
assert
.
True
(
t
,
result
.
matched
)
assert
.
Equal
(
t
,
result
.
release
.
version
.
String
(),
c
.
output
)
assert
.
Equal
(
t
,
result
.
release
.
url
,
fmt
.
Sprintf
(
"https://s3.amazonaws.com/heroku-nodebin/yarn/release/yarn-v%s.tar.gz"
,
c
.
output
))
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment