|
| 1 | +name: Test SAP Cloud SDK Versions |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + - cron: 0 22 * * * |
| 7 | + |
| 8 | +env: |
| 9 | + MVN_MULTI_THREADED_ARGS: --batch-mode --no-transfer-progress --fail-at-end --show-version --threads 1C |
| 10 | + JAVA_VERSION: 17 |
| 11 | + |
| 12 | +jobs: |
| 13 | + fetch-dependency-versions: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + versions: ${{ steps.set-versions.outputs.versions }} |
| 17 | + |
| 18 | + steps: |
| 19 | + |
| 20 | + - name: Fetch versions from Maven Central |
| 21 | + id: fetch-versions |
| 22 | + run: | |
| 23 | + # Specify the dependency coordinates |
| 24 | + GROUP_ID="com.example" |
| 25 | + ARTIFACT_ID="my-dependency" |
| 26 | +
|
| 27 | + # Fetch available versions from Maven Central API |
| 28 | + 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") |
| 29 | + |
| 30 | + # Extract and filter versions (e.g., to exclude snapshots or specific versions) |
| 31 | + versions=$(echo "$response" | jq -r '.response.docs[].v' | grep -v -E 'SNAPSHOT|alpha|beta' | sort -V) |
| 32 | + |
| 33 | + # Convert the versions to a JSON array |
| 34 | + json_versions=$(echo "$versions" | jq -R . | jq -s .) |
| 35 | + |
| 36 | + # Output the versions as a string that can be used in the matrix |
| 37 | + echo "::set-output name=versions::${json_versions}" |
| 38 | +
|
| 39 | + test-dependency-versions: |
| 40 | + needs: fetch-dependency-versions |
| 41 | + runs-on: ubuntu-latest |
| 42 | + strategy: |
| 43 | + matrix: |
| 44 | + version: ${{ fromJson(needs.fetch-dependency-versions.outputs.versions) }} |
| 45 | + steps: |
| 46 | + - name: "Checkout repository" |
| 47 | + uses: actions/checkout@v4 |
| 48 | + |
| 49 | + - name: "Setup java" |
| 50 | + uses: actions/setup-java@v4 |
| 51 | + with: |
| 52 | + distribution: "temurin" |
| 53 | + java-version: ${{ env.JAVA_VERSION }} |
| 54 | + cache: 'maven' |
| 55 | + |
| 56 | + - name: "Build SDK" |
| 57 | + run: | |
| 58 | + MVN_ARGS="${{ env.MVN_MULTI_THREADED_ARGS }} clean install -DskipTests -DskipFormatting" |
| 59 | + mvn $MVN_ARGS |
| 60 | +
|
| 61 | + - name: "Run tests with explicit version" |
| 62 | + run: | |
| 63 | + MVN_ARGS="${{ env.MVN_MULTI_THREADED_ARGS }} clean package spring-boot:run -pl :spring-app -Dcloud-sdk.version=${{ matrix.version }} -Denforcer.skip=true" |
| 64 | + mvn $MVN_ARGS |
| 65 | + env: |
| 66 | + # See "End-to-end test application instructions" on the README.md to update the secret |
| 67 | + AICORE_SERVICE_KEY: ${{ secrets.AICORE_SERVICE_KEY }} |
| 68 | + |
| 69 | + - name: "Start Application Locally" |
| 70 | + run: | |
| 71 | + cd sample-code/spring-app |
| 72 | + mvn spring-boot:run & |
| 73 | + timeout=15 |
| 74 | + while ! nc -z localhost 8080; do |
| 75 | + sleep 1 |
| 76 | + timeout=$((timeout - 1)) |
| 77 | + if [ $timeout -le 0 ]; then |
| 78 | + echo "Server did not start within 15 seconds." |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | + done |
| 82 | + env: |
| 83 | + # See "End-to-end test application instructions" on the README.md to update the secret |
| 84 | + AICORE_SERVICE_KEY: ${{ secrets.AICORE_SERVICE_KEY }} |
| 85 | + |
| 86 | + - name: "Health Check" |
| 87 | + # print response body with headers to stdout. q:body only O:print -:stdout S:headers |
| 88 | + run: wget -qO- -S localhost:8080 |
0 commit comments