Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Make stacks metadata for dependencies dependent on version (#179)
Browse files Browse the repository at this point in the history
* 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 committed Jul 7, 2022
1 parent ae346d3 commit 0899228
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .github/data/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@
requires: dotnet-sdk
stacks:
- id: io.buildpacks.stacks.bionic
version-constraint: "*"
- id: io.buildpacks.stacks.jammy
version-constraint: ">=6.*"
- name: dotnet-runtime
requires: dotnet-sdk
stacks:
- id: io.buildpacks.stacks.bionic
version-constraint: "*"
- id: io.buildpacks.stacks.jammy
version-constraint: ">=6.*"
- name: dotnet-sdk
stacks:
- id: io.buildpacks.stacks.bionic
version-constraint: "*"
- id: io.buildpacks.stacks.jammy
version-constraint: ">=6.*"
- name: go
stacks:
- id: io.buildpacks.stacks.bionic
Expand Down
9 changes: 8 additions & 1 deletion .github/templates/test-upload-metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ jobs:
with:
version: ${{ github.event.client_payload.version }}

- name: Get Stacks for Version
id: compatible-stacks
uses: paketo-buildpacks/dep-server/actions/get-compatible-stacks@main
with:
version: "${{ steps.semantic-version.outputs.sem-version }}"
stacks: #@ data.values.stacks

- name: Upload dependency metadata
uses: paketo-buildpacks/dep-server/actions/upload-metadata@main
with:
Expand All @@ -68,7 +75,7 @@ jobs:
version: "${{ steps.semantic-version.outputs.sem-version }}"
sha256: "${{ github.event.client_payload.sha256 }}"
uri: "${{ github.event.client_payload.uri }}"
stacks: #@ data.values.stacks
stacks: "${{ steps.compatible-stacks.outputs.compatible-stacks }}"
source-uri: "${{ github.event.client_payload.source_uri }}"
source-sha256: "${{ github.event.client_payload.source_sha256 }}"
deprecation-date: "${{ github.event.client_payload.deprecation_date }}"
Expand Down
8 changes: 8 additions & 0 deletions actions/get-compatible-stacks/Dockerfile
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"]


25 changes: 25 additions & 0 deletions actions/get-compatible-stacks/action.yml
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 }}"
5 changes: 5 additions & 0 deletions actions/get-compatible-stacks/entrypoint/go.mod
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
2 changes: 2 additions & 0 deletions actions/get-compatible-stacks/entrypoint/go.sum
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=
79 changes: 79 additions & 0 deletions actions/get-compatible-stacks/entrypoint/main.go
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))
}

0 comments on commit 0899228

Please sign in to comment.