Added proper test-summary #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Integration Tests for Metastore | |
on: | |
push: | |
branches: | |
- alpha | |
- beta | |
- development | |
- master | |
- lineageondemand | |
- makerlogic | |
- mlh41-integration-tests | |
jobs: | |
wait-for-deployment: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get commit ID | |
run: echo "COMMIT_ID=$(echo ${GITHUB_SHA} | cut -c1-7)" >> $GITHUB_ENV | |
- name: Wait for Matching Revision | |
run: | | |
MAX_RETRIES=30 # Set maximum number of retries | |
SLEEP_TIME=30 # Time in seconds between retries | |
for i in $(seq 1 $MAX_RETRIES); do | |
echo "Attempt $i: Checking API for matching commit ID..." | |
REVISION=$(curl --silent --location 'https://gcpotel.atlan.com/api/meta/admin/version' \ | |
--header "Authorization: Bearer $(curl --silent --location 'https://gcpotel.atlan.com/auth/realms/default/protocol/openid-connect/token' \ | |
--header 'Content-Type: application/x-www-form-urlencoded' \ | |
--data-urlencode 'client_id=atlan-argo' \ | |
--data-urlencode 'grant_type=client_credentials' \ | |
--data-urlencode "client_secret=${{ secrets.ATLAN_ARGO_CLIENT_SECRET }}" | jq -r '.access_token')" | jq -r '.Revision' | cut -c1-7) | |
echo "Fetched Revision: $REVISION" | |
echo "Expected Commit ID: $COMMIT_ID" | |
if [[ "$REVISION" == "$COMMIT_ID" ]]; then | |
echo "✅ Revision matches commit ID! Proceeding to the next step..." | |
exit 0 | |
fi | |
echo "🔄 No match yet. Retrying in $SLEEP_TIME seconds..." | |
sleep $SLEEP_TIME | |
done | |
echo "❌ ERROR: Max retries reached. Commit ID did not match the revision." | |
exit 1 | |
setup-java-sdk: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Java SDK Repo | |
uses: actions/checkout@v4 | |
with: | |
repository: atlanhq/atlan-java | |
ref: main | |
- name: Set up JDK for SDK | |
uses: actions/setup-java@v4 | |
with: | |
java-version: 17 | |
distribution: temurin | |
- name: Compile | |
uses: burrunan/gradle-cache-action@v1 | |
with: | |
arguments: assemble shadowJar test | |
list-integration-tests: | |
runs-on: ubuntu-latest | |
outputs: | |
tests: ${{ steps.test-files.outputs.tests }} | |
steps: | |
- name: Checkout Java SDK Repo | |
uses: actions/checkout@v4 | |
with: | |
repository: atlanhq/atlan-java | |
ref: main | |
- name: List integration tests | |
id: test-files | |
run: | | |
tests=$(ls integration-tests/src/test/java/com/atlan/java/sdk/*Test.java | sed -E 's|.*/src/test/java/com/atlan/java/sdk/||; s|/|.|g; s|\.java$||' | tr '\n' ' ') | |
json_tests=$(echo "$tests[@]}" | jq -R -c 'split(" ")[:-1]') | |
echo "tests=$json_tests" >> $GITHUB_OUTPUT | |
integration-test: | |
needs: | |
- wait-for-deployment | |
- setup-java-sdk | |
- list-integration-tests | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
tests: ${{ fromJson(needs.list-integration-tests.outputs.tests) }} | |
concurrency: | |
group: ${{ matrix.tests }} | |
name: "Integration" | |
steps: | |
- name: Checkout Java SDK Repo | |
uses: actions/checkout@v4 | |
with: | |
repository: atlanhq/atlan-java | |
ref: main | |
- name: Set up JDK | |
uses: actions/setup-java@v4 | |
with: | |
java-version: 17 | |
distribution: temurin | |
- name: Run integration test for ${{ matrix.tests }} | |
run: | | |
# Run ONLY the test class for this matrix entry | |
./gradlew -PintegrationTests integration-tests:test \ | |
--tests "com.atlan.java.sdk.${{ matrix.tests }}" \ | |
--rerun-tasks | |
env: | |
ATLAN_BASE_URL: "https://gcpotel.atlan.com/" | |
ATLAN_API_KEY: ${{ secrets.TENANT_API_KEY }} | |
- name: Move JUnit XML results | |
# Move them into a test-specific folder so that multiple matrix jobs don't overwrite each other's results. | |
run: | | |
mkdir -p integration-tests/build/test-results/${{ matrix.tests }} | |
mv integration-tests/build/test-results/test/* integration-tests/build/test-results/${{ matrix.tests }} || true | |
- name: Upload JUnit test results | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.tests }}-junit-results | |
path: integration-tests/build/test-results/${{ matrix.tests }} | |
report-test-results: | |
needs: integration-test | |
if: always() # Run this even if tests fail | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download Test Results | |
uses: actions/download-artifact@v4 | |
with: | |
# This will download all artifacts, including each test's folder | |
path: test-results | |
- name: Summarize JUnit XML | |
id: summary | |
run: | | |
echo "### Integration Test Results" > test-summary.md | |
echo "" >> test-summary.md | |
all_passed=true | |
total_failures=0 | |
# Each matrix test has its own subfolder named "...-junit-results", | |
# but the download-artifact step will default to putting each artifact in a directory. | |
# For example: test-results/PersonaTest-junit-results/ (with *.xml inside). | |
# Find all JUnit XML files under test-results/ | |
while IFS= read -r -d '' xmlfile; do | |
# We'll parse "failures" and "tests" attributes from each <testsuite> in the XML. | |
# If you have multiple <testsuite> elements, we sum them up. | |
# This quick grep-based approach is enough, but for more robust parsing, consider using xmllint or a test-report action. | |
# Extract numeric sums for failures in this file | |
file_failures=$(grep -Po 'failures="\K\d+' "$xmlfile" | paste -sd+ - | bc) | |
[[ -z "$file_failures" ]] && file_failures=0 | |
# If any failures > 0, we note them | |
if [ "$file_failures" -gt 0 ]; then | |
echo "❌ Failures found in: $xmlfile ($file_failures failures)" >> test-summary.md | |
all_passed=false | |
total_failures=$((total_failures + file_failures)) | |
else | |
echo "✅ No failures in: $xmlfile" >> test-summary.md | |
fi | |
done < <(find test-results -name '*.xml' -print0) | |
if [ "$all_passed" = true ]; then | |
echo "" >> test-summary.md | |
echo "✅ **All integration tests passed!** Ready to merge. 🚀" >> test-summary.md | |
echo "ALL_TESTS_PASSED=true" >> $GITHUB_ENV | |
else | |
echo "" >> test-summary.md | |
echo "❌ **Some tests failed.** Total failures: $total_failures" >> test-summary.md | |
echo "ALL_TESTS_PASSED=false" >> $GITHUB_ENV | |
fi | |
- name: Output Test Summary to Logs | |
run: | | |
echo "--------------------------------------------------" | |
echo "✅ Printing the test summary before posting to PR" | |
echo "--------------------------------------------------" | |
cat test-summary.md | |
- name: Post Comment on PR | |
uses: mshick/add-pr-comment@v2 | |
if: github.event_name == 'pull_request' | |
with: | |
message-path: test-summary.md | |
repo-token: ${{ secrets.GITHUB_TOKEN }} |