Skip to content

Commit

Permalink
Only test and scan current TP for K8s samples
Browse files Browse the repository at this point in the history
  • Loading branch information
trisberg committed Sep 12, 2024
1 parent 7c0419c commit f78f2d6
Show file tree
Hide file tree
Showing 108 changed files with 207 additions and 1 deletion.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions .github/tests-og/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
set -euo pipefail

rm -fr /tmp/result
mkdir /tmp/result

[[ $1 =~ (.*)-.* ]]
accname=${BASH_REMATCH[1]}

WORKSPACE="${TEST_WORKSPACE:-$GITHUB_WORKSPACE}"

echo WORKSPACE=$WORKSPACE
pushd ${WORKSPACE}

CMD="${TANZU_CLI:-.github/tests/tanzu-accelerator-linux_amd64}"
PLUGIN="${CLI_PLUGIN:-}"

SERVER_URL="${ACC_SERVER_URL:-http://localhost:8888}"
echo SERVER_URL=$SERVER_URL

${CMD} ${PLUGIN} generate-from-local \
--server-url $SERVER_URL \
--output-dir /tmp/result \
--fragment-paths devcontainer=fragments/devcontainer \
--fragment-paths app-sso-client=fragments/app-sso-client \
--fragment-paths java-version=fragments/java-version \
--fragment-paths live-update=fragments/live-update \
--fragment-paths java-version=fragments/java-version \
--fragment-paths spring-boot-app-sso-auth-code-flow=fragments/spring-boot-app-sso-auth-code-flow \
--fragment-paths spring-boot-database=fragments/spring-boot-database \
--fragment-paths spring-boot-h2=fragments/spring-boot-h2 \
--fragment-paths spring-boot-mysql=fragments/spring-boot-mysql \
--fragment-paths spring-boot-postgresql=fragments/spring-boot-postgresql \
--fragment-paths steeltoe-postgresql=fragments/steeltoe-postgresql \
--fragment-paths testcontainers-mysql=fragments/testcontainers-mysql \
--fragment-paths testcontainers-postgresql=fragments/testcontainers-postgresql \
--fragment-paths tap-initialize=fragments/tap-initialize \
--fragment-paths tap-workload=fragments/tap-workload \
--fragment-paths build-wrapper-maven=fragments/build-wrapper-maven \
--fragment-paths build-wrapper-gradle=fragments/build-wrapper-gradle \
--accelerator-path ${accname}=${accname} \
$([ -f .github/tests/$1/options.json ] && echo --options-file .github/tests/$1/options.json)

popd
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions .github/tests-og/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -euo pipefail

[[ $1 =~ (.*)-.* ]]

WORKSPACE="${TEST_WORKSPACE:-$GITHUB_WORKSPACE}"
pushd ${WORKSPACE}/.github/tests/$1

[ -f assertions.sh ] && ./assertions.sh /tmp/result

popd
11 changes: 11 additions & 0 deletions .github/tests-og/scan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -euo pipefail

[[ $1 =~ (.*)-.* ]]
grype_location=$2

pushd ${GITHUB_WORKSPACE}/.github/tests/$1

[ -f scan.sh ] && ./scan.sh /tmp/result $grype_location

popd
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
87 changes: 87 additions & 0 deletions .github/tests-og/testFunctions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash

# Assert that the file exists
assertFileExists()
{
if ! [ -f $1 ]; then
echo "$1 DOES NOT exist"
exit 1
fi
}

# Assert that a file does NOT exist
assertFileDoesntExist()
{
if [ -f $1 ]; then
echo "$1 SHOULD NOT exist"
exit 1
fi
}

# Assert that a directory does NOT exist
assertDirDoesntExist()
{
if [ -d $1 ]; then
echo "$1 SHOULD NOT exist"
exit 1
fi
}

# Assert that a file contains some string
assertFileContains()
{
if ! grep -Fq "$2" $1; then
echo "$1 DOES NOT contain \"$2\""
exit 1
fi
}

# Assert that a file DOES NOT contain some string
assertFileDoesntContain()
{
if grep -Fq "$2" $1; then
echo "$1 SHOULD NOT contain \"$2\""
exit 1
fi
}

# Assert project's groupId and artifactId
assertPomHasProjectCoordinates()
{
DEPTEST="//project[groupId=\"$2\"][artifactId=\"$3\"]"
DEPRESULT=`xpath -e $DEPTEST -q $1 2>/dev/null`
if [ ${#DEPRESULT} -eq "0" ]; then
echo "$1 does not have project coordinates \"$2:$3\""
exit 1
fi
}

# Assert that the pom has a given dependency
assertPomHasDependency()
{
DEPTEST="//project/dependencies/dependency[groupId=\"$2\"][artifactId=\"$3\"]"
if [ $# -gt 3 ]; then
DEPTEST="$DEPTEST[version=\"$4\"]"
fi

DEPRESULT=`xpath -e $DEPTEST -q $1 2>/dev/null`
if [ ${#DEPRESULT} -eq "0" ]; then
echo "$1 does not contain dependency \"$2:$3:$4\""
exit 1
fi
}

# Assert that the pom DOES NOT have a given dependency
assertPomDoesntHaveDependency()
{
DEPTEST="//project/dependencies/dependency[groupId=\"$2\"][artifactId=\"$3\"]"
if [ $# -gt 3 ]; then
DEPTEST="$DEPTEST[version=\"$4\"]"
fi

DEPRESULT=`xpath -e $DEPTEST -q $1 2>/dev/null`
if ! [ ${#DEPRESULT} -eq "0" ]; then
echo "$1 does not contain dependency \"$2:$3:$4\""
exit 1
fi
}
File renamed without changes.
18 changes: 18 additions & 0 deletions .github/tests/tanzu-java-web-app-gradle_java21/assertions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -euo pipefail

pushd $1

if [ -f pom.xml ]; then
echo "FAIL: Found pom.xml file!"
exit 5
fi

if ! grep -q 'JavaVersion.VERSION_21' build.gradle.kts; then
echo "Couldn't find Java version 21"
exit 2
fi

./gradlew build

popd
6 changes: 6 additions & 0 deletions .github/tests/tanzu-java-web-app-gradle_java21/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"projectName": "tanzu-java-web-app",
"buildTool": "gradle",
"javaVersion": "21",
"includeBuildToolWrapper": true
}
13 changes: 13 additions & 0 deletions .github/tests/tanzu-java-web-app-mvn_java17/assertions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -euxo pipefail

pushd $1

if ls | grep -q gradle; then
echo "FAIL: There are gradle related files present."
exit 1
fi

./mvnw package

popd
6 changes: 6 additions & 0 deletions .github/tests/tanzu-java-web-app-mvn_java17/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"projectName": "tanzu-java-web-app",
"buildTool": "maven",
"javaVersion": "17",
"includeBuildToolWrapper": true
}
10 changes: 10 additions & 0 deletions .github/tests/tanzu-java-web-app-mvn_java17/scan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -euxo pipefail

pushd $1
grype=$2

./mvnw package
$grype target/demo-0.0.1-SNAPSHOT.jar --fail-on high --config ${GITHUB_WORKSPACE}/.github/tests/.grype.yaml

popd
2 changes: 1 addition & 1 deletion .github/workflows/scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Download Grype
uses: anchore/scan-action/download-grype@v3
with:
grype-version: v0.72.0
grype-version: v0.80.1
id: grype
- name: Generate ${{matrix.test}}
run: .github/tests/generate.sh ${{matrix.test}}
Expand Down

0 comments on commit f78f2d6

Please sign in to comment.