|
| 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 |
0 commit comments