Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Test compatibility with Cloud SDK automatically #161

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions .github/workflows/dependency-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: Test SAP Cloud SDK Versions

on:
workflow_dispatch:
schedule:
- cron: 0 22 * * *
push:
branches:
- "workflow/compatibility-version"

env:
MVN_MULTI_THREADED_ARGS: --batch-mode --no-transfer-progress --fail-at-end --show-version --threads 1C
JAVA_VERSION: 17

jobs:
fetch-dependency-versions:
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.fetch-versions.outputs.VERSIONS }}

steps:
- name: Fetch versions from Maven Central
id: fetch-versions
run: |
# Specify the dependency coordinates
GROUP_ID="com.sap.cloud.sdk"
ARTIFACT_ID="sdk-bom"

# Fetch available versions from Maven Central API
response=$(curl -s "https://search.maven.org/solrsearch/select?q=g:%22${GROUP_ID}%22+AND+a:%22${ARTIFACT_ID}%22&rows=15&core=gav&wt=json")

# Extract and filter versions (e.g., to exclude snapshots or specific versions)
versions=$(echo "$response" | jq -r '.response.docs[].v' | grep -v -E 'SNAPSHOT|alpha|beta' | sort -V)

# Convert the versions to a JSON array
json_versions=$(echo "$versions" | jq -R . | jq -s . | tr -d '\n')

echo "JSON Versions: $json_versions"

# Output the versions as a string that can be used in the matrix
echo "VERSIONS=${json_versions}" >> $GITHUB_OUTPUT

setup-environment:
runs-on: ubuntu-latest
outputs:
cache-key: ${{ steps.cache-build.outputs.cache-key }}
steps:
- name: "Checkout repository"
uses: actions/checkout@v4

- name: "Setup java"
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: ${{ env.JAVA_VERSION }}
cache: 'maven'

- name: "Cache build"
id: cache-build
uses: actions/cache@v3
with:
path: |
~/.m2/repository
target
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-

- name: "Build SDK"
run: |
MVN_ARGS="${{ env.MVN_MULTI_THREADED_ARGS }} clean install -DskipTests -DskipFormatting"
mvn $MVN_ARGS

test-dependency-versions:
needs: [ fetch-dependency-versions, setup-environment ]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version: ${{ fromJson(needs.fetch-dependency-versions.outputs.versions) }}
continue-on-error: true
steps:
- name: "Checkout repository"
uses: actions/checkout@v4

- name: "Setup java"
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: ${{ env.JAVA_VERSION }}
cache: 'maven'

- name: "Restore build cache"
uses: actions/cache@v3
with:
path: |
~/.m2/repository
target
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}

- name: "Run tests with explicit version"
run: |
MVN_ARGS="${{ env.MVN_MULTI_THREADED_ARGS }} clean package -pl :spring-app -DskipTests=false -DskipFormatting -Dcloud-sdk.version=${{ matrix.version }} -Denforcer.skip=true -Dspotless.skip=true"
mvn $MVN_ARGS
env:
# See "End-to-end test application instructions" on the README.md to update the secret
AICORE_SERVICE_KEY: ${{ secrets.AICORE_SERVICE_KEY }}

- name: "Start Application Locally"
run: |
cd sample-code/spring-app
mvn spring-boot:run &
timeout=15
while ! nc -z localhost 8080; do
sleep 1
timeout=$((timeout - 1))
if [ $timeout -le 0 ]; then
echo "Server did not start within 15 seconds."
exit 1
fi
done
env:
# See "End-to-end test application instructions" on the README.md to update the secret
AICORE_SERVICE_KEY: ${{ secrets.AICORE_SERVICE_KEY }}

- name: "Health Check"
# print response body with headers to stdout. q:body only O:print -:stdout S:headers
run: wget -qO- -S localhost:8080
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@
<wiremock.version>3.9.2</wiremock.version>
<assertj-core.version>3.26.3</assertj-core.version>
<slf4j.version>2.0.16</slf4j.version>
<spotless.version>2.43.0</spotless.version>
<checkstyle.version>10.20.1</checkstyle.version>
<system-stubs.version>2.1.3</system-stubs.version>
<surefire.version>3.5.2</surefire.version>
<springframework.version>6.1.14</springframework.version>
<dotenv-java.version>3.0.2</dotenv-java.version>
<mockito.version>5.14.2</mockito.version>
<!-- Formatting -->
<spotless.version>2.43.0</spotless.version>
<spotless.skip>false</spotless.skip>
<!-- Quality assurance -->
<enforcer.skip>false</enforcer.skip>
<enforcer.skipBanLoggingFrameworks>false</enforcer.skipBanLoggingFrameworks>
<enforcer.skipEnforceScopeLoggerBridges>false</enforcer.skipEnforceScopeLoggerBridges>
<enforcer.skipEnforceScopeLombok>false</enforcer.skipEnforceScopeLombok>
Expand Down Expand Up @@ -213,6 +216,7 @@
<version>3.5.0</version>
<configuration>
<fail>true</fail>
<skip>${enforcer.skip}</skip>
</configuration>
<executions>
<execution>
Expand Down Expand Up @@ -394,6 +398,7 @@
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.version}</version>
<configuration>
<skip>${spotless.skip}</skip>
<java>
<!-- https://github.com/diffplug/spotless/tree/main/plugin-maven#java -->
<removeUnusedImports/>
Expand Down
Loading