Skip to content

Commit

Permalink
Merge pull request #2 from paketo-community/run
Browse files Browse the repository at this point in the history
Move main.go into run sub-package
  • Loading branch information
dwillist authored Jun 8, 2020
2 parents 9d42d02 + f2e0ce2 commit 1a1799b
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package thin

import (
"github.com/paketo-buildpacks/packit"
Expand Down
8 changes: 3 additions & 5 deletions build_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main_test
package thin_test

import (
"bytes"
Expand All @@ -8,7 +8,7 @@ import (

"github.com/paketo-buildpacks/packit"
"github.com/paketo-buildpacks/packit/scribe"
main "github.com/paketo-community/thin"
"github.com/paketo-community/thin"
"github.com/sclevine/spec"

. "github.com/onsi/gomega"
Expand Down Expand Up @@ -40,7 +40,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
buffer = bytes.NewBuffer(nil)
logger := scribe.NewLogger(buffer)

build = main.Build(logger)
build = thin.Build(logger)
})

it.After(func() {
Expand Down Expand Up @@ -80,7 +80,5 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {

Expect(buffer.String()).To(ContainSubstring("Some Buildpack some-version"))
Expect(buffer.String()).To(ContainSubstring("Writing start command"))

})

}
2 changes: 1 addition & 1 deletion detect.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package thin

import (
"fmt"
Expand Down
12 changes: 6 additions & 6 deletions detect_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main_test
package thin_test

import (
"errors"
Expand All @@ -9,7 +9,7 @@ import (
"io/ioutil"

"github.com/paketo-buildpacks/packit"
main "github.com/paketo-community/thin"
"github.com/paketo-community/thin"
"github.com/paketo-community/thin/fakes"
"github.com/sclevine/spec"

Expand Down Expand Up @@ -38,7 +38,7 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {

gemfileParser = &fakes.Parser{}

detect = main.Detect(gemfileParser)
detect = thin.Detect(gemfileParser)
})

it.After(func() {
Expand All @@ -59,19 +59,19 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
Requires: []packit.BuildPlanRequirement{
{
Name: "gems",
Metadata: main.BuildPlanMetadata{
Metadata: thin.BuildPlanMetadata{
Launch: true,
},
},
{
Name: "bundler",
Metadata: main.BuildPlanMetadata{
Metadata: thin.BuildPlanMetadata{
Launch: true,
},
},
{
Name: "mri",
Metadata: main.BuildPlanMetadata{
Metadata: thin.BuildPlanMetadata{
Launch: true,
},
},
Expand Down
2 changes: 1 addition & 1 deletion gemfile_parser.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package thin

import (
"bufio"
Expand Down
9 changes: 5 additions & 4 deletions gemfile_parser_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package main_test
package thin_test

import (
"io/ioutil"
"os"
"testing"

"github.com/paketo-community/thin"
"github.com/sclevine/spec"

. "github.com/onsi/gomega"
main "github.com/paketo-community/thin"
)

func testGemfileParser(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect

path string
parser main.GemfileParser
parser thin.GemfileParser
)

it.Before(func() {
Expand All @@ -24,7 +25,7 @@ func testGemfileParser(t *testing.T, context spec.G, it spec.S) {
defer file.Close()

path = file.Name()
parser = main.NewGemfileParser()
parser = thin.NewGemfileParser()
})

it.After(func() {
Expand Down
2 changes: 1 addition & 1 deletion init_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main_test
package thin_test

import (
"testing"
Expand Down
11 changes: 6 additions & 5 deletions main.go → run/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (

"github.com/paketo-buildpacks/packit"
"github.com/paketo-buildpacks/packit/scribe"
"github.com/paketo-community/thin"
)

func main() {
parser := NewGemfileParser()
parser := thin.NewGemfileParser()
logger := scribe.NewLogger(os.Stdout)

detect := Detect(parser)
build := Build(logger)

packit.Run(detect, build)
packit.Run(
thin.Detect(parser),
thin.Build(logger),
)
}
22 changes: 22 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@ readonly BUILDPACKDIR="$(cd "${PROGDIR}/.." && pwd)"
function main() {
mkdir -p "${BUILDPACKDIR}/bin"

if [[ -f "${BUILDPACKDIR}/run/main.go" ]]; then
pushd "${BUILDPACKDIR}/bin" > /dev/null || return
printf "%s" "Building run..."

GOOS=linux \
go build \
-ldflags="-s -w" \
-o "run" \
"${BUILDPACKDIR}/run"

echo "Success!"

for name in detect build; do
printf "%s" "Linking ${name}..."

ln -sf "run" "${name}"

echo "Success!"
done
popd > /dev/null || return
fi

if [[ -f "${BUILDPACKDIR}/main.go" ]]; then
pushd "${BUILDPACKDIR}/bin" > /dev/null || return
printf "%s" "Building run..."
Expand Down

0 comments on commit 1a1799b

Please sign in to comment.