ci: Allow rerun of only failed tests in Junit (#29469)

## Description
- Added the required logic to rerun only the failed tests in JUnit in
server-build.yml
- Separated the build and test steps to accommodate our requirements

#### Type of change
- Workflow changes (server-build.yml)
## Testing
- [x] [Workflow
run](https://github.com/appsmithorg/appsmith/actions/runs/7164444771?pr=29469)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Documentation**
- Enhanced comments for clarity in test methods related to application
creation, duplication, and cloning.
- Updated comments to reflect changes in test assertions for application
visibility and user anonymity.

- **Tests**
- Modified assertions in `ActionServiceCE_Test` to align with expected
behavior in view mode.
- Added new assertions and comments in `ApplicationServiceCETest` to
improve test coverage and documentation.

- **Chores**
- Improved the server build workflow with better caching and error
handling mechanisms.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Saroj 2023-12-11 18:30:11 +05:30 committed by GitHub
parent 4c65938b72
commit d9698faa25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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()