forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Added a shell script that checks if the files in the repository c…
…onform to the file naming convention as discussed in ElektraInitiative#1615. This script is executed at the cirrus CI and the Jenkins CI.
- Loading branch information
Showing
5 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -281,6 +281,42 @@ task: | |
false | ||
fi | ||
task: | ||
matrix: | ||
|
||
- name: 📄 Check | ||
container: | ||
cpu: 2 | ||
memory: 4G | ||
dockerfile: scripts/docker/cirrus/arch/Dockerfile | ||
|
||
clone_script: | | ||
if [ -z "$CIRRUS_PR" ]; then | ||
git clone --branch=$CIRRUS_BRANCH https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git \ | ||
$CIRRUS_WORKING_DIR | ||
git reset --hard $CIRRUS_CHANGE_IN_REPO | ||
else | ||
git clone https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR | ||
git fetch origin pull/$CIRRUS_PR/head:pull/$CIRRUS_PR | ||
git config user.email "[email protected]" | ||
git config user.name "nobody" | ||
git merge --no-commit --no-ff $CIRRUS_CHANGE_IN_REPO | ||
fi | ||
script: | ||
- *generate | ||
- scripts/dev/filename-checker 2> bad_file_names.txt > /dev/null | ||
|
||
tests_script: | ||
- | | ||
if test -s bad_file_names.txt; then | ||
printf >&2 '—————————————\n' | ||
cat >&2 bad_file_names.txt | ||
printf >&2 '—————————————\n' | ||
false | ||
fi | ||
task: | ||
matrix: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/sh | ||
# | ||
# @author muskater | ||
# @brief Checks that only files exist in the repository that conform to the naming convention: [/.a-zA-Z0-9_-]* | ||
# Exceptions to this rule can be specified in tests/filename.whitelist. | ||
# The current directory will be used as base directory. | ||
# @date 18.11.2021 | ||
# @tags validation | ||
|
||
if [ $# -ne 0 ]; then | ||
echo "Usage: filename-checker" | ||
exit | ||
fi | ||
|
||
# Check if tests/allow-list exists. | ||
ALLOW_LIST_FILE=./tests/filename.whitelist | ||
if [ ! -f "$ALLOW_LIST_FILE" ]; then | ||
echo >&2 "$ALLOW_LIST_FILE dose not exists." | ||
exit 1 | ||
fi | ||
|
||
# Store the content of the allow-list into ALLOW_LIST. | ||
# Ignore every line that starts with '#' or spaces. | ||
ALLOW_LIST=$(grep -Ev '^(#|[[:space:]]*$)' "./tests/filename.whitelist") | ||
|
||
# Find any file that is non-compliant. | ||
# Save them to the variable FORBIDDEN_NAMES. | ||
FORBIDDEN_NAMES=$(find . | grep -v '^[-_/.a-zA-Z0-9]*$') | ||
|
||
# All file names that offend the rule are saved into BANNED_NAMES. | ||
BANNED_NAMES=$(echo "$FORBIDDEN_NAMES" | while read -r test_line; do | ||
# Set the delimiter to newline to compare every line. | ||
# Import the variable test_line as l. | ||
# Compare line by line the allow-list with test_line. | ||
CHECK=$(echo "$ALLOW_LIST" | awk -F "\n" -v l="$test_line" '$1 == l { print $1 }') | ||
# When CHECK is empty it means that that no entry in the white list was found. | ||
if [ -z "$CHECK" ]; then | ||
echo "$test_line" | ||
fi | ||
done) | ||
if [ -n "$BANNED_NAMES" ]; then | ||
echo >&2 "These file names do not comply with the naming convention: [/.a-zA-Z0-9_-]*" | ||
echo >&2 "Please change them accordingly or add them to tests/filename.whitelist" | ||
echo >&2 "$BANNED_NAMES" | ||
exit 1 | ||
else | ||
echo "All file names comply!" | ||
exit 0 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Whitelist for the filename-checker | ||
./.idea/fileTemplates/includes/C File Header.h |