Skip to content

Commit

Permalink
Automatically update lifecycle.toml when new apis are added (#756)
Browse files Browse the repository at this point in the history
Signed-off-by: Natalie Arellano <narellano@vmware.com>
  • Loading branch information
natalieparellano authored Nov 10, 2021
1 parent 6438e02 commit 7762adc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
17 changes: 15 additions & 2 deletions api/apis.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package api

import (
"fmt"
"strings"

"github.com/pkg/errors"
)

Expand All @@ -10,8 +13,18 @@ var (
)

type APIs struct {
Supported []*Version
Deprecated []*Version
Supported List
Deprecated List
}

type List []*Version

func (l List) String() string {
var els []string
for _, el := range l {
els = append(els, fmt.Sprintf("%q", el.String()))
}
return "[" + strings.Join(els, ", ") + "]"
}

// newApisMustParse calls NewApis and panics on error
Expand Down
8 changes: 4 additions & 4 deletions lifecycle.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[apis]
[apis.buildpack]
deprecated = []
supported = ["0.2", "0.3", "0.4", "0.5", "0.6"]
deprecated = {{.apis_buildpack_deprecated}}
supported = {{.apis_buildpack_supported}}
[apis.platform]
deprecated = []
supported = ["0.3", "0.4", "0.5", "0.6", "0.7"]
deprecated = {{.apis_platform_deprecated}}
supported = {{.apis_platform_supported}}

# For backwards compatibility the minimum supported APIs are provided in RFC-0011 format
# https://github.com/buildpacks/rfcs/blob/main/text/0011-lifecycle-descriptor.md
Expand Down
9 changes: 8 additions & 1 deletion tools/packager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/pkg/errors"

"github.com/buildpacks/lifecycle/api"
"github.com/buildpacks/lifecycle/archive"
)

Expand Down Expand Up @@ -65,7 +66,13 @@ func doPackage() error {
return errors.Wrap(err, fmt.Sprintf("Failed to read descriptor file %s", descriptorPath))
}

descriptorContents, err := fillTemplate(templateContents, map[string]interface{}{"lifecycle_version": version})
descriptorContents, err := fillTemplate(templateContents, map[string]interface{}{
"lifecycle_version": version,
"apis_buildpack_supported": api.Buildpack.Supported.String(),
"apis_buildpack_deprecated": api.Buildpack.Deprecated.String(),
"apis_platform_supported": api.Platform.Supported.String(),
"apis_platform_deprecated": api.Platform.Deprecated.String(),
})
if err != nil {
return errors.Wrap(err, "Failed to fill template")
}
Expand Down

0 comments on commit 7762adc

Please sign in to comment.