diff --git a/.github/workflows/file-length-check.yml b/.github/workflows/file-length-check.yml deleted file mode 100644 index b483a0c..0000000 --- a/.github/workflows/file-length-check.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: 'File Length Check' - -on: - workflow_call: - inputs: - max_file_length: - description: 'The maximum number of lines that a file can be.' - default: 500 - required: false - type: number - files: - description: 'List of files to check for changes.' - required: true - type: string - -jobs: - file-length-check: - runs-on: ubuntu-latest - steps: - - name: Dependencies - run: | - sudo apt-get update - sudo apt-get -y install tclsh tcllib tdom tclcurl libpgtcl - - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Checkout Qcode CI - uses: actions/checkout@v3 - with: - repository: qcode-software/ci-development - path: qcode-ci - - - name: Get Changed Tcl Script Files - id: changed-files - uses: tj-actions/changed-files@v34 - with: - files: ${{ inputs.files }} - - - name: Check File Length - if: steps.changed-files.outputs.any_changed == 'true' - run: | - echo "Checking for line counts greater than ${{ inputs.max_line_length }} \ - in files: ${{ steps.changed-files.outputs.all_changed_files }}" - cd ${{ github.workspace }}/qcode-ci/scripts - tclsh file-length-check.tcl \ - ${{ inputs.max_file_length }} \ - ${{ github.workspace }} \ - ${{ steps.changed-files.outputs.all_changed_files }} \ No newline at end of file diff --git a/.github/workflows/line-length-check.yml b/.github/workflows/line-length-check.yml deleted file mode 100644 index fa44ace..0000000 --- a/.github/workflows/line-length-check.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: 'Line Length Check' - -on: - workflow_call: - inputs: - max_line_length: - description: 'The maximum number of characters that a line can be.' - default: 90 - required: false - type: number - files: - description: 'List of files to check for changes.' - required: true - type: string - -jobs: - line-length-check: - runs-on: ubuntu-latest - steps: - - name: Dependencies - run: | - sudo apt-get update - sudo apt-get -y install tclsh tcllib tdom tclcurl libpgtcl - - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Checkout Qcode CI - uses: actions/checkout@v3 - with: - repository: qcode-software/ci-development - path: qcode-ci - - - name: Get Changed Tcl Script Files - id: changed-files - uses: tj-actions/changed-files@v34 - with: - files: ${{ inputs.files }} - - - name: Check Line Length - if: steps.changed-files.outputs.any_changed == 'true' - run: | - echo "Checking line length is under ${{ inputs.max_line_length }} chars \ - in files: ${{ steps.changed-files.outputs.all_changed_files }}" - cd ${{ github.workspace }}/qcode-ci/scripts - tclsh line-length-check.tcl \ - ${{ github.workspace }}/qcode-ci/tcl/linter.tcl \ - ${{ inputs.max_line_length }} \ - ${{ github.workspace }} \ - ${{ steps.changed-files.outputs.all_changed_files }} \ No newline at end of file diff --git a/.github/workflows/proc-length-check.yml b/.github/workflows/proc-length-check.yml deleted file mode 100644 index 5e09029..0000000 --- a/.github/workflows/proc-length-check.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: 'Proc Length Check' - -on: - workflow_call: - inputs: - files: - description: 'List of files to check for changes.' - required: true - type: string - max_proc_body_length: - description: 'The maximum number of lines that a proc body can be.' - default: 80 - required: false - type: number - -jobs: - proc-length-check: - runs-on: ubuntu-latest - steps: - - name: Dependencies - run: | - sudo apt-get update - sudo apt-get -y install tclsh tcllib tdom tclcurl libpgtcl - - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Checkout Qcode CI - uses: actions/checkout@v3 - with: - repository: qcode-software/ci-development - path: qcode-ci - - - name: Get Changed Tcl Script Files - id: changed-files - uses: tj-actions/changed-files@v34 - with: - files: ${{ inputs.files }} - - - name: Check Proc Lengths - if: steps.changed-files.outputs.any_changed == 'true' - run: | - echo "Checking proc body lengths in files: \ - ${{ steps.changed-files.outputs.all_changed_files }}" - cd ${{ github.workspace }}/qcode-ci/scripts - tclsh proc-length-check.tcl \ - ${{ github.workspace }}/qcode-ci/tcl/linter.tcl \ - ${{ inputs.max_proc_body_length }} \ - ${{ github.workspace }} \ - ${{ steps.changed-files.outputs.all_changed_files }} \ No newline at end of file diff --git a/.github/workflows/proc-name-check.yml b/.github/workflows/proc-name-check.yml deleted file mode 100644 index ff5f3c6..0000000 --- a/.github/workflows/proc-name-check.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: 'Proc Name Check' - -on: - workflow_call: - inputs: - files: - description: 'List of files to check for changes.' - required: true - type: string - -jobs: - proc-name-check: - runs-on: ubuntu-latest - steps: - - name: Dependencies - run: | - sudo apt-get update - sudo apt-get -y install tclsh tcllib tdom tclcurl libpgtcl - - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Checkout Qcode CI - uses: actions/checkout@v3 - with: - repository: qcode-software/ci-development - path: qcode-ci - - - name: Get Changed Tcl Script Files - id: changed-files - uses: tj-actions/changed-files@v34 - with: - files: ${{ inputs.files }} - - - name: Check Proc Names - if: steps.changed-files.outputs.any_changed == 'true' - run: | - echo "Checking proc name prefixes in files: \ - ${{ steps.changed-files.outputs.all_changed_files }}" - cd ${{ github.workspace }}/qcode-ci/scripts - tclsh proc-name-check.tcl \ - ${{ github.workspace }}/qcode-ci/tcl/linter.tcl \ - ${{ github.workspace }} \ - ${{ steps.changed-files.outputs.all_changed_files }} \ No newline at end of file diff --git a/.github/workflows/procs-have-unit-tests-check.yml b/.github/workflows/procs-have-unit-tests-check.yml deleted file mode 100644 index f979dba..0000000 --- a/.github/workflows/procs-have-unit-tests-check.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: 'Procs Have Unit Tests Check' - -on: - workflow_call: - inputs: - test_directory: - description: 'Directory within the repository where test files are located.' - default: test - required: false - type: string - files: - description: 'List of files to check for changes.' - required: true - type: string - -jobs: - procs-have-unit-tests-check: - runs-on: ubuntu-latest - steps: - - name: Dependencies - run: | - sudo apt-get update - sudo apt-get -y install tclsh tcllib tdom tclcurl libpgtcl - - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Checkout Qcode CI - uses: actions/checkout@v3 - with: - repository: qcode-software/ci-development - path: qcode-ci - - - name: Get Changed Tcl Script Files - id: changed-files - uses: tj-actions/changed-files@v34 - with: - files: ${{ inputs.files }} - - - name: Check Procs Have Unit Tests - if: steps.changed-files.outputs.any_changed == 'true' - run: | - echo "Checking procs in the following files have unit tests: \ - ${{ steps.changed-files.outputs.all_changed_files }}" - cd ${{ github.workspace }}/qcode-ci/scripts - tclsh procs-have-unit-tests-check.tcl \ - ${{ github.workspace }}/qcode-ci/tcl/test_coverage.tcl \ - ${{ github.workspace }} \ - ${{ inputs.test_directory }} \ - ${{ steps.changed-files.outputs.all_changed_files }} \ No newline at end of file diff --git a/.github/workflows/qcode-ci.yml b/.github/workflows/qcode-ci.yml index f0e6c07..d6feb96 100644 --- a/.github/workflows/qcode-ci.yml +++ b/.github/workflows/qcode-ci.yml @@ -54,46 +54,97 @@ on: type: string jobs: - line_length_check: - name: Check for Lines Exceeding Max Chars - if: inputs.check_line_lengths - uses: ./.github/workflows/line-length-check.yml - with: - max_line_length: ${{ inputs.max_line_length }} - files: ${{ inputs.files }} - secrets: inherit + linting: + runs-on: ubuntu-latest + steps: + - name: Dependencies + run: | + sudo apt-get update + sudo apt-get -y install tclsh tcllib tdom tclcurl libpgtcl - proc_name_check: - name: Check for Proc Names Not Prefixed with File Name - if: inputs.check_proc_names - uses: ./.github/workflows/proc-name-check.yml - with: - files: ${{ inputs.files }} - secrets: inherit + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 - proc_length_check: - name: Check for Proc Bodies Exceeding Max Lines - if: inputs.check_proc_lengths - uses: ./.github/workflows/proc-length-check.yml - with: - max_proc_body_length: ${{ inputs.max_proc_body_length }} - files: ${{ inputs.files }} - secrets: inherit + - name: Checkout Qcode CI + uses: actions/checkout@v3 + with: + repository: qcode-software/ci-development + path: qcode-ci - procs_have_unit_tests_check: - name: Check Procs Have Unit Tests - if: inputs.check_procs_have_unit_tests - uses: ./.github/workflows/procs-have-unit-tests-check.yml - with: - test_directory: ${{ inputs.test_directory }} - files: ${{ inputs.files }} - secrets: inherit + - name: Get Changed Tcl Script Files + id: changed-files + uses: tj-actions/changed-files@v34 + with: + files: ${{ inputs.files }} - file_length_check: - name: Check for Files Exceeding Max Lines - if: inputs.check_file_lengths - uses: ./.github/workflows/file-length-check.yml - with: - max_file_length: ${{ inputs.max_file_length }} - files: ${{ inputs.files }} - secrets: inherit \ No newline at end of file + - name: Check for Lines Exceeding Max Chars + id: check-line-length + if: > + always() + && steps.changed-files.outcome == 'success' + && inputs.check_line_lengths + && steps.changed-files.outputs.any_changed == 'true' + run: | + cd ${{ github.workspace }}/qcode-ci/scripts + tclsh line-length-check.tcl \ + ${{ github.workspace }}/qcode-ci/tcl/linter.tcl \ + ${{ inputs.max_line_length }} \ + ${{ github.workspace }} \ + ${{ steps.changed-files.outputs.all_changed_files }} + + - name: Check for Proc Names Not Prefixed with File Name + if: > + always() + && steps.changed-files.outcome == 'success' + && inputs.check_proc_names + && steps.changed-files.outputs.any_changed == 'true' + run: | + cd ${{ github.workspace }}/qcode-ci/scripts + tclsh proc-name-check.tcl \ + ${{ github.workspace }}/qcode-ci/tcl/linter.tcl \ + ${{ github.workspace }} \ + ${{ steps.changed-files.outputs.all_changed_files }} + + + - name: Check for Proc Bodies Exceeding Max Lines + if: > + always() + && steps.changed-files.outcome == 'success' + && inputs.check_proc_lengths + && steps.changed-files.outputs.any_changed == 'true' + run: | + cd ${{ github.workspace }}/qcode-ci/scripts + tclsh proc-length-check.tcl \ + ${{ github.workspace }}/qcode-ci/tcl/linter.tcl \ + ${{ inputs.max_proc_body_length }} \ + ${{ github.workspace }} \ + ${{ steps.changed-files.outputs.all_changed_files }} + + - name: Check Procs Have Unit Tests + if: > + always() + && steps.changed-files.outcome == 'success' + && inputs.check_procs_have_unit_tests + && steps.changed-files.outputs.any_changed == 'true' + run: | + cd ${{ github.workspace }}/qcode-ci/scripts + tclsh procs-have-unit-tests-check.tcl \ + ${{ github.workspace }}/qcode-ci/tcl/test_coverage.tcl \ + ${{ github.workspace }} \ + ${{ inputs.test_directory }} \ + ${{ steps.changed-files.outputs.all_changed_files }} + + - name: Check for Files Exceeding Max Lines + if: > + always() + && steps.changed-files.outcome == 'success' + && inputs.check_file_lengths + && steps.changed-files.outputs.any_changed == 'true' + run: | + cd ${{ github.workspace }}/qcode-ci/scripts + tclsh file-length-check.tcl \ + ${{ inputs.max_file_length }} \ + ${{ github.workspace }} \ + ${{ steps.changed-files.outputs.all_changed_files }} \ No newline at end of file diff --git a/scripts/file-length-check.tcl b/scripts/file-length-check.tcl index 50a8e5a..6ced7bf 100644 --- a/scripts/file-length-check.tcl +++ b/scripts/file-length-check.tcl @@ -3,6 +3,8 @@ set repository [lindex $argv 1] set files [lrange $argv 2 end] set long_files [list] +puts "Checking for files that are more than $max_lines lines long." + foreach file $files { try { set handle [open "${repository}/${file}" r] @@ -28,10 +30,8 @@ foreach file $files { if { [dict size $long_files] > 0 } { - puts "Files with more than ${max_lines} lines:" - dict for {filename line_count} $long_files { - puts " $filename :: $line_count lines" + puts "The file $filename has $line_count lines." } exit 1 diff --git a/scripts/line-length-check.tcl b/scripts/line-length-check.tcl index ff8a152..e325f8f 100644 --- a/scripts/line-length-check.tcl +++ b/scripts/line-length-check.tcl @@ -6,6 +6,8 @@ set long_lines [list] source $linter +puts "Checking line length is under $max_line_length chars in files that have changed." + foreach file $files { set lines [linter_report_lines_over_length \ "${repository}/${file}" \ @@ -13,7 +15,7 @@ foreach file $files { lappend long_lines {*}$lines foreach line $lines { - puts $line + puts "$line" } } diff --git a/scripts/proc-length-check.tcl b/scripts/proc-length-check.tcl index 0fc23a4..30f5b3b 100644 --- a/scripts/proc-length-check.tcl +++ b/scripts/proc-length-check.tcl @@ -6,6 +6,8 @@ set long_procs [list] source $linter +puts "Checking for procs that have bodies that are more than $max_lines lines long." + foreach file $files { set proc_lengths [linter_file_proc_lengths "${repository}/${file}"] @@ -18,11 +20,10 @@ foreach file $files { if { [dict size $long_procs] > 0 } { - puts "Procs with bodies greater than ${max_lines} lines:" - dict for {filename procs} $long_procs { dict for {proc_name body_length} $procs { - puts " $filename :: $proc_name :: $body_length lines" + puts "The proc \"$proc_name\" in file $filename has a body that is\ + $body_length long." } } diff --git a/scripts/proc-name-check.tcl b/scripts/proc-name-check.tcl index a01d825..7ed630b 100644 --- a/scripts/proc-name-check.tcl +++ b/scripts/proc-name-check.tcl @@ -5,6 +5,8 @@ set reported_procs [list] source $linter +puts "Checking proc name prefixes in files that have changed." + foreach file $files { set lines [linter_report_procs_without_filename_prefix \ "${repository}/${file}"] diff --git a/scripts/procs-have-unit-tests-check.tcl b/scripts/procs-have-unit-tests-check.tcl index 1b08974..5f0f78f 100644 --- a/scripts/procs-have-unit-tests-check.tcl +++ b/scripts/procs-have-unit-tests-check.tcl @@ -9,6 +9,8 @@ set procs_missing_tests false source $test_coverage_api +puts "Checking for procs that do not have at least one unit test." + foreach file $files { set proc_names [test_coverage_proc_names_get "${repository}/${file}"] dict set file_procs $file $proc_names @@ -28,7 +30,7 @@ dict for {filename procs_tests} $map { if { [dict size $tests] == 0 } { set procs_missing_tests true - puts "Missing unit test: $filename :: $proc_name" + puts "The proc \"$proc_name\" in file $filename doesn't have a unit test." } } } diff --git a/tcl/linter.tcl b/tcl/linter.tcl index 9bfc75e..32cbe63 100644 --- a/tcl/linter.tcl +++ b/tcl/linter.tcl @@ -14,9 +14,9 @@ proc linter_report_lines_over_length { set line_length [string length $line] if { $line_length > $max_line_length } { set partial_line [string range [string trimleft $line] 0 15] - - set details "[file tail $file] :: line $line_no :: " - append details "length: $line_length chars :: ${partial_line}..." + + set details "Line $line_no in file $file is $line_length chars long" + append details " - ${partial_line}..." lappend report $details } @@ -49,7 +49,8 @@ proc linter_report_procs_without_filename_prefix {file} { foreach proc_name $proc_names { if { ![string match "${prefix}*" $proc_name] } { - lappend report "$filename :: $proc_name" + lappend report "The proc name \"$proc_name\" in file $filename is not\ + prefixed with \"$prefix\"." } }