This repository has been archived by the owner on Mar 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make stacks metadata for dependencies dependent on version (#179)
* create action that finds stacks thats that match versions * use get-compatible-stacks action in test and upload workflows
- Loading branch information
Frankie G-J
authored
Jul 7, 2022
1 parent
ae346d3
commit 0899228
Showing
7 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM golang:alpine | ||
|
||
COPY entrypoint /tmp/entrypoint | ||
RUN cd /tmp/entrypoint && go build -o /entrypoint . | ||
|
||
ENTRYPOINT ["/entrypoint"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: 'Get Stacks Compatible With Version' | ||
description: | | ||
Takes a version and a list of stacks with version constraints and returns a | ||
list of stacks that are compatible with the given version | ||
inputs: | ||
version: | ||
description: dependency version | ||
required: true | ||
stacks: | ||
description: JSON array of stacks with version constraints | ||
required: true | ||
|
||
outputs: | ||
compatible-stacks: | ||
description: JSON array of stacks that fulfill the version constraints | ||
|
||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' | ||
args: | ||
- "--version" | ||
- "${{ inputs.version }}" | ||
- "--stacks" | ||
- "${{ inputs.stacks }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/paketo-buildpacks/dep-server/actions/get-compatible-stacks/entrypoint | ||
|
||
go 1.18 | ||
|
||
require github.com/Masterminds/semver v1.5.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= | ||
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"flag" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/Masterminds/semver" | ||
) | ||
|
||
type Stack struct { | ||
ID string `json:"id"` | ||
VersionConstraint string `json:"version-constraint,omitempty"` | ||
Mixins []string `json:"mixins,omitempty"` | ||
} | ||
|
||
func main() { | ||
var config struct { | ||
Version string | ||
StacksJSON string | ||
} | ||
|
||
flag.StringVar(&config.StacksJSON, | ||
"stacks", | ||
"", | ||
"JSON array of stack IDs with version constraints") | ||
flag.StringVar(&config.Version, | ||
"version", | ||
"", | ||
"Version of dependency") | ||
|
||
flag.Parse() | ||
|
||
if config.StacksJSON == "" { | ||
config.StacksJSON = `[]` | ||
} | ||
|
||
var stacks []Stack | ||
err := json.Unmarshal([]byte(config.StacksJSON), &stacks) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
var result []Stack | ||
for _, stack := range stacks { | ||
if stack.VersionConstraint == "" { | ||
result = append(result, Stack{ID: stack.ID, Mixins: stack.Mixins}) | ||
continue | ||
} | ||
c, err := semver.NewConstraint(stack.VersionConstraint) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
v, _ := semver.NewVersion(config.Version) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
compatible, msgs := c.Validate(v) | ||
if compatible { | ||
result = append(result, Stack{ID: stack.ID, Mixins: stack.Mixins}) | ||
continue | ||
} | ||
for _, m := range msgs { | ||
log.Println(m) | ||
} | ||
} | ||
output, err := json.Marshal(result) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if len(result) == 0 { | ||
log.Fatal("No stacks compatible with this version") | ||
} | ||
|
||
log.Println("Output: ", string(output)) | ||
fmt.Printf("::set-output name=compatible-stacks::%s\n", string(output)) | ||
} |