Skip to content

Commit

Permalink
Merge pull request #91 from paketo-buildpacks/make-public
Browse files Browse the repository at this point in the history
Make Public

Signed-off-by: Ben Hale <bhale@vmware.com>
  • Loading branch information
nebhale authored Nov 4, 2020
2 parents 68813f6 + cb77028 commit 58c0e12
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 82 deletions.
8 changes: 3 additions & 5 deletions cmd/octo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,18 @@ import (
)

func main() {
w := octo.Octo{}

flagSet := pflag.NewFlagSet("octo", pflag.ExitOnError)
flagSet.StringVar(&w.DescriptorPath, "descriptor", "", "path to input descriptor")
descriptor := flagSet.String("descriptor", "", "path to input descriptor")

if err := flagSet.Parse(os.Args[1:]); err != nil {
log.Fatal(fmt.Errorf("unable to parse flags\n%w", err))
}

if w.DescriptorPath == "" {
if descriptor == nil {
log.Fatal("--descriptor is required")
}

if err := w.Contribute(); err != nil {
if err := octo.Contribute(*descriptor); err != nil {
log.Fatal(fmt.Errorf("unable to build\n%w", err))
}
}
4 changes: 2 additions & 2 deletions octo/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ func ContributeActions(descriptor Descriptor) ([]Contribution, error) {
{
Id: "version",
Name: "Compute Version",
Run: statikString("/compute-version.sh"),
Run: StatikString("/compute-version.sh"),
},
{
Name: "Create Action",
Run: statikString("/create-action.sh"),
Run: StatikString("/create-action.sh"),
Env: map[string]string{
"PUSH": "${{ github.event_name != 'pull_request' }}",
"SOURCE": a.Source,
Expand Down
14 changes: 7 additions & 7 deletions octo/builder_dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ func contributeBuildImage(descriptor Descriptor, image string, classifier string
},
{
Name: "Install update-build-image-dependency",
Run: statikString("/install-update-build-image-dependency.sh"),
Run: StatikString("/install-update-build-image-dependency.sh"),
},
{
Name: "Install crane",
Run: statikString("/install-crane.sh"),
Run: StatikString("/install-crane.sh"),
Env: map[string]string{"CRANE_VERSION": CraneVersion},
},
{
Name: "Install yj",
Run: statikString("/install-yj.sh"),
Run: StatikString("/install-yj.sh"),
Env: map[string]string{"YJ_VERSION": YJVersion},
},
{
Expand All @@ -109,7 +109,7 @@ func contributeBuildImage(descriptor Descriptor, image string, classifier string
{
Id: "build-image",
Name: "Update Build Image Dependency",
Run: statikString("/update-build-image-dependency.sh"),
Run: StatikString("/update-build-image-dependency.sh"),
Env: map[string]string{
"IMAGE": image,
"CLASSIFIER": classifier,
Expand Down Expand Up @@ -160,11 +160,11 @@ func contributeLifecycle(descriptor Descriptor) (Contribution, error) {
},
{
Name: "Install update-lifecycle-dependency",
Run: statikString("/install-update-lifecycle-dependency.sh"),
Run: StatikString("/install-update-lifecycle-dependency.sh"),
},
{
Name: "Install yj",
Run: statikString("/install-yj.sh"),
Run: StatikString("/install-yj.sh"),
Env: map[string]string{"YJ_VERSION": YJVersion},
},
{
Expand All @@ -183,7 +183,7 @@ func contributeLifecycle(descriptor Descriptor) (Contribution, error) {
{
Id: "lifecycle",
Name: "Update Lifecycle Dependency",
Run: statikString("/update-lifecycle-dependency.sh"),
Run: StatikString("/update-lifecycle-dependency.sh"),
Env: map[string]string{
"VERSION": "${{ steps.dependency.outputs.version }}",
},
Expand Down
6 changes: 3 additions & 3 deletions octo/buildpack_dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ func ContributeBuildpackDependencies(descriptor Descriptor) ([]Contribution, err
},
{
Name: "Install update-buildpack-dependency",
Run: statikString("/install-update-buildpack-dependency.sh"),
Run: StatikString("/install-update-buildpack-dependency.sh"),
},
{
Name: "Install yj",
Run: statikString("/install-yj.sh"),
Run: StatikString("/install-yj.sh"),
Env: map[string]string{"YJ_VERSION": YJVersion},
},
{
Expand All @@ -64,7 +64,7 @@ func ContributeBuildpackDependencies(descriptor Descriptor) ([]Contribution, err
{
Id: "buildpack",
Name: "Update Buildpack Dependency",
Run: statikString("/update-buildpack-dependency.sh"),
Run: StatikString("/update-buildpack-dependency.sh"),
Env: map[string]string{
"ID": d.Id,
"SHA256": "${{ steps.dependency.outputs.sha256 }}",
Expand Down
2 changes: 1 addition & 1 deletion octo/contribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func NewHttpCredentialActions(credentials []HTTPCredentials) []actions.Step {
s = append(s, actions.Step{
Name: fmt.Sprintf("HTTP login %s", c.Host),
If: "${{ github.event_name != 'pull_request' || ! github.event.pull_request.head.repo.fork }}",
Run: statikString("/update-netrc.sh"),
Run: StatikString("/update-netrc.sh"),
Env: map[string]string{
"HOST": c.Host,
"USERNAME": c.Username,
Expand Down
10 changes: 5 additions & 5 deletions octo/create_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ func ContributeCreateBuilder(descriptor Descriptor) (*Contribution, error) {
},
{
Name: "Install crane",
Run: statikString("/install-crane.sh"),
Run: StatikString("/install-crane.sh"),
Env: map[string]string{"CRANE_VERSION": CraneVersion},
},
{
Name: "Install pack",
Run: statikString("/install-pack.sh"),
Run: StatikString("/install-pack.sh"),
Env: map[string]string{"PACK_VERSION": PackVersion},
},
{
Expand All @@ -60,12 +60,12 @@ func ContributeCreateBuilder(descriptor Descriptor) (*Contribution, error) {
{
Id: "version",
Name: "Compute Version",
Run: statikString("/compute-version.sh"),
Run: StatikString("/compute-version.sh"),
},
{
Id: "builder",
Name: "Create Builder",
Run: statikString("/create-builder.sh"),
Run: StatikString("/create-builder.sh"),
Env: map[string]string{
"BUILDER": descriptor.Builder.Repository,
"PUBLISH": "true",
Expand All @@ -74,7 +74,7 @@ func ContributeCreateBuilder(descriptor Descriptor) (*Contribution, error) {
},
{
Name: "Update release with digest",
Run: statikString("/update-release-digest.sh"),
Run: StatikString("/update-release-digest.sh"),
Env: map[string]string{
"DIGEST": "${{ steps.builder.outputs.digest }}",
"GITHUB_TOKEN": descriptor.GitHubToken,
Expand Down
14 changes: 7 additions & 7 deletions octo/create_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ func ContributeCreatePackage(descriptor Descriptor) (*Contribution, error) {
},
{
Name: "Install create-package",
Run: statikString("/install-create-package.sh"),
Run: StatikString("/install-create-package.sh"),
},
{
Name: "Install crane",
Run: statikString("/install-crane.sh"),
Run: StatikString("/install-crane.sh"),
Env: map[string]string{"CRANE_VERSION": CraneVersion},
},
{
Name: "Install pack",
Run: statikString("/install-pack.sh"),
Run: StatikString("/install-pack.sh"),
Env: map[string]string{"PACK_VERSION": PackVersion},
},
{
Expand All @@ -85,11 +85,11 @@ func ContributeCreatePackage(descriptor Descriptor) (*Contribution, error) {
{
Id: "version",
Name: "Compute Version",
Run: statikString("/compute-version.sh"),
Run: StatikString("/compute-version.sh"),
},
{
Name: "Create Package",
Run: statikString("/create-package.sh"),
Run: StatikString("/create-package.sh"),
Env: map[string]string{
"INCLUDE_DEPENDENCIES": strconv.FormatBool(descriptor.Package.IncludeDependencies),
"VERSION": "${{ steps.version.outputs.version }}",
Expand All @@ -98,7 +98,7 @@ func ContributeCreatePackage(descriptor Descriptor) (*Contribution, error) {
{
Id: "package",
Name: "Package Buildpack",
Run: statikString("/package-buildpack.sh"),
Run: StatikString("/package-buildpack.sh"),
Env: map[string]string{
"PACKAGE": descriptor.Package.Repository,
"PUBLISH": "true",
Expand All @@ -107,7 +107,7 @@ func ContributeCreatePackage(descriptor Descriptor) (*Contribution, error) {
},
{
Name: "Update release with digest",
Run: statikString("/update-release-digest.sh"),
Run: StatikString("/update-release-digest.sh"),
Env: map[string]string{
"DIGEST": "${{ steps.package.outputs.digest }}",
"GITHUB_TOKEN": descriptor.GitHubToken,
Expand Down
4 changes: 2 additions & 2 deletions octo/dependabot.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func ContributeDependabot(descriptor Descriptor) (Contribution, error) {
}

file := filepath.Join(descriptor.Path, "go.mod")
if e, err := exists(file); err != nil {
return Contribution{}, fmt.Errorf("unable to determine if %s exists\n%w", file, err)
if e, err := Exists(file); err != nil {
return Contribution{}, fmt.Errorf("unable to determine if %s Exists\n%w", file, err)
} else if e {
d.Updates = append(d.Updates, dependabot.Update{
PackageEcosystem: dependabot.GoModulesPackageEcosystem,
Expand Down
6 changes: 3 additions & 3 deletions octo/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func NewDescriptor(path string) (Descriptor, error) {

if !filepath.IsAbs(d.Path) {
if d.Path, err = filepath.Abs(filepath.Join(filepath.Dir(path), d.Path)); err != nil {
return Descriptor{}, fmt.Errorf("unable to find absolute path\n%w", err)
return Descriptor{}, fmt.Errorf("unable to Find absolute path\n%w", err)
}
}

Expand All @@ -132,12 +132,12 @@ func NewDescriptor(path string) (Descriptor, error) {
d.Test.Steps = []actions.Step{
{
Name: "Install richgo",
Run: statikString("/install-richgo.sh"),
Run: StatikString("/install-richgo.sh"),
Env: map[string]string{"RICHGO_VERSION": RichGoVersion},
},
{
Name: "Run Tests",
Run: statikString("/run-tests.sh"),
Run: StatikString("/run-tests.sh"),
Env: map[string]string{"RICHGO_FORCE_COLOR": "1"},
},
}
Expand Down
18 changes: 9 additions & 9 deletions octo/draft_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,21 @@ func ContributeDraftRelease(descriptor Descriptor) ([]Contribution, error) {
}

file := filepath.Join(descriptor.Path, "builder.toml")
builderExists, err := exists(file)
builderExists, err := Exists(file)
if err != nil {
return nil, fmt.Errorf("unable to determine if %s exists\n%w", file, err)
return nil, fmt.Errorf("unable to determine if %s Exists\n%w", file, err)
}

file = filepath.Join(descriptor.Path, "buildpack.toml")
buildpackExists, err := exists(file)
buildpackExists, err := Exists(file)
if err != nil {
return nil, fmt.Errorf("unable to determine if %s exists\n%w", file, err)
return nil, fmt.Errorf("unable to determine if %s Exists\n%w", file, err)
}

file = filepath.Join(descriptor.Path, "package.toml")
packageExists, err := exists(file)
packageExists, err := Exists(file)
if err != nil {
return nil, fmt.Errorf("unable to determine if %s exists\n%w", file, err)
return nil, fmt.Errorf("unable to determine if %s Exists\n%w", file, err)
}

if builderExists || buildpackExists {
Expand All @@ -122,7 +122,7 @@ func ContributeDraftRelease(descriptor Descriptor) ([]Contribution, error) {
j.Steps = append(j.Steps,
actions.Step{
Name: "Install crane",
Run: statikString("/install-crane.sh"),
Run: StatikString("/install-crane.sh"),
Env: map[string]string{"CRANE_VERSION": CraneVersion},
},
)
Expand All @@ -131,15 +131,15 @@ func ContributeDraftRelease(descriptor Descriptor) ([]Contribution, error) {
j.Steps = append(j.Steps,
actions.Step{
Name: "Install yj",
Run: statikString("/install-yj.sh"),
Run: StatikString("/install-yj.sh"),
Env: map[string]string{"YJ_VERSION": YJVersion},
},
actions.Step{
Uses: "actions/checkout@v2",
},
actions.Step{
Name: "Update draft release with buildpack information",
Run: statikString("/update-draft-release-buildpack.sh"),
Run: StatikString("/update-draft-release-buildpack.sh"),
Env: map[string]string{
"GITHUB_TOKEN": descriptor.GitHubToken,
"RELEASE_ID": "${{ steps.release-drafter.outputs.id }}",
Expand Down
18 changes: 7 additions & 11 deletions octo/octo.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,10 @@ const (

var RemovedFiles []string

type Octo struct {
DescriptorPath string
}

func (o Octo) Contribute() error {
descriptor, err := NewDescriptor(o.DescriptorPath)
func Contribute(path string) error {
descriptor, err := NewDescriptor(path)
if err != nil {
return fmt.Errorf("unable to read descriptor\n%w", err)
return fmt.Errorf("unable to read descriptor %s\n%w", path, err)
}

var contributions []Contribution
Expand Down Expand Up @@ -124,14 +120,14 @@ func (o Octo) Contribute() error {
contributions = append(contributions, c)
}

if err := o.Remove(descriptor, RemovedFiles); err != nil {
if err := Remove(descriptor, RemovedFiles); err != nil {
return err
}

return o.Write(descriptor, contributions)
return Write(descriptor, contributions)
}

func (Octo) Remove(descriptor Descriptor, removals []string) error {
func Remove(descriptor Descriptor, removals []string) error {
for _, r := range removals {
file := filepath.Join(descriptor.Path, r)
fmt.Printf("Removing %s\n", r)
Expand All @@ -144,7 +140,7 @@ func (Octo) Remove(descriptor Descriptor, removals []string) error {
return nil
}

func (Octo) Write(descriptor Descriptor, contributions []Contribution) error {
func Write(descriptor Descriptor, contributions []Contribution) error {
t := gotree.New(descriptor.Path)

sort.Slice(contributions, func(i, j int) bool {
Expand Down
12 changes: 6 additions & 6 deletions octo/offline_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func contributeOfflinePackage(descriptor Descriptor, offlinePackage OfflinePacka
Steps: []actions.Step{
{
Name: "Install crane",
Run: statikString("/install-crane.sh"),
Run: StatikString("/install-crane.sh"),
Env: map[string]string{"CRANE_VERSION": CraneVersion},
},
{
Expand All @@ -66,7 +66,7 @@ func contributeOfflinePackage(descriptor Descriptor, offlinePackage OfflinePacka
{
Id: "version",
Name: "Checkout next version",
Run: statikString("/checkout-next-version.sh"),
Run: StatikString("/checkout-next-version.sh"),
Env: map[string]string{
"SOURCE": offlinePackage.Source,
"TARGET": offlinePackage.Target,
Expand All @@ -91,18 +91,18 @@ func contributeOfflinePackage(descriptor Descriptor, offlinePackage OfflinePacka
{
Name: "Install create-package",
If: "${{ ! steps.version.outputs.skip }}",
Run: statikString("/install-create-package.sh"),
Run: StatikString("/install-create-package.sh"),
},
{
Name: "Install pack",
If: "${{ ! steps.version.outputs.skip }}",
Run: statikString("/install-pack.sh"),
Run: StatikString("/install-pack.sh"),
Env: map[string]string{"PACK_VERSION": PackVersion},
},
{
Name: "Create Package",
If: "${{ ! steps.version.outputs.skip }}",
Run: statikString("/create-package.sh"),
Run: StatikString("/create-package.sh"),
Env: map[string]string{
"INCLUDE_DEPENDENCIES": "true",
"VERSION": "${{ steps.version.outputs.version }}",
Expand All @@ -111,7 +111,7 @@ func contributeOfflinePackage(descriptor Descriptor, offlinePackage OfflinePacka
{
Name: "Package Buildpack",
If: "${{ ! steps.version.outputs.skip }}",
Run: statikString("/package-buildpack.sh"),
Run: StatikString("/package-buildpack.sh"),
Env: map[string]string{
"PACKAGE": offlinePackage.Target,
"PUBLISH": "true",
Expand Down
Loading

0 comments on commit 58c0e12

Please sign in to comment.