From df9be3d476852be5d5eb7e06bf4c49c8dbf812c8 Mon Sep 17 00:00:00 2001 From: Shreya Saha <165661012+shsahahyland@users.noreply.github.com> Date: Mon, 11 Nov 2024 16:43:02 +0530 Subject: [PATCH] AAE-28088 Skip tests during PR draft (#811) --- .../actions/maven-build-and-tag/action.yml | 23 +++++++++++++++++-- docs/README.md | 21 +++++++++++++++++ version.txt | 2 +- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/.github/actions/maven-build-and-tag/action.yml b/.github/actions/maven-build-and-tag/action.yml index f348f31ec..24e9b4942 100644 --- a/.github/actions/maven-build-and-tag/action.yml +++ b/.github/actions/maven-build-and-tag/action.yml @@ -82,11 +82,18 @@ inputs: description: Whether testcontainers should be reused required: false default: 'false' + skip-tests-label: + description: The label name for skipping tests + required: false + default: 'skip-tests' outputs: version: description: "The version of the new tag created by this workflow" value: ${{ steps.update-pom-to-next-version.outputs.next-prerelease }} + skip-tests: + description: "Whether tests were skipped during build or not" + value: ${{ steps.set-skip-tests-env-variable.outputs.skip-tests }} runs: using: composite @@ -112,13 +119,24 @@ runs: with: maven-version: ${{ inputs.maven-version }} + - name: Set skip tests env variable + id: set-skip-tests-env-variable + env: + SKIP_TESTS: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, inputs.skip-tests-label) }} + shell: bash + run: | + echo "SKIP_TESTS=$SKIP_TESTS" >> $GITHUB_ENV + echo "skip-tests=$SKIP_TESTS" >> $GITHUB_OUTPUT + - name: Compute maven options id: compute-maven-options shell: bash run: | NTP='--no-transfer-progress' ${{ inputs.verbose }} && NTP='' - echo "result=--show-version --settings settings.xml $NTP" >> $GITHUB_OUTPUT + TEST_OPTIONS='' + [[ $SKIP_TESTS == 'true' ]] && TEST_OPTIONS='-DskipTests=true -DskipITs=true' + echo "result=--show-version --settings settings.xml $NTP $TEST_OPTIONS" >> $GITHUB_OUTPUT - name: Set is_preview env variable id: set-is-preview-env-variable @@ -245,7 +263,7 @@ runs: ${{ inputs.upload-jars-path }} - uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 - if: inputs.upload-coverage == 'true' + if: inputs.upload-coverage == 'true' && env.SKIP_TESTS != 'true' with: name: coverage retention-days: 1 @@ -253,6 +271,7 @@ runs: **/target/site/jacoco-aggregate/jacoco.xml - name: Echo Longest Tests run + if: env.SKIP_TESTS != 'true' shell: bash run: find . -name TEST-*.xml -exec grep -h testcase {} \; | awk -F '"' '{printf("%s#%s() - %.3fms\n", $4, $2, $6); }' | sort -n -k 3 | tail -20 diff --git a/docs/README.md b/docs/README.md index fe335a97e..f9116c87c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1008,6 +1008,7 @@ Check out, builds a maven project and docker images, generating a new alpha vers ```yaml outputs: version: ${{ steps.build-and-tag.outputs.version }} + skip-tests: ${{ steps.build-and-tag.outputs.skip-tests }} steps: - uses: Alfresco/alfresco-build-tools/.github/actions/maven-build-and-tag@ref id: build-and-tag @@ -1027,6 +1028,26 @@ There is a possibility to publish snapshot maven artifacts and docker images fro In order to use it specify `preview-label` input (or use default `preview`). Create a PR with the `preview-label` label. The created maven artifacts and docker images will be tagged as `0.0.1-$GITHUB_PR_NUMBER-SNAPSHOT`. +#### Option to skip tests for maven-build-and-tag + +There is a possibility to skip Unit and Integration Tests during build for an open PR. +In order to use it specify `skip-tests-label` input (or use default `skip-tests`). Create a PR with the `skip-tests` label. +A PR should not be merged if tests are skpped. + +Sample usage to prevent merging when tests are skipped: + +```yaml + - name: Set status check + shell: bash + run: | + if [[ ${{ steps.build-and-tag.outputs.skip-tests }} == 'true' ]]; then + echo "This pull request cannot be merged." + exit 1 + else + echo "This pull request can be merged." + fi +``` + ### maven-deploy-file Upload one or more files to a maven server, without requiring the presence of a diff --git a/version.txt b/version.txt index bd433e35d..33edba2d0 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v8.3.1 +v8.4.0