Add CI task to validate file extension (#3196)

The dotnet squad would like to improve the rule specification sprint
process requiring some UTs to be temporarily added under the rule folder
on RSPEC repository. These test case files (`.cs` and `.vb`) will be
copied to the sonar-dotnet repository during the initial phases of
implementation and will serve as an initial test bed.
However, before merging the PR on the RSPEC side we need to make sure
that these test case files are deleted and they don't end up on master.

The goal of this PR would be to add a check on the pipeline that will
fail if `.cs` or `.vb` files are detected (it's acceptable if it's red
until the implementation is done).
This commit is contained in:
Cristian Ambrosini 2023-10-09 10:37:38 +02:00 committed by GitHub
parent 7c129a0f1b
commit ea83931eb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -125,6 +125,15 @@ validate_links_task:
cache_upload_script:
- bash ci/cirrus-cache.sh upload ${LINK_CACHE_NAME} ${LINK_CACHE_PATH}
validate_file_extensions_task:
eks_container:
<<: *CONTAINER_DEFINITION
dockerfile: ci/Dockerfile
cpu: 1
memory: 2G
file_extension_tests_script:
- bash ./ci/validate_file_extensions.sh
all_required_checks_task:
depends_on:
- tooling_tests
@ -132,6 +141,7 @@ all_required_checks_task:
- validate_metadata
- validate_asciidoc
- validate_ci_tests
- validate_file_extensions
eks_container:
<<: *CONTAINER_DEFINITION
dockerfile: ci/Dockerfile

View File

@ -0,0 +1,25 @@
#!/bin/bash
#
# Validates that there are no files with .cs, .vb, .razor or .cshtml extensions present inside rules folder.
#
# As part of the new DotNet squad rule specification sprint guidelines, test case files similar to the ones
# used for unit tests in sonar-dotnet should be temporarely added under the rule folder on RSPEC repository.
# Those files can be of any number for both C# (*.cs, *.razor, *.cshtml) and VB.NET (.*vb).
# The test case files will be copied to the sonar-dotnet repository during the initial phases of implementation
# and will serve as an initial test bed.
# Before merging the PR on the RSPEC side, it is important to ensure that these test case files are deleted.
# The script make sure to fail the CI if any of those previously mentioned files are present inside the rules folder.
set -euxo pipefail
TOPLEVEL="$(realpath .)"
RULES_DIR="${TOPLEVEL}/rules"
CSVB_FILES=($(find "${RULES_DIR}" -type f -name "*.cs" -o -name "*.vb" -o -name "*.razor" -o -name "*.cshtml"))
if [ ${#CSVB_FILES[@]} -gt 0 ]; then
echo "ERROR: '.cs','.vb','.razor' or '.cshtml' files are detected."
printf '%s\n' "${CSVB_FILES[@]}"
exit 1
else
echo "SUCCESS: no '.cs' or '.vb' files detected."
exit 0
fi