Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version regex pattern for Maven dependency action #909

Merged
merged 1 commit into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,12 @@ The Maven Dependency queries a [Maven Repository](https://repo1.maven.org/maven2
```yaml
uses: docker://ghcr.io/paketo-buildpacks/actions/maven-dependency:main
with:
uri: https://repo1.maven.org/maven2
group_id: org.apache.maven
artifact_id: apache-maven
classifier: bin
packaging: tar.gz
uri: https://repo1.maven.org/maven2
group_id: org.apache.maven
artifact_id: apache-maven
classifier: bin
packaging: tar.gz
version_regex: ^3\.[\d]+\.[\d]+$
```

### New Relic Dependency
Expand Down
42 changes: 26 additions & 16 deletions actions/maven-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"net/http"
"os"
"regexp"
"strings"

"github.com/paketo-buildpacks/pipeline-builder/actions"
Expand All @@ -44,6 +45,13 @@ func main() {
panic(fmt.Errorf("artifact_id must be specified"))
}

versionRegex, ok := inputs["version_regex"]
if !ok {
fmt.Println(`No version_regex set, using default: ^[\d]+\.[\d]+\.[\d]+/$`)
versionRegex = `^[\d]+\.[\d]+\.[\d]+$`
dmikusa marked this conversation as resolved.
Show resolved Hide resolved
}
versionPattern := regexp.MustCompile(versionRegex)

uri := fmt.Sprintf("%s/%s/%s/maven-metadata.xml", u, strings.ReplaceAll(g, ".", "/"), a)

resp, err := http.Get(uri)
Expand All @@ -63,23 +71,25 @@ func main() {

versions := make(actions.Versions)
for _, v := range raw.Versioning.Versions {
w := fmt.Sprintf("%s/%s/%s/%s", u, strings.ReplaceAll(g, ".", "/"), a, v)
w = fmt.Sprintf("%s/%s-%s", w, a, v)
if s, ok := inputs["classifier"]; ok {
w = fmt.Sprintf("%s-%s", w, s)
}
if s, ok := inputs["packaging"]; ok {
w = fmt.Sprintf("%s.%s", w, s)
} else {
w = fmt.Sprintf("%s.jar", w)
if p := versionPattern.MatchString(v); p {
w := fmt.Sprintf("%s/%s/%s/%s", u, strings.ReplaceAll(g, ".", "/"), a, v)
w = fmt.Sprintf("%s/%s-%s", w, a, v)
if s, ok := inputs["classifier"]; ok {
w = fmt.Sprintf("%s-%s", w, s)
}
if s, ok := inputs["packaging"]; ok {
w = fmt.Sprintf("%s.%s", w, s)
} else {
w = fmt.Sprintf("%s.jar", w)
}

n, err := actions.NormalizeVersion(v)
if err != nil {
panic(err)
}

versions[n] = w
}

n, err := actions.NormalizeVersion(v)
if err != nil {
panic(err)
}

versions[n] = w
}

if o, err := versions.GetLatest(inputs); err != nil {
Expand Down