Skip to content

Commit

Permalink
Make Java Smoke Test PR workflow generic
Browse files Browse the repository at this point in the history
* so that it can be used for every Java samples
  • Loading branch information
anthonydahanne committed Sep 25, 2023
1 parent 413f419 commit 777e343
Show file tree
Hide file tree
Showing 22 changed files with 180 additions and 164 deletions.
29 changes: 0 additions & 29 deletions .github/workflows/test-pull-request-java-akka.yml

This file was deleted.

117 changes: 66 additions & 51 deletions .github/workflows/test-pull-request-java.yml
Original file line number Diff line number Diff line change
@@ -1,63 +1,78 @@
name: Test Pull Request (Java)
name: Smoke Test Pull Request (Java)

on:
merge_group:
pull_request:
branches:
- main
- main
paths:
- 'java/**'
- '!java/native-image/**'
- '!java/java-node/**'
- 'java/**'

jobs:
prepare:
name: Prepare
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.paths.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Discover changed paths
id: paths
run: |
env
# see: https://stackoverflow.com/a/8721550/24069 for usage of paste
changed_java_folders=$( git diff --name-only --merge-base origin/$GITHUB_BASE_REF $GITHUB_SHA | xargs -n 1 dirname | sort -k 2 | uniq | grep -v "^\." )
smoke_test_folders=""
while read -r changed_folder
do
echo "working on $changed_folder"
smoke_test=""
current_folder=$changed_folder
while [ -z "$smoke_test" ] && [ "$current_folder" != "." ]
do
echo "--smoke_test is $smoke_test"
echo "--current_folder is $current_folder"
if [[ -s $current_folder/smoke_test ]]; then
smoke_test="$current_folder/smoke_test"
else
current_folder=$(dirname $current_folder)
fi
done
if [ "$current_folder" != "." ]; then
smoke_test_folders="$smoke_test_folders\"$smoke_test\"\n"
fi
done <<<"$changed_java_folders"
smoke_test_folders=$( echo -e $smoke_test_folders | uniq | grep "\S" | paste -s -d, -)
echo "These are the Java folders where we found changes for this PR : $changed_java_folders" >> $GITHUB_STEP_SUMMARY
echo "These are the Java folders where we found changes AND the presence of smoke tests for this PR : $smoke_test_folders" >> $GITHUB_STEP_SUMMARY
echo "matrix={\"java_sample_folder\":[$smoke_test_folders]}" >> $GITHUB_OUTPUT
echo "This is how the matrix will look like: $(cat $GITHUB_OUTPUT)"
smoke:
needs: prepare
name: Smoke Tests
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJSON(needs.prepare.outputs.matrix) }}

steps:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.18.x

- name: Checkout
uses: actions/checkout@v4

- name: Cache local Gradle repository
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('java/**/*.gradle*', 'java/**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: |
~/.m2/repository
~/.m2/wrapper
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml', 'java/**/maven-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Setup Directories
run: |
#!/usr/bin/env bash
set -euo pipefail
mkdir -p ~/.m2/repository
mkdir -p ~/.m2/repository/wrapper/dists
mkdir -p ~/.gradle/caches
mkdir -p ~/.gradle/wrapper/dists
chmod -R 775 ~/.m2
chmod -R 775 ~/.gradle
- name: Test Java Samples
run: |
./scripts/smoke.sh --suite java \
--builder paketobuildpacks/builder:full \
--builder paketobuildpacks/builder:base \
--builder paketobuildpacks/builder:tiny
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x

- name: Checkout
uses: actions/checkout@v4

- name: Smoke Test Java samples
run: |
echo "About to run the smoke test script against this suite folder: ${{ matrix.java_sample_folder }}/smoke_test"
./scripts/smoke.sh --suite ${{ matrix.java_sample_folder }} \
--builder paketobuildpacks/builder:base \
--builder paketobuildpacks/builder:tiny
6 changes: 2 additions & 4 deletions java/akka/smoke_test/akka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func testAkkaWithBuilder(builder string) func(*testing.T, spec.G, spec.S) {

pack occam.Pack
docker occam.Docker
home string = os.Getenv("HOME")
)

it.Before(func() {
Expand Down Expand Up @@ -81,7 +80,7 @@ func testAkkaWithBuilder(builder string) func(*testing.T, spec.G, spec.S) {

err = docker.Image.Remove.Execute(image.ID)
if err != nil {
Expect(err.Error()).To(ContainSubstring("failed to remove docker image: exit status 1: Error"))
Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error")))
} else {
Expect(err).ToNot(HaveOccurred())
}
Expand All @@ -96,14 +95,13 @@ func testAkkaWithBuilder(builder string) func(*testing.T, spec.G, spec.S) {
}

var err error
source, err = occam.Source(filepath.Join("../../", "akka"))
source, err = occam.Source(filepath.Join("../"))
Expect(err).NotTo(HaveOccurred())

var logs fmt.Stringer
image, logs, err = pack.Build.
WithPullPolicy("never").
WithBuilder(builder).
WithVolumes(fmt.Sprintf("%s/.m2:/home/cnb/.m2:rw", home)).
WithGID("123").
Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func testApplicationInsightsWithBuilders(builder string) func(*testing.T, spec.G

pack occam.Pack
docker occam.Docker
home string = os.Getenv("HOME")
)

it.Before(func() {
Expand Down Expand Up @@ -80,7 +79,7 @@ func testApplicationInsightsWithBuilders(builder string) func(*testing.T, spec.G

err = docker.Image.Remove.Execute(image.ID)
if err != nil {
Expect(err).To(MatchError("failed to remove docker image: exit status 1: Error: No such image:"))
Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error")))
} else {
Expect(err).ToNot(HaveOccurred())
}
Expand All @@ -91,14 +90,13 @@ func testApplicationInsightsWithBuilders(builder string) func(*testing.T, spec.G
context("app uses application insights", func() {
it("builds successfully", func() {
var err error
source, err = occam.Source(filepath.Join("../java", "application-insights"))
source, err = occam.Source(filepath.Join("../"))
Expect(err).NotTo(HaveOccurred())

var logs fmt.Stringer
image, logs, err = pack.Build.
WithPullPolicy("never").
WithBuilder(builder).
WithVolumes(fmt.Sprintf("%s/.m2:/home/cnb/.m2:rw", home)).
WithGID("123").
Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)
Expand Down
15 changes: 10 additions & 5 deletions java/aspectj_test.go → java/aspectj/smoke_test/aspectj_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package java_test
package aspectj_test

import (
"flag"
"fmt"
"github.com/paketo-buildpacks/samples/tests"
"os"
"path/filepath"
"testing"
Expand All @@ -15,6 +17,11 @@ import (
. "github.com/paketo-buildpacks/occam/matchers"
)

var builders tests.BuilderFlags

func init() {
flag.Var(&builders, "name", "the name a builder to test with")
}
func TestAspectJ(t *testing.T) {
Expect := NewWithT(t).Expect

Expand All @@ -37,7 +44,6 @@ func testAspectJWithBuilder(builder string) func(*testing.T, spec.G, spec.S) {

pack occam.Pack
docker occam.Docker
home string = os.Getenv("HOME")
)

it.Before(func() {
Expand Down Expand Up @@ -72,7 +78,7 @@ func testAspectJWithBuilder(builder string) func(*testing.T, spec.G, spec.S) {

err = docker.Image.Remove.Execute(image.ID)
if err != nil {
Expect(err).To(MatchError("failed to remove docker image: exit status 1: Error: No such image:"))
Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error")))
} else {
Expect(err).ToNot(HaveOccurred())
}
Expand All @@ -83,14 +89,13 @@ func testAspectJWithBuilder(builder string) func(*testing.T, spec.G, spec.S) {
context("app uses aspectj", func() {
it("builds successfully", func() {
var err error
source, err = occam.Source(filepath.Join("../java", "aspectj"))
source, err = occam.Source(filepath.Join("../"))
Expect(err).NotTo(HaveOccurred())

var logs fmt.Stringer
image, logs, err = pack.Build.
WithPullPolicy("never").
WithBuilder(builder).
WithVolumes(fmt.Sprintf("%s/.m2:/home/cnb/.m2:rw", home)).
WithGID("123").
Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)
Expand Down
15 changes: 10 additions & 5 deletions java/deps_test.go → java/deps/smoke_test/deps_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package java_test
package deps_test

import (
"flag"
"fmt"
"github.com/paketo-buildpacks/samples/tests"
"os"
"path/filepath"
"testing"
Expand All @@ -15,6 +17,11 @@ import (
. "github.com/paketo-buildpacks/occam/matchers"
)

var builders tests.BuilderFlags

func init() {
flag.Var(&builders, "name", "the name a builder to test with")
}
func TestDeps(t *testing.T) {
Expect := NewWithT(t).Expect

Expand All @@ -37,7 +44,6 @@ func testDepsWithBuilder(builder string) func(*testing.T, spec.G, spec.S) {

pack occam.Pack
docker occam.Docker
home string = os.Getenv("HOME")
)

it.Before(func() {
Expand Down Expand Up @@ -72,7 +78,7 @@ func testDepsWithBuilder(builder string) func(*testing.T, spec.G, spec.S) {

err = docker.Image.Remove.Execute(image.ID)
if err != nil {
Expect(err).To(MatchError("failed to remove docker image: exit status 1: Error: No such image:"))
Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error")))
} else {
Expect(err).ToNot(HaveOccurred())
}
Expand All @@ -83,7 +89,7 @@ func testDepsWithBuilder(builder string) func(*testing.T, spec.G, spec.S) {
context("app uses clojure tools with deps", func() {
it("builds successfully", func() {
var err error
source, err = occam.Source(filepath.Join("../java", "deps"))
source, err = occam.Source(filepath.Join("../"))
Expect(err).NotTo(HaveOccurred())

var logs fmt.Stringer
Expand All @@ -93,7 +99,6 @@ func testDepsWithBuilder(builder string) func(*testing.T, spec.G, spec.S) {
"JAVA_TOOL_OPTIONS": "-XX:MaxMetaspaceSize=100M",
}).
WithBuilder(builder).
WithVolumes(fmt.Sprintf("%s/.m2:/home/cnb/.m2:rw", home)).
WithGID("123").
Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package java_test
package dist_zip_test

import (
"flag"
"fmt"
"github.com/paketo-buildpacks/samples/tests"
"os"
"path/filepath"
"strings"
Expand All @@ -16,6 +18,11 @@ import (
. "github.com/paketo-buildpacks/occam/matchers"
)

var builders tests.BuilderFlags

func init() {
flag.Var(&builders, "name", "the name a builder to test with")
}
func TestDistZip(t *testing.T) {
Expect := NewWithT(t).Expect

Expand All @@ -38,7 +45,6 @@ func testDistZipWithBuilder(builder string) func(*testing.T, spec.G, spec.S) {

pack occam.Pack
docker occam.Docker
home string = os.Getenv("HOME")
)

it.Before(func() {
Expand Down Expand Up @@ -73,7 +79,7 @@ func testDistZipWithBuilder(builder string) func(*testing.T, spec.G, spec.S) {

err = docker.Image.Remove.Execute(image.ID)
if err != nil {
Expect(err).To(MatchError("failed to remove docker image: exit status 1: Error: No such image:"))
Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error")))
} else {
Expect(err).ToNot(HaveOccurred())
}
Expand All @@ -88,7 +94,7 @@ func testDistZipWithBuilder(builder string) func(*testing.T, spec.G, spec.S) {
}

var err error
source, err = occam.Source(filepath.Join("../java", "dist-zip"))
source, err = occam.Source(filepath.Join("../"))
Expect(err).NotTo(HaveOccurred())

var logs fmt.Stringer
Expand All @@ -99,7 +105,6 @@ func testDistZipWithBuilder(builder string) func(*testing.T, spec.G, spec.S) {
"BP_GRADLE_BUILD_ARGUMENTS": "--no-daemon -x test bootDistZip",
"BP_GRADLE_BUILT_ARTIFACT": "build/distributions/*.zip"}).
WithBuilder(builder).
WithVolumes(fmt.Sprintf("%s/.gradle:/home/cnb/.gradle:rw", home)).
WithGID("123").
Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)
Expand Down
Loading

0 comments on commit 777e343

Please sign in to comment.