Skip to content

Commit

Permalink
Add CI task to validate file extension (#3196)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
cristian-ambrosini-sonarsource authored Oct 9, 2023
1 parent 7c129a0 commit ea83931
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,23 @@ 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
- frontend_tests
- validate_metadata
- validate_asciidoc
- validate_ci_tests
- validate_file_extensions
eks_container:
<<: *CONTAINER_DEFINITION
dockerfile: ci/Dockerfile
Expand Down
25 changes: 25 additions & 0 deletions ci/validate_file_extensions.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ea83931

Please sign in to comment.