Skip to content

Commit

Permalink
Merge pull request #1719 from paketo-buildpacks/add-new-tests
Browse files Browse the repository at this point in the history
* Run the integration tests with make
  • Loading branch information
anthonydahanne authored Sep 21, 2024
2 parents e235784 + b175e59 commit 8c414b1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
1 change: 1 addition & 0 deletions octo/octo.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
const (
CraneVersion = "0.19.1"
GoVersion = "1.23"
JavaVersion = "17"
PackVersion = "0.34.2"
BuildpackActionsVersion = "5.7.2"
RichGoVersion = "0.3.10"
Expand Down
5 changes: 5 additions & 0 deletions octo/run-integration-tests-composites.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -euo pipefail

BP_UNDER_TEST=ttl.sh/${PACKAGE}-${VERSION}:1h make integration
2 changes: 1 addition & 1 deletion octo/statik/statik.go

Large diffs are not rendered by default.

49 changes: 39 additions & 10 deletions octo/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,22 @@ func ContributeTest(descriptor Descriptor) (*Contribution, error) {
Jobs: map[string]actions.Job{},
}

goFiles, err := Find(descriptor.Path, regexp.MustCompile(`.+\.go`).MatchString)
goFilesButNoIntegrationTests, err := Find(descriptor.Path, isGoFileButNotInIntegrationFolder)
if err != nil {
return nil, fmt.Errorf("unable to Find .go files in %s\n%w", descriptor.Path, err)
}

var integrationTestsWithMake []string
integrationTestFiles, err := Find(descriptor.Path, regexp.MustCompile(`integration/.+\.go`).MatchString)
if err != nil {
return nil, fmt.Errorf("unable to Find .go files in %s\n%w", filepath.Join(descriptor.Path, "integration"), err)
} else {
integrationTestsWithMake, err = Find(descriptor.Path, regexp.MustCompile(`Makefile`).MatchString)
if err != nil {
return nil, fmt.Errorf("unable to Find Makefile in %s\n%w", descriptor.Path, err)
}
}

if len(goFiles) > 0 {
if len(goFilesButNoIntegrationTests) > 0 {
j := actions.Job{
Name: "Unit Test",
RunsOn: []actions.VirtualEnvironment{actions.UbuntuLatest},
Expand Down Expand Up @@ -217,6 +222,11 @@ func ContributeTest(descriptor Descriptor) (*Contribution, error) {
}

if len(integrationTestFiles) > 0 {
integrationTestsScript := "/run-integration-tests.sh"
if len(integrationTestsWithMake) > 0 {
integrationTestsScript = "/run-integration-tests-composites.sh"
}

j.Steps = append(j.Steps,
actions.Step{
Name: "Package Buildpack",
Expand All @@ -227,15 +237,27 @@ func ContributeTest(descriptor Descriptor) (*Contribution, error) {
"VERSION": "1h",
"TTL_SH_PUBLISH": "true",
},
},
actions.Step{
Name: "Run Integration Tests",
Run: StatikString("/run-integration-tests.sh"),
Env: map[string]string{
"PACKAGE": "test",
"VERSION": "${{ steps.version.outputs.version }}",
})

if len(integrationTestsWithMake) > 0 {
j.Steps = append(j.Steps, actions.Step{
Name: "Set up JDK",
Uses: "actions/setup-java@v5",
With: map[string]interface{}{
"java-version": JavaVersion,
"distribution": "liberica",
},
})
}

j.Steps = append(j.Steps, actions.Step{
Name: "Run Integration Tests",
Run: StatikString(integrationTestsScript),
Env: map[string]string{
"PACKAGE": "test",
"VERSION": "${{ steps.version.outputs.version }}",
},
})
} else {
j.Steps = append(j.Steps,
actions.Step{
Expand Down Expand Up @@ -281,3 +303,10 @@ func ContributeTest(descriptor Descriptor) (*Contribution, error) {

return &c, nil
}

func isGoFileButNotInIntegrationFolder(path string) bool {
if regexp.MustCompile(`\.go$`).MatchString(path) && !regexp.MustCompile(`^.*integration/`).MatchString(path) {
return true
}
return false
}

0 comments on commit 8c414b1

Please sign in to comment.