diff --git a/.github/workflows/server-build.yml b/.github/workflows/server-build.yml index fc41d7b9b0..89202df576 100644 --- a/.github/workflows/server-build.yml +++ b/.github/workflows/server-build.yml @@ -73,16 +73,37 @@ jobs: # In case this is second attempt try restoring status of the prior attempt from cache - name: Restore the previous run result + id: cache-appsmith uses: actions/cache@v3 with: path: | ~/run_result - key: ${{ github.run_id }}-${{ github.job }}-server + key: ${{ github.run_id }}-${{ github.job }}-server-junit # Fetch prior run result - name: Get the previous run result id: run_result - run: cat ~/run_result 2>/dev/null || echo 'default' + run: | + if [ -f ~/run_result ]; then + echo "run_result=$(cat ~/run_result)" >> $GITHUB_OUTPUT + else + echo "run_result=default" >> $GITHUB_OUTPUT + fi + + - name: Download the failed test artifact in case of rerun + if: steps.run_result.outputs.run_result == 'failedtest' + uses: actions/download-artifact@v3 + with: + name: failed-server-tests + path: ~/failed-server-tests + + - name: Extract the tests for rerun + id: failed_tests + if: steps.run_result.outputs.run_result == 'failedtest' + run: | + failed_tests=$(awk '$0 != "" && !seen[$0]++ {printf("%s%s",sep,$0); sep=","}' ~/failed-server-tests/failed-server-tests.txt) + echo "$failed_tests" + echo "tests=$failed_tests" >> $GITHUB_OUTPUT # In case of prior failure run the job - if: steps.run_result.outputs.run_result != 'success' @@ -125,8 +146,8 @@ jobs: echo version=$next_version-SNAPSHOT >> $GITHUB_OUTPUT echo tag=$(echo ${GITHUB_REF:11}) >> $GITHUB_OUTPUT - # Build and test the code - - name: Build and test + # Build the code + - name: Build if: steps.run_result.outputs.run_result != 'success' env: ACTIVE_PROFILE: test @@ -140,16 +161,50 @@ jobs: APPSMITH_ENVFILE_PATH: /tmp/dummy.env APPSMITH_VERBOSE_LOGGING_ENABLED: false run: | - if [[ "${{ inputs.skip-tests }}" == "true" ]] - then - args=-DskipTests - fi mvn --batch-mode versions:set \ -DnewVersion=${{ steps.vars.outputs.version }} \ -DgenerateBackupPoms=false \ -DprocessAllModules=true - args="$args -DtestResultFile=$PWD/failed-server-tests.txt" - ./build.sh $args + ./build.sh -DskipTests + + # Test the code + - name: Run only tests + if: inputs.skip-tests != 'true' || steps.run_result.outputs.run_result == 'failedtest' + env: + ACTIVE_PROFILE: test + APPSMITH_MONGODB_URI: "mongodb://localhost:27017/mobtools" + APPSMITH_CLOUD_SERVICES_BASE_URL: "https://release-cs.appsmith.com" + APPSMITH_CLOUD_SERVICES_TEMPLATE_UPLOAD_AUTH: ${{ secrets.APPSMITH_CLOUD_SERVICES_TEMPLATE_UPLOAD_AUTH }} + APPSMITH_REDIS_URL: "redis://127.0.0.1:6379" + APPSMITH_ENCRYPTION_PASSWORD: "password" + APPSMITH_ENCRYPTION_SALT: "salt" + APPSMITH_IS_SELF_HOSTED: false + APPSMITH_ENVFILE_PATH: /tmp/dummy.env + APPSMITH_VERBOSE_LOGGING_ENABLED: false + run: | + args=() + if [[ "${{ steps.run_result.outputs.run_result }}" == "failedtest" ]]; then + failed_tests="${{ steps.failed_tests.outputs.tests }}" + args+=("-DfailIfNoTests=false" "-Dtest=${failed_tests}") + fi + args+=("-DtestResultFile=$PWD/failed-server-tests.txt") + mvn test "${args[@]}" + + # Set status = failedtest + - name: Set fail if there are test failures + if: failure() + run: | + echo "run_result=failedtest" >> $GITHUB_OUTPUT + echo "failedtest" > ~/run_result + + # Force store previous run result to cache + - name: Store the previous run result + if: failure() + uses: actions/cache/save@v3 + with: + path: | + ~/run_result + key: ${{ github.run_id }}-${{ github.job }}-server-junit - name: Upload the failed tests report if: always()