Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
hpc-compendium
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ZIH
hpcsupport
hpc-compendium
Commits
d3e294fb
Commit
d3e294fb
authored
3 years ago
by
Martin Schroschk
Browse files
Options
Downloads
Plain Diff
Merge branch 'preview' of gitlab.hrz.tu-chemnitz.de:zih/hpcsupport/hpc-compendium into issue137
parents
65fa9e69
3616b648
No related branches found
No related tags found
3 merge requests
!322
Merge preview into main
,
!319
Merge preview into main
,
!272
Review loadleveler page
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc.zih.tu-dresden.de/util/grep-forbidden-words.sh
+96
-47
96 additions, 47 deletions
doc.zih.tu-dresden.de/util/grep-forbidden-words.sh
with
96 additions
and
47 deletions
doc.zih.tu-dresden.de/util/grep-forbidden-words.sh
+
96
−
47
View file @
d3e294fb
...
...
@@ -2,58 +2,107 @@
set
-euo
pipefail
branch
=
"preview"
if
[
-n
"
$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
"
]
;
then
branch
=
"origin/
$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
"
fi
scriptpath
=
${
BASH_SOURCE
[0]
}
basedir
=
`
dirname
"
$scriptpath
"
`
basedir
=
`
dirname
"
$basedir
"
`
#This is the ruleset. Each line represents a rule of tab-separated fields.
#The first field represents whether the match should be case-sensitive (s) or insensitive (i).
#The second field represents the pattern that should not be contained in any file that is checked.
#Further fields represent patterns with exceptions.
#For example, the first rule says:
# The pattern \<io\> should not be present in any file (case-insensitive match), except when it appears as ".io".
ruleset
=
"i
\<
io
\>
\.
io
s
\<
SLURM
\>
i file
\+
system
i
\<
taurus
\>
taurus
\.
hrsk /taurus
i
\<
hrskii
\>
i hpc
\+
system
i hpc[ -]
\+
da
\>
"
any_fails
=
false
function
grepExceptions
()
{
if
[
$#
-gt
0
]
;
then
firstPattern
=
$1
shift
grep
-v
"
$firstPattern
"
| grepExceptions
"
$@
"
else
cat
-
fi
}
files
=
$(
git diff
--name-only
"
$(
git merge-base HEAD
"
$branch
"
)
"
)
function
usage
()
{
echo
"
$0
[options]"
echo
"Search forbidden patterns in markdown files."
echo
""
echo
"Options:"
echo
" -a Search in all markdown files (default: git-changed files)"
echo
" -s Silent mode"
echo
" -h Show help message"
}
# Options
all_files
=
false
silent
=
false
while
getopts
":ahs"
option
;
do
case
$option
in
a
)
all_files
=
true
;;
s
)
silent
=
true
;;
h
)
usage
exit
;;
\?
)
# Invalid option
echo
"Error: Invalid option."
usage
exit
;;
esac
done
branch
=
"origin/
${
CI_MERGE_REQUEST_TARGET_BRANCH_NAME
:-
preview
}
"
if
[
$all_files
=
true
]
;
then
echo
"Search in all markdown files."
files
=
$(
git ls-tree
--full-tree
-r
--name-only
HEAD
$basedir
/docs/ |
grep
.md
)
else
echo
"Search in git-changed files."
files
=
`
git diff
--name-only
"
$(
git merge-base HEAD
"
$branch
"
)
"
`
fi
cnt
=
0
for
f
in
$files
;
do
if
[
"
$f
"
!=
doc.zih.tu-dresden.de/README.md
-a
"
${
f
:
-3
}
"
==
".md"
]
;
then
#The following checks assume that grep signals success when it finds something,
#while it signals failure if it doesn't find something.
#We assume that we are successful if we DON'T find the pattern,
#which is the other way around, hence the "!".
echo
"Checking wording of
$f
: IO"
#io must be the whole word
if
!
grep
-n
-i
'\<io\>'
"
$f
"
|
grep
-v
'\.io'
;
then
any_fails
=
true
fi
echo
"Checking wording of
$f
: SLURM"
#SLURM must be the whole word, otherwise it might match script variables
#such as SLURM_JOB_ID
if
!
grep
-n
'\<SLURM\>'
"
$f
"
;
then
any_fails
=
true
fi
echo
"Checking wording of
$f
: file system"
#arbitrary white space in between
if
!
grep
-n
-i
'file \+system'
"
$f
"
;
then
any_fails
=
true
fi
#check for word taurus, except when used in conjunction with .hrsk or /taurus,
#which might appear in code snippets
echo
"Checking wording of
$f
: taurus"
if
!
grep
-n
-i
'\<taurus\>'
"
$f
"
|
grep
-v
'taurus\.hrsk'
|
grep
-v
'/taurus'
;
then
any_fails
=
true
fi
echo
"Checking wording of
$f
: hrskii"
if
!
grep
-n
-i
'\<hrskii\>'
"
$f
"
;
then
any_fails
=
true
fi
echo
"Checking wording of
$f
: hpc system"
if
!
grep
-n
-i
'hpc \+system'
"
$f
"
;
then
any_fails
=
true
if
[
"
$f
"
!=
doc.zih.tu-dresden.de/README.md
-a
"
${
f
:
-3
}
"
==
".md"
]
;
then
echo
"Check wording in file
$f
"
while
IFS
=
$'
\t
'
read
-r
flags pattern exceptionPatterns
;
do
while
IFS
=
$'
\t
'
read
-r
-a
exceptionPatternsArray
;
do
if
[
$silent
=
false
]
;
then
echo
" Pattern:
$pattern
"
fi
echo
"Checking wording of
$f
: hpc-da"
if
!
grep
-n
-i
'hpc[ -]\+da\>'
"
$f
"
;
then
any_fails
=
true
grepflag
=
case
"
$flags
"
in
"i"
)
grepflag
=
-i
;;
esac
if
grep
-n
$grepflag
"
$pattern
"
"
$f
"
| grepExceptions
"
${
exceptionPatternsArray
[@]
}
"
;
then
((
cnt
=
cnt+1
))
fi
fi
done
<<<
$exceptionPatterns
done
<<<
$ruleset
fi
done
if
[
"
$any_fails
"
==
true
]
;
then
exit
1
echo
""
case
$cnt
in
1
)
echo
"Forbidden Patterns: 1 match found"
;;
*
)
echo
"Forbidden Patterns:
$cnt
matches found"
;;
esac
if
[
$cnt
-gt
0
]
;
then
exit
1
fi
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment