diff --git a/.github/workflows/build-and-review-pr.yml b/.github/workflows/build-and-review-pr.yml index 27da842..07fd4a2 100644 --- a/.github/workflows/build-and-review-pr.yml +++ b/.github/workflows/build-and-review-pr.yml @@ -64,36 +64,13 @@ jobs: unit-tests: runs-on: ubuntu-latest env: - REPORTS_INPUT_VALID: './test/input-files/valid/*.xml' - REPORTS_INPUT_BAD_DIR: './test/input-files/bad-dir/*.xml' - REPORTS_INPUT_BAD_PATTERN: './test/input-files/valid/*.opncvr.xml' - - TARGETDIR_INPUT_VERBOSITY: './test-results/invalid-verbosity' - TARGETDIR_INPUT_REPORTTYPES: './test-results/invalid-reporttypes' - TARGETDIR_INPUT_DOES_NOT_EXIST: './test-results/dir-does-not-exist' - TARGETDIR_INPUT_BAD_PATTERN: './test-results/bad-pattern' - TARGETDIR_INPUT_INVALID: './test-results/invalid-xml' - TARGETDIR_INPUT_MATCHING: './test-results/matching-reports' - TARGETDIR_INPUT_ASSEMBLY_FILTERS: './test-results/assembly-filter' - TARGETDIR_INPUT_CLASS_FILTERS: './test-results/class-filter' - TARGETDIR_INPUT_FILE_FILTERS: './test-results/file-filter' - - ERROR_REASON_OUTPUT_VERBOSITY: 'Invalid verbosity' - ERROR_REASON_OUTPUT_REPORTTYPES: 'Invalid report type' - ERROR_REASON_OUTPUT_NO_MATCHING_FILES: 'No matching files found' - ERROR_REASON_OUTPUT_TOOL: 'Failed to execute ReportGenerator.exe' - ERROR_REASON_OUTPUT_ACTION: 'Failed to execute the action' - - ACTUAL_CONTENTS_MATCHING: './test-results/matching-reports/Summary.md' # MarkdownSummary - ACTUAL_CONTENTS_ASSEMBLY_FILTERS: './test-results/assembly-filters/Summary.xml' # XmlSummary - ACTUAL_CONTENTS_CLASS_FILTERS: './test-results/class-filters/Summary.json' # JsonSummary - ACTUAL_CONTENTS_FILE_FILTERS: './test-results/file-filters/Summary.txt' # TextSummary - - EXPECTED_CONTENTS_MATCHING: './test/expected-contents/matching-reports.md' - EXPECTED_CONTENTS_ASSEMBLY_FILTERS: './test/expected-contents/assembly-filters.xml' - EXPECTED_CONTENTS_CLASS_FILTERS: './test/expected-contents/class-filters.json' - EXPECTED_CONTENTS_FILE_FILTERS: './test/expected-contents/file-filters.txt' - + # These env vars are reused and set for each test scenario + REPORTS_INPUT: '' + TARGETDIR_INPUT: '' + ERROR_REASON: '' + GENERATED_FILE: '' + FILE_WITH_SUBSTRING: '' + steps: - name: '-------------------------------------------------------------------------------------------------------------' run: echo "" @@ -103,19 +80,37 @@ jobs: - name: Setup - Checkout the action uses: actions/checkout@v4 + - name: Setup - Create the test-results directory + run: mkdir -p ./test-results + - name: '-------------------------------------------------------------------------------------------------------------' run: echo "" - name: ' TEST 1 - INVALID VERBOSITY INPUT ' run: echo "" + - name: Setup - Set variables for Test 1 + if: always() + run: | + errorReason="Invalid verbosity" + reports="./test/input-files/valid/*.xml" + targetDir="./test-results/invalid-verbosity" + generatedFile="" + fileWithSubstring="" + + echo "ERROR_REASON=$errorReason" >> "$GITHUB_ENV" + echo "REPORTS_INPUT=$reports" >> "$GITHUB_ENV" + echo "TARGETDIR_INPUT=$targetDir" >> "$GITHUB_ENV" + echo "GENERATED_FILE=$generatedFile" >> "$GITHUB_ENV" + echo "FILE_WITH_SUBSTRING=$fileWithSubstring" >> "$GITHUB_ENV" + - name: 1a - When code-coverage-report-generator is called with an invalid 'verbosity' input id: invalid-verbosity if: always() continue-on-error: true # This is needed because we expect the step to fail but we need it to "pass" in order for the test job to succeed. uses: ./ with: - reports: '${{ env.REPORTS_INPUT_VALID }}' - targetdir: '${{ env.TARGETDIR_INPUT_VERBOSITY }}' + reports: '${{ env.REPORTS_INPUT }}' + targetdir: '${{ env.TARGETDIR_INPUT }}' reporttypes: 'MarkdownSummary' verbosity: 'InVaLId_VeRbOsItY' @@ -123,27 +118,42 @@ jobs: if: always() run: ./test/assert-values-match.sh --name "step outcome" --expected "failure" --actual "${{ steps.invalid-verbosity.outcome }}" - - name: 1c - And the 'error-reason' output should be '${{ env.ERROR_REASON_OUTPUT_VERBOSITY }}' + - name: 1c - And the 'error-reason' output should be '${{ env.ERROR_REASON }}' if: always() - run: ./test/assert-values-match.sh --name "error-reason output" --expected "${{ env.ERROR_REASON_OUTPUT_VERBOSITY }}" --actual "${{ steps.invalid-verbosity.outputs.error-reason }}" + run: ./test/assert-values-match.sh --name "error-reason output" --expected "${{ env.ERROR_REASON }}" --actual "${{ steps.invalid-verbosity.outputs.error-reason }}" - name: 1d - And the target directory should not exist if: always() - run: ./test/assert-dir-does-not-exist.sh --dir "${{ env.TARGETDIR_INPUT_VERBOSITY }}" + run: ./test/assert-dir-does-not-exist.sh --dir "${{ env.TARGETDIR_INPUT }}" - name: '-------------------------------------------------------------------------------------------------------------' run: echo "" - name: ' TEST 2 - INVALID REPORTTYPES INPUT ' run: echo "" + - name: Setup - Set variables for Test 2 + if: always() + run: | + errorReason="Invalid report type" + reports="./test/input-files/valid/*.xml" + targetDir="./test-results/invalid-reporttypes" + generatedFile="" + fileWithSubstring="" + + echo "ERROR_REASON=$errorReason" >> "$GITHUB_ENV" + echo "REPORTS_INPUT=$reports" >> "$GITHUB_ENV" + echo "TARGETDIR_INPUT=$targetDir" >> "$GITHUB_ENV" + echo "GENERATED_FILE=$generatedFile" >> "$GITHUB_ENV" + echo "FILE_WITH_SUBSTRING=$fileWithSubstring" >> "$GITHUB_ENV" + - name: 2a - When code-coverage-report-generator is called with an invalid 'reporttypes' input id: invalid-reporttypes if: always() continue-on-error: true # This is needed because we expect the step to fail but we need it to "pass" in order for the test job to succeed. uses: ./ with: - reports: '${{ env.REPORTS_INPUT_VALID }}' - targetdir: '${{ env.TARGETDIR_INPUT_REPORTTYPES }}' + reports: '${{ env.REPORTS_INPUT }}' + targetdir: '${{ env.TARGETDIR_INPUT }}' reporttypes: 'BarkdownSummary' verbosity: 'Info' @@ -151,27 +161,42 @@ jobs: if: always() run: ./test/assert-values-match.sh --name "step outcome" --expected "failure" --actual "${{ steps.invalid-reporttypes.outcome }}" - - name: 2c - And the 'error-reason' output should be '${{ env.ERROR_REASON_OUTPUT_REPORTTYPES }}' + - name: 2c - And the 'error-reason' output should be '${{ env.ERROR_REASON }}' if: always() - run: ./test/assert-values-match.sh --name "error-reason output" --expected "${{ env.ERROR_REASON_OUTPUT_REPORTTYPES }}" --actual "${{ steps.invalid-reporttypes.outputs.error-reason }}" + run: ./test/assert-values-match.sh --name "error-reason output" --expected "${{ env.ERROR_REASON }}" --actual "${{ steps.invalid-reporttypes.outputs.error-reason }}" - name: 2d - And the target directory should not exist if: always() - run: ./test/assert-dir-does-not-exist.sh --dir "${{ env.TARGETDIR_INPUT_REPORTTYPES }}" + run: ./test/assert-dir-does-not-exist.sh --dir "${{ env.TARGETDIR_INPUT }}" - name: '-------------------------------------------------------------------------------------------------------------' run: echo "" - name: ' TEST 3 - BAD REPORTS INPUT (DIR DOES NOT EXIST) ' run: echo "" + - name: Setup - Set variables for Test 3 + if: always() + run: | + errorReason="No matching files found" + reports="./test/input-files/bad-dir/*.xml" + targetDir="./test-results/dir-does-not-exist" + generatedFile="" + fileWithSubstring="" + + echo "ERROR_REASON=$errorReason" >> "$GITHUB_ENV" + echo "REPORTS_INPUT=$reports" >> "$GITHUB_ENV" + echo "TARGETDIR_INPUT=$targetDir" >> "$GITHUB_ENV" + echo "GENERATED_FILE=$generatedFile" >> "$GITHUB_ENV" + echo "FILE_WITH_SUBSTRING=$fileWithSubstring" >> "$GITHUB_ENV" + - name: 3a - When code-coverage-report-generator is called with a 'reports' input dir that does not exist id: dir-does-not-exist if: always() continue-on-error: true # This is needed because we expect the step to fail but we need it to "pass" in order for the test job to succeed. uses: ./ with: - reports: '${{ env.REPORTS_INPUT_BAD_DIR }}' - targetdir: '${{ env.TARGETDIR_INPUT_DOES_NOT_EXIST }}' + reports: '${{ env.REPORTS_INPUT }}' + targetdir: '${{ env.TARGETDIR_INPUT }}' reporttypes: 'MarkdownSummary' verbosity: 'Info' @@ -179,27 +204,42 @@ jobs: if: always() run: ./test/assert-values-match.sh --name "step outcome" --expected "failure" --actual "${{ steps.dir-does-not-exist.outcome }}" - - name: 3c - And the 'error-reason' output should be '${{ env.ERROR_REASON_OUTPUT_NO_MATCHING_FILES }}' + - name: 3c - And the 'error-reason' output should be '${{ env.ERROR_REASON }}' if: always() - run: ./test/assert-values-match.sh --name "error-reason output" --expected "${{ env.ERROR_REASON_OUTPUT_NO_MATCHING_FILES }}" --actual "${{ steps.dir-does-not-exist.outputs.error-reason }}" + run: ./test/assert-values-match.sh --name "error-reason output" --expected "${{ env.ERROR_REASON }}" --actual "${{ steps.dir-does-not-exist.outputs.error-reason }}" - - name: 3d - And the target directory should not exist + - name: 3d - And the target directory should be empty if: always() - run: ./test/assert-dir-does-not-exist.sh --dir "${{ env.TARGETDIR_INPUT_DOES_NOT_EXIST }}" + run: ./test/assert-dir-is-empty.sh --dir "${{ env.TARGETDIR_INPUT }}" - name: '-------------------------------------------------------------------------------------------------------------' run: echo "" - name: ' TEST 4 - BAD REPORTS INPUT (PATTERN DOES NOT MATCH ANY FILES) ' run: echo "" + - name: Setup - Set variables for Test 4 + if: always() + run: | + errorReason="No matching files found" + reports="./test/input-files/valid/*.opncvr.xml" + targetDir="./test-results/bad-pattern" + generatedFile="" + fileWithSubstring="" + + echo "ERROR_REASON=$errorReason" >> "$GITHUB_ENV" + echo "REPORTS_INPUT=$reports" >> "$GITHUB_ENV" + echo "TARGETDIR_INPUT=$targetDir" >> "$GITHUB_ENV" + echo "GENERATED_FILE=$generatedFile" >> "$GITHUB_ENV" + echo "FILE_WITH_SUBSTRING=$fileWithSubstring" >> "$GITHUB_ENV" + - name: 4a - When code-coverage-report-generator is called with a 'reports' input pattern that does not match any files id: bad-pattern if: always() continue-on-error: true # This is needed because we expect the step to fail but we need it to "pass" in order for the test job to succeed. uses: ./ with: - reports: '${{ env.REPORTS_INPUT_BAD_PATTERN }}' - targetdir: '${{ env.TARGETDIR_INPUT_BAD_PATTERN }}' + reports: '${{ env.REPORTS_INPUT }}' + targetdir: '${{ env.TARGETDIR_INPUT }}' reporttypes: 'MarkdownSummary' verbosity: 'Info' @@ -207,26 +247,41 @@ jobs: if: always() run: ./test/assert-values-match.sh --name "step outcome" --expected "failure" --actual "${{ steps.bad-pattern.outcome }}" - - name: 4c - And the 'error-reason' output should be '${{ env.ERROR_REASON_OUTPUT_NO_MATCHING_FILES }}' + - name: 4c - And the 'error-reason' output should be '${{ env.ERROR_REASON }}' if: always() - run: ./test/assert-values-match.sh --name "error-reason output" --expected "${{ env.ERROR_REASON_OUTPUT_NO_MATCHING_FILES }}" --actual "${{ steps.bad-pattern.outputs.error-reason }}" + run: ./test/assert-values-match.sh --name "error-reason output" --expected "${{ env.ERROR_REASON }}" --actual "${{ steps.bad-pattern.outputs.error-reason }}" - - name: 4d - And the target directory should not exist + - name: 4d - And the target directory should be empty if: always() - run: ./test/assert-dir-does-not-exist.sh --dir "${{ env.TARGETDIR_INPUT_BAD_PATTERN }}" + run: ./test/assert-dir-is-empty.sh --dir "${{ env.TARGETDIR_INPUT }}" - name: '-------------------------------------------------------------------------------------------------------------' run: echo "" - name: ' TEST 5 - MATCHING REPORTS ' run: echo "" + - name: Setup - Set variables for Test 5 + if: always() + run: | + errorReason="" + reports="./test/input-files/valid/*.xml" + targetDir="./test-results/matching-reports" + generatedFile="$targetDir/Summary.md" + fileWithSubstring="./test/expected-contents/matching-reports.md" + + echo "ERROR_REASON=$errorReason" >> "$GITHUB_ENV" + echo "REPORTS_INPUT=$reports" >> "$GITHUB_ENV" + echo "TARGETDIR_INPUT=$targetDir" >> "$GITHUB_ENV" + echo "GENERATED_FILE=$generatedFile" >> "$GITHUB_ENV" + echo "FILE_WITH_SUBSTRING=$fileWithSubstring" >> "$GITHUB_ENV" + - name: 5a - When code-coverage-report-generator is called with a 'reports' input pattern that matches files id: matching-reports if: always() uses: ./ with: - reports: '${{ env.REPORTS_INPUT_VALID }}' - targetdir: '${{ env.TARGETDIR_INPUT_MATCHING }}' + reports: '${{ env.REPORTS_INPUT }}' + targetdir: '${{ env.TARGETDIR_INPUT}}' reporttypes: ' MarkDoWNSummary;Html ' verbosity: ' InFo ' title: 'MyProj Code Coverage' @@ -242,9 +297,9 @@ jobs: - name: 5d - And the target directory should exist if: always() - run: ./test/assert-dir-exists.sh --dir "${{ env.TARGETDIR_INPUT_MATCHING }}" + run: ./test/assert-dir-exists.sh --dir "${{ env.TARGETDIR_INPUT }}" - - name: 5e - And '${{ env.ACTUAL_CONTENTS_MATCHING }}' should contain the expected contents + - name: 5e - And '${{ env.GENERATED_FILE }}' should contain the expected contents if: always() run: | # Comparing the Summary.md file will ensure that: @@ -252,22 +307,37 @@ jobs: # - The title is not included (reporttype=MarkDoWNSummary does not support it) # - None of the assemblies/classes/files have been filtered out because those inputs were not supplied - actualFile="${{ env.ACTUAL_CONTENTS_MATCHING }}" - expectedContentsFile="${{ env.EXPECTED_CONTENTS_MATCHING }}" - ./test/assert-file-contains-expected-content.sh --fileName $actualFile --expectedContents $expectedContentsFile + generatedFile="${{ env.GENERATED_FILE }}" + substringFile="${{ env.FILE_WITH_SUBSTRING }}" + ./test/assert-file-contains-substring.sh --fullFile $generatedFile --substringFile $substringFile - name: '-------------------------------------------------------------------------------------------------------------' run: echo "" - name: ' TEST 6 - ASSEMBLY FILTERS ' run: echo "" + - name: Setup - Set variables for Test 6 + if: always() + run: | + errorReason="" + reports="./test/input-files/valid/*.xml" + targetDir="./test-results/assembly-filters" + generatedFile="$targetDir/Summary.xml" + fileWithSubstring="./test/expected-contents/assembly-filters.xml" + + echo "ERROR_REASON=$errorReason" >> "$GITHUB_ENV" + echo "REPORTS_INPUT=$reports" >> "$GITHUB_ENV" + echo "TARGETDIR_INPUT=$targetDir" >> "$GITHUB_ENV" + echo "GENERATED_FILE=$generatedFile" >> "$GITHUB_ENV" + echo "FILE_WITH_SUBSTRING=$fileWithSubstring" >> "$GITHUB_ENV" + - name: 6a - When code-coverage-report-generator is called with assembly filters id: assembly-filters if: always() uses: ./ with: - reports: '${{ env.REPORTS_INPUT_VALID }}' - targetdir: '${{ env.TARGETDIR_INPUT_ASSEMBLY_FILTERS }}' + reports: '${{ env.REPORTS_INPUT }}' + targetdir: '${{ env.TARGETDIR_INPUT }}' reporttypes: 'XmlSummary' title: 'MyProj Code Coverage AssemblyFilter' assemblyfilters: '+MyProj*;-MyProj.Tests.*' @@ -283,9 +353,9 @@ jobs: - name: 6d - And the target directory should exist if: always() - run: ./test/assert-dir-exists.sh --dir "${{ env.TARGETDIR_INPUT_ASSEMBLY_FILTERS }}" + run: ./test/assert-dir-exists.sh --dir "${{ env.TARGETDIR_INPUT }}" - - name: 6e - And '${{ env.ACTUAL_CONTENTS_ASSEMBLY_FILTERS }}' should contain the expected contents + - name: 6e - And '${{ env.GENERATED_FILE }}' should contain the expected contents if: always() run: | # Comparing the Summary.xml file will ensure that: @@ -293,22 +363,37 @@ jobs: # - The title is included (reporttype=XmlSummary supports it) # - The assemblies have been filtered - actualFile="${{ env.ACTUAL_CONTENTS_ASSEMBLY_FILTERS }}" - expectedContentsFile="${{ env.EXPECTED_CONTENTS_ASSEMBLY_FILTERS }}" - ./test/assert-file-contains-expected-content.sh --fileName $actualFile --expectedContents $expectedContentsFile + generatedFile="${{ env.GENERATED_FILE }}" + substringFile="${{ env.FILE_WITH_SUBSTRING }}" + ./test/assert-file-contains-substring.sh --fullFile $generatedFile --substringFile $substringFile - name: '-------------------------------------------------------------------------------------------------------------' run: echo "" - name: ' TEST 7 - CLASS FILTERS ' run: echo "" + - name: Setup - Set variables for Test 7 + if: always() + run: | + errorReason="" + reports="./test/input-files/valid/*.xml" + targetDir="./test-results/class-filters" + generatedFile="$targetDir/Summary.json" + fileWithSubstring="./test/expected-contents/class-filters.json" + + echo "ERROR_REASON=$errorReason" >> "$GITHUB_ENV" + echo "REPORTS_INPUT=$reports" >> "$GITHUB_ENV" + echo "TARGETDIR_INPUT=$targetDir" >> "$GITHUB_ENV" + echo "GENERATED_FILE=$generatedFile" >> "$GITHUB_ENV" + echo "FILE_WITH_SUBSTRING=$fileWithSubstring" >> "$GITHUB_ENV" + - name: 7a - When code-coverage-report-generator is called with class filters id: class-filters if: always() uses: ./ with: - reports: '${{ env.REPORTS_INPUT_VALID }}' - targetdir: '${{ env.TARGETDIR_INPUT_CLASS_FILTERS }}' + reports: '${{ env.REPORTS_INPUT }}' + targetdir: '${{ env.TARGETDIR_INPUT }}' reporttypes: 'JsonSummary' classfilters: '-MyProj.Tests.*;-MyProj.Core*' tag: 'class-filter-tag' @@ -323,9 +408,9 @@ jobs: - name: 7d - And the target directory should exist if: always() - run: ./test/assert-dir-exists.sh --dir "${{ env.TARGETDIR_INPUT_CLASS_FILTERS }}" + run: ./test/assert-dir-exists.sh --dir "${{ env.TARGETDIR_INPUT }}" - - name: 7e - And '${{ env.ACTUAL_CONTENTS_CLASS_FILTERS }}' should contain the expected contents + - name: 7e - And '${{ env.GENERATED_FILE }}' should contain the expected contents if: always() run: | # Comparing the Summary.json file will ensure that: @@ -333,22 +418,37 @@ jobs: # - No title is included (the input was not supplied) # - The classes have been filtered - actualFile="${{ env.ACTUAL_CONTENTS_CLASS_FILTERS }}" - expectedContentsFile="${{ env.EXPECTED_CONTENTS_CLASS_FILTERS }}" - ./test/assert-file-contains-expected-content.sh --fileName $actualFile --expectedContents $expectedContentsFile + generatedFile="${{ env.GENERATED_FILE }}" + substringFile="${{ env.FILE_WITH_SUBSTRING }}" + ./test/assert-file-contains-substring.sh --fullFile $generatedFile --substringFile $substringFile - name: '-------------------------------------------------------------------------------------------------------------' run: echo "" - name: ' TEST 8 - FILE FILTERS ' run: echo "" + - name: Setup - Set variables for Test 8 + if: always() + run: | + errorReason="" + reports="./test/input-files/valid/*.xml" + targetDir="./test-results/file-filters" + generatedFile="$targetDir/Summary.txt" + fileWithSubstring="./test/expected-contents/file-filters.txt" + + echo "ERROR_REASON=$errorReason" >> "$GITHUB_ENV" + echo "REPORTS_INPUT=$reports" >> "$GITHUB_ENV" + echo "TARGETDIR_INPUT=$targetDir" >> "$GITHUB_ENV" + echo "GENERATED_FILE=$generatedFile" >> "$GITHUB_ENV" + echo "FILE_WITH_SUBSTRING=$fileWithSubstring" >> "$GITHUB_ENV" + - name: 8a - When code-coverage-report-generator is called with file filters id: file-filters if: always() uses: ./ with: - reports: '${{ env.REPORTS_INPUT_VALID }}' - targetdir: '${{ env.TARGETDIR_INPUT_FILE_FILTERS }}' + reports: '${{ env.REPORTS_INPUT }}' + targetdir: '${{ env.TARGETDIR_INPUT }}' reporttypes: 'TextSummary' filefilters: '+*EnumExtensions.cs' tag: 'file-filter-tag' @@ -363,9 +463,9 @@ jobs: - name: 8d - And the target directory should exist if: always() - run: ./test/assert-dir-exists.sh --dir "${{ env.TARGETDIR_INPUT_FILE_FILTERS }}" + run: ./test/assert-dir-exists.sh --dir "${{ env.TARGETDIR_INPUT }}" - - name: 8e - And '${{ env.ACTUAL_CONTENTS_FILE_FILTERS }}' should contain the expected contents + - name: 8e - And '${{ env.GENERATED_FILE }}' should contain the expected contents if: always() run: | # Comparing the Summary.txt file will ensure that: @@ -373,6 +473,6 @@ jobs: # - No title is included (the input was not supplied) # - The files have been filtered - actualFile="${{ env.ACTUAL_CONTENTS_FILE_FILTERS }}" - expectedContentsFile="${{ env.EXPECTED_CONTENTS_FILE_FILTERS }}" - ./test/assert-file-contains-expected-content.sh --fileName $actualFile --expectedContents $expectedContentsFile + generatedFile="${{ env.GENERATED_FILE }}" + substringFile="${{ env.FILE_WITH_SUBSTRING }}" + ./test/assert-file-contains-substring.sh --fullFile $generatedFile --substringFile $substringFile diff --git a/dist/index.js b/dist/index.js index 419107f..b8fb06d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3390,8 +3390,9 @@ async function run() { if (!areReportTypesValid(reportTypes)) return; let output = ''; const toolPath = 'reportgeneratortool'; - core.info('Detecting .NET Core SDK...'); + core.info('\nDetecting .NET Core SDK...'); try { + core.startGroup('dotnet version output'); await exec.exec('dotnet', ['--version'], { listeners: { stdout: data => { @@ -3399,8 +3400,10 @@ async function run() { } } }); - core.info(`Detected .NET Core SDK version '${output}'`); + core.endGroup(); + core.info(`Detected .NET Core SDK version '${output.trim()}'`); } catch (error) { + core.endGroup(); const shortMsg = 'dotnet not available'; core.setOutput('error-reason', shortMsg); core.setFailed(shortMsg); @@ -3411,13 +3414,14 @@ async function run() { core.info(" dotnet-version: '8.x' # 5.0 or higher"); return; } - core.info('Installing ReportGenerator global tool...'); - core.info('https://www.nuget.org/packages/dotnet-reportgenerator-globaltool'); + core.info('\nChecking for ReportGenerator global tool...'); if (fs.existsSync(toolPath)) { core.info('ReportGenerator global tool already installed'); } else { output = ''; try { + core.startGroup('Installing ReportGenerator global tool'); + core.info('https://www.nuget.org/packages/dotnet-reportgenerator-globaltool'); await exec.exec( 'dotnet', [ @@ -3438,13 +3442,15 @@ async function run() { } } ); + core.endGroup(); core.info('Successfully installed ReportGenerator global tool'); } catch (error) { + core.endGroup(); core.setFailed('Failed to install ReportGenerator global tool'); return; } } - core.info('Executing ReportGenerator'); + core.info('\nExecuting ReportGenerator global tool'); try { let args = [ `-reports:${core.getInput('reports')}`, @@ -3457,6 +3463,7 @@ async function run() { `-title:${core.getInput('title')}`, `-tag:${core.getInput('tag')}` ]; + core.startGroup('reportgenerator output'); await exec.exec(`${toolPath}/reportgenerator`, args, { listeners: { stdout: data => { @@ -3464,8 +3471,10 @@ async function run() { } } }); + core.endGroup(); core.info('Successfully executed ReportGenerator'); } catch (error) { + core.endGroup(); if (output.includes('No matching files found.')) { const shortMsg = 'No matching files found'; core.setOutput('error-reason', shortMsg); diff --git a/src/reportgenerator.js b/src/reportgenerator.js index f64a9b0..757a514 100644 --- a/src/reportgenerator.js +++ b/src/reportgenerator.js @@ -15,8 +15,9 @@ async function run() { let output = ''; const toolPath = 'reportgeneratortool'; - core.info('Detecting .NET Core SDK...'); + core.info('\nDetecting .NET Core SDK...'); try { + core.startGroup('dotnet version output'); await exec.exec('dotnet', ['--version'], { listeners: { stdout: data => { @@ -24,8 +25,10 @@ async function run() { } } }); - core.info(`Detected .NET Core SDK version '${output}'`); + core.endGroup(); + core.info(`Detected .NET Core SDK version '${output.trim()}'`); } catch (error) { + core.endGroup(); const shortMsg = 'dotnet not available'; core.setOutput('error-reason', shortMsg); core.setFailed(shortMsg); @@ -37,14 +40,15 @@ async function run() { return; } - core.info('Installing ReportGenerator global tool...'); - core.info('https://www.nuget.org/packages/dotnet-reportgenerator-globaltool'); + core.info('\nChecking for ReportGenerator global tool...'); if (fs.existsSync(toolPath)) { core.info('ReportGenerator global tool already installed'); } else { output = ''; try { + core.startGroup('Installing ReportGenerator global tool'); + core.info('https://www.nuget.org/packages/dotnet-reportgenerator-globaltool'); await exec.exec( 'dotnet', [ @@ -65,14 +69,16 @@ async function run() { } } ); + core.endGroup(); core.info('Successfully installed ReportGenerator global tool'); } catch (error) { + core.endGroup(); core.setFailed('Failed to install ReportGenerator global tool'); return; } } - core.info('Executing ReportGenerator'); + core.info('\nExecuting ReportGenerator global tool'); try { let args = [ `-reports:${core.getInput('reports')}`, @@ -85,7 +91,7 @@ async function run() { `-title:${core.getInput('title')}`, `-tag:${core.getInput('tag')}` ]; - + core.startGroup('reportgenerator output'); await exec.exec(`${toolPath}/reportgenerator`, args, { listeners: { stdout: data => { @@ -93,8 +99,10 @@ async function run() { } } }); + core.endGroup(); core.info('Successfully executed ReportGenerator'); } catch (error) { + core.endGroup(); if (output.includes('No matching files found.')) { const shortMsg = 'No matching files found'; core.setOutput('error-reason', shortMsg); diff --git a/test/assert-dir-does-not-exist.sh b/test/assert-dir-does-not-exist.sh index c56f0bd..16bed8b 100755 --- a/test/assert-dir-does-not-exist.sh +++ b/test/assert-dir-does-not-exist.sh @@ -18,6 +18,7 @@ Asserting '$dir' does not exist" if [ -d "$dir" ]; then echo "The target directory exists when it should not." + ls -r $dir exit 1 else echo "The target directory does not exist, which is expected." diff --git a/test/assert-dir-exists.sh b/test/assert-dir-exists.sh index 3efbb3e..a197693 100755 --- a/test/assert-dir-exists.sh +++ b/test/assert-dir-exists.sh @@ -17,7 +17,8 @@ echo " Asserting '$dir' exists" if [ -d "$dir" ]; then - echo "The target directory exists, which is expected." + echo "The target directory exists, which is expected. It contains:" + ls -r $dir else echo "The target directory does not exist but it should." exit 1 diff --git a/test/assert-dir-is-empty.sh b/test/assert-dir-is-empty.sh new file mode 100755 index 0000000..0222eed --- /dev/null +++ b/test/assert-dir-is-empty.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +dir='' + +for arg in "$@"; do + case $arg in + --dir) + dir=$2 + shift # Remove argument --dir from `$@` + shift # Remove argument value from `$@` + ;; + esac +done + +echo " +Asserting '$dir' exists and that it is empty" + +if [ -d "$dir" ]; then + echo "The target directory exists, which is expected." +else + echo "The target directory does not exist but it should." + exit 1 +fi + +if [ -z "$(ls -A $dir)" ]; then + echo "The target directory is empty, which is expected." +else + echo "The target directory is not empty but it should be." + echo "These items exist under the directory:" + ls -r $dir + exit 1 +fi \ No newline at end of file diff --git a/test/assert-file-contains-expected-content.sh b/test/assert-file-contains-expected-content.sh deleted file mode 100755 index 960b314..0000000 --- a/test/assert-file-contains-expected-content.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -name='' -expectedContents='' -fileName='' - -for arg in "$@"; do - case $arg in - --name) - name=$2 - shift # Remove argument --name from `$@` - shift # Remove argument value from `$@` - ;; - --expectedContents) - expectedContents=$2 - shift # Remove argument --expected from `$@` - shift # Remove argument value from `$@` - ;; - --fileName) - fileName=$2 - shift # Remove argument --actual from `$@` - shift # Remove argument value from `$@` - ;; - - esac -done - -echo " -Asserting file contents match: -File with expected contents: '$expectedContents' -File with actual contents: '$fileName'" - -# First make sure the actual file exists -if [ -f "$fileName" ] -then - echo "The file with actual contents exists which is expected." - actualFileContents=$(cat $fileName) -else - echo "The file with actual contents does not exist which is not expected" - exit 1 -fi -expectedFileContents=$(cat $expectedContents) - -# Then print the contents -echo "::group::Expected file contents" -echo "$expectedFileContents" -echo "::endgroup::" - -echo "::group::Actual file contents" -echo "$actualFileContents" -echo "::endgroup::" - -# And finally compare the contents -if echo "$actualFileContents" | grep -q "$expectedFileContents"; then - echo "The actual contents contain the expected cotnents, which is expected." -else - echo "The actual contents do not contain the expected contents, which is not expected." - exit 1 -fi \ No newline at end of file diff --git a/test/assert-file-contains-substring.sh b/test/assert-file-contains-substring.sh new file mode 100755 index 0000000..4aabab7 --- /dev/null +++ b/test/assert-file-contains-substring.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +substringFile='' +fullFile='' + +for arg in "$@"; do + case $arg in + --substringFile) + substringFile=$2 + shift # Remove argument --substringFile from `$@` + shift # Remove argument value from `$@` + ;; + --fullFile) + fullFile=$2 + shift # Remove argument --fullFile from `$@` + shift # Remove argument value from `$@` + ;; + + esac +done + +# Print out the file contents for easy manual comparison +echo " +Asserting full file contains substring: +File with full contents: '$fullFile' +File with substring: '$substringFile'" + +fullFileContents=$(cat $fullFile) +echo "::group::Full file contents" +echo "'$fullFileContents'" +echo "::endgroup::" + +substringContents=$(cat $substringFile) +echo "::group::Substring" +echo "'$substringContents'" +echo "::endgroup::" + + +# Now compare the contents +if echo "$fullFileContents" | grep -q "$substringContents"; then + echo "The file contains the substring, which is expected." +else + echo "The file does not contain the substring, which is not expected." + exit 1 +fi \ No newline at end of file diff --git a/test/expected-contents/class-filters.json b/test/expected-contents/class-filters.json index d7dc69c..287fba5 100644 --- a/test/expected-contents/class-filters.json +++ b/test/expected-contents/class-filters.json @@ -1,4 +1,4 @@ - "parser": "OpenCoverParser", +parser": "OpenCoverParser", "assemblies": 3, "classes": 4, "files": 4, @@ -20,6 +20,4 @@ { "name": "MyProj.Core", "classes": 0, "coverage": null, "coveredlines": 0, "coverablelines": 0, "totallines": 0, "branchcoverage": null, "coveredbranches": 0, "totalbranches": 0, "classesinassembly": [ ] }, { "name": "MyProj.Tests.Shared", "classes": 0, "coverage": null, "coveredlines": 0, "coverablelines": 0, "totallines": 0, "branchcoverage": null, "coveredbranches": 0, "totalbranches": 0, "classesinassembly": [ - ] } ] - } -} \ No newline at end of file + ] } ] \ No newline at end of file diff --git a/test/expected-contents/file-filters.txt b/test/expected-contents/file-filters.txt index 3c74f1f..2d3e134 100644 --- a/test/expected-contents/file-filters.txt +++ b/test/expected-contents/file-filters.txt @@ -13,4 +13,4 @@ MyProj MyProj.Core 90.9% MyProj.Core.EnumExtensions 90.9% -MyProj.Tests.Shared +MyProj.Tests.Shared \ No newline at end of file diff --git a/test/expected-contents/matching-reports.md b/test/expected-contents/matching-reports.md index eadd2ae..13c4a41 100644 --- a/test/expected-contents/matching-reports.md +++ b/test/expected-contents/matching-reports.md @@ -26,4 +26,4 @@ |**MyProj.Tests.Shared**|**136**|**0**|**136**|**0**|**100%**|**0**|**0**|****| |MyProj.Tests.Shared.TestGrades|4|0|4|0|100%|0|0|| |MyProj.Tests.Shared.TestPositions|125|0|125|0|100%|0|0|| -|MyProj.Tests.Shared.TestRoles|7|0|7|0|100%|0|0|| +|MyProj.Tests.Shared.TestRoles|7|0|7|0|100%|0|0|| \ No newline at end of file