Skip to content

Commit a9be1ed

Browse files
newtorka-d
andauthored
[Ops] Test compatibility with Cloud SDK automatically (#161)
* Initial * Update dependency-test.yaml --------- Co-authored-by: Alexander Dümont <[email protected]>
1 parent 31c2ac3 commit a9be1ed

File tree

2 files changed

+130
-1
lines changed

2 files changed

+130
-1
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Test SAP Cloud SDK Versions
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
MVN_MULTI_THREADED_ARGS: --batch-mode --no-transfer-progress --fail-at-end --show-version --threads 1C
8+
JAVA_VERSION: 17
9+
10+
jobs:
11+
fetch-dependency-versions:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
versions: ${{ steps.fetch-versions.outputs.VERSIONS }}
15+
16+
steps:
17+
- name: Fetch versions from Maven Central
18+
id: fetch-versions
19+
run: |
20+
# Specify the dependency coordinates
21+
GROUP_ID="com.sap.cloud.sdk"
22+
ARTIFACT_ID="sdk-bom"
23+
24+
# Fetch available versions from Maven Central API
25+
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")
26+
27+
# Extract and filter versions (e.g., to exclude snapshots or specific versions)
28+
versions=$(echo "$response" | jq -r '.response.docs[].v' | grep -v -E 'SNAPSHOT|alpha|beta' | sort -V)
29+
30+
# Convert the versions to a JSON array
31+
json_versions=$(echo "$versions" | jq -R . | jq -s . | tr -d '\n')
32+
33+
echo "JSON Versions: $json_versions"
34+
35+
# Output the versions as a string that can be used in the matrix
36+
echo "VERSIONS=${json_versions}" >> $GITHUB_OUTPUT
37+
38+
setup-environment:
39+
runs-on: ubuntu-latest
40+
outputs:
41+
cache-key: ${{ steps.cache-build.outputs.cache-key }}
42+
steps:
43+
- name: "Checkout repository"
44+
uses: actions/checkout@v4
45+
46+
- name: "Setup java"
47+
uses: actions/setup-java@v4
48+
with:
49+
distribution: "temurin"
50+
java-version: ${{ env.JAVA_VERSION }}
51+
cache: 'maven'
52+
53+
- name: "Cache build"
54+
id: cache-build
55+
uses: actions/cache@v3
56+
with:
57+
path: |
58+
~/.m2/repository
59+
target
60+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
61+
restore-keys: |
62+
${{ runner.os }}-maven-
63+
64+
- name: "Build SDK"
65+
run: |
66+
MVN_ARGS="${{ env.MVN_MULTI_THREADED_ARGS }} clean install -DskipTests -DskipFormatting"
67+
mvn $MVN_ARGS
68+
69+
test-dependency-versions:
70+
needs: [ fetch-dependency-versions, setup-environment ]
71+
runs-on: ubuntu-latest
72+
strategy:
73+
max-parallel: 1
74+
fail-fast: false
75+
matrix:
76+
version: ${{ fromJson(needs.fetch-dependency-versions.outputs.versions) }}
77+
continue-on-error: true
78+
steps:
79+
- name: "Checkout repository"
80+
uses: actions/checkout@v4
81+
82+
- name: "Setup java"
83+
uses: actions/setup-java@v4
84+
with:
85+
distribution: "temurin"
86+
java-version: ${{ env.JAVA_VERSION }}
87+
cache: 'maven'
88+
89+
- name: "Restore build cache"
90+
uses: actions/cache@v3
91+
with:
92+
path: |
93+
~/.m2/repository
94+
target
95+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
96+
97+
- name: "Run tests with explicit version"
98+
run: |
99+
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"
100+
mvn $MVN_ARGS
101+
env:
102+
# See "End-to-end test application instructions" on the README.md to update the secret
103+
AICORE_SERVICE_KEY: ${{ secrets.AICORE_SERVICE_KEY }}
104+
105+
- name: "Start Application Locally"
106+
run: |
107+
cd sample-code/spring-app
108+
mvn spring-boot:run &
109+
timeout=15
110+
while ! nc -z localhost 8080; do
111+
sleep 1
112+
timeout=$((timeout - 1))
113+
if [ $timeout -le 0 ]; then
114+
echo "Server did not start within 15 seconds."
115+
exit 1
116+
fi
117+
done
118+
env:
119+
# See "End-to-end test application instructions" on the README.md to update the secret
120+
AICORE_SERVICE_KEY: ${{ secrets.AICORE_SERVICE_KEY }}
121+
122+
- name: "Health Check"
123+
# print response body with headers to stdout. q:body only O:print -:stdout S:headers
124+
run: wget -qO- -S localhost:8080

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,17 @@
6060
<wiremock.version>3.9.2</wiremock.version>
6161
<assertj-core.version>3.26.3</assertj-core.version>
6262
<slf4j.version>2.0.16</slf4j.version>
63-
<spotless.version>2.43.0</spotless.version>
6463
<checkstyle.version>10.20.1</checkstyle.version>
6564
<system-stubs.version>2.1.3</system-stubs.version>
6665
<surefire.version>3.5.2</surefire.version>
6766
<springframework.version>6.2.0</springframework.version>
6867
<dotenv-java.version>3.0.2</dotenv-java.version>
6968
<mockito.version>5.14.2</mockito.version>
69+
<!-- Formatting -->
70+
<spotless.version>2.43.0</spotless.version>
71+
<spotless.skip>false</spotless.skip>
7072
<!-- Quality assurance -->
73+
<enforcer.skip>false</enforcer.skip>
7174
<enforcer.skipBanLoggingFrameworks>false</enforcer.skipBanLoggingFrameworks>
7275
<enforcer.skipEnforceScopeLoggerBridges>false</enforcer.skipEnforceScopeLoggerBridges>
7376
<enforcer.skipEnforceScopeLombok>false</enforcer.skipEnforceScopeLombok>
@@ -213,6 +216,7 @@
213216
<version>3.5.0</version>
214217
<configuration>
215218
<fail>true</fail>
219+
<skip>${enforcer.skip}</skip>
216220
</configuration>
217221
<executions>
218222
<execution>
@@ -394,6 +398,7 @@
394398
<artifactId>spotless-maven-plugin</artifactId>
395399
<version>${spotless.version}</version>
396400
<configuration>
401+
<skip>${spotless.skip}</skip>
397402
<java>
398403
<!-- https://github.com/diffplug/spotless/tree/main/plugin-maven#java -->
399404
<removeUnusedImports/>

0 commit comments

Comments
 (0)