#!/bin/bash #============================================================================== # Copyright and license info is available in the LICENSE file included with # the software, and also available online: # https://swarm.workshop.perforce.com/projects/tom_tyler-wfv_tidy/view/main/LICENSE #------------------------------------------------------------------------------ #------------------------------------------------------------------------------ # This is called as a Perforce Helix trigger. # # This script is optimized for "fail safe" behavior, meaning that if it # cannot to it's core job of HTML validation, it will exit with a '0' # exit code, thus not disrupting the 'submit' operation. This would # only occur in very strange scenarious, e.g. if the 'tidy' binary # disappeared or the command line usage was bad, neither of which should # ever happen. But if they do, it's better to stop validations than to # block submits on the Helix server. # Triggers: # wfv_tidy change-content //path/... "/p4/common/bin/triggers/wfv_tidy.sh %changelist%" #------------------------------------------------------------------------------ set -u declare -i Version=1.0.3 declare Changelist=${1:-Unset} declare TidyExe= declare TidyExitCode= declare LogDir=${LOGS:-/tmp} declare TidyLog= declare TmpFile=/tmp/tmp.wfv_tidy.$$.$RANDOM declare DepotFile= declare HeadAction= declare -i FirstMsg=0 declare -i i=0 declare -i OverallExitCode=0 [[ $Changelist == Unset ]] && exit 0 # If we can't find the 'tidy' exe in our PATH, just quietly bail. TidyExe=$(which tidy 2>/dev/null) [[ -z "$TidyExe" ]] && exit 0 # Check for the bypass. desc=$(p4 -ztag -F %Description% change -o $Changelist) [[ "$desc" == *"BYPASS_VALIDATOR"* ]] && exit 0 while [[ 1 ]]; do DepotFile="$(p4 -ztag -F %depotFile${i}% describe -s $Changelist)" [[ -z "$DepotFile" ]] && break HeadAction="$(p4 -ztag -F %action${i}% describe -s $Changelist)" i=$((i+1)) [[ "$HeadAction" =~ ^(add|edit|integrate|move/add)$ ]] || continue [[ "$DepotFile" =~ ^.*(html|inc)$ ]] || continue TidyLog=$LogDir/tidy.$Changelist.$i.log p4 print -q -o $TmpFile "$DepotFile@=$Changelist" $TidyExe $TmpFile > $TidyLog 2>&1 TidyExitCode=$? if [[ $TidyExitCode -ne 0 ]]; then if [[ $FirstMsg -eq 0 ]]; then echo -e "\nIn Changelist $Changelist, the following files had issues with HTML validation:\n" FirstMsg=1 fi if [[ $TidyExitCode -eq 1 ]]; then OverallExitCode=1 echo -e "\nTidy reported validation Warnings for $DepotFile. Details:\n" fi if [[ $TidyExitCode -eq 2 ]]; then OverallExitCode=2 echo -e "\nTidy reported validation Errors for $DepotFile. Details:\n" fi cat $TidyLog echo -e "\n" fi done find $LogDir -type f -depth 1 -name "tidy.*.log" -mtime +14 -exec /bin/rm -f {} \; exit $OverallExitCode
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 19447 | C. Thomas Tyler | Fixed a doc typo and added version id. | ||
#2 | 18812 | C. Thomas Tyler |
chmod +x wfv-tidy.sh. No content change. |
||
#1 | 17301 | C. Thomas Tyler |
Added README.md and LICENSE file. Added initial version of wfv_tidy.sh, still a work in progress. |