From 761e34a93ab0688c5f9ca680d669541fbfe0549e Mon Sep 17 00:00:00 2001 From: walkowif <59475134+walkowif@users.noreply.github.com> Date: Wed, 6 Dec 2023 14:04:31 +0100 Subject: [PATCH] Add `storage-subdirectory` input (#36) Closes https://github.com/insightsengineering/coverage-action/issues/35 --- action.yml | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/action.yml b/action.yml index 720724f..c06d76a 100644 --- a/action.yml +++ b/action.yml @@ -33,6 +33,10 @@ inputs: description: Branch to diff against. required: false default: main + storage-subdirectory: + description: Subdirectory in the diff-storage branch where the XML reports will be stored. + required: false + default: "." diff-storage: description: Branch where coverage reports are stored for diff purposes. required: false @@ -132,19 +136,20 @@ runs: - name: Generate diff against ${{ inputs.diff-branch }} if: contains(inputs.diff, 'true') run: | + echo "storage_subdirectory = '${{ inputs.storage-subdirectory }}'" pushd ${{ inputs.diff-storage }} git checkout ${{ inputs.diff-storage }} || touch ${{ inputs.diff-storage }}-not-found popd - if [[ -f "${{ inputs.diff-storage }}/data/${{ inputs.diff-branch }}/coverage.xml" && (! -f ${{ inputs.diff-storage }}-not-found) ]] + if [[ -f "${{ inputs.diff-storage }}/data/${{ inputs.diff-branch }}/${{ inputs.storage-subdirectory }}/coverage.xml" && (! -f ${{ inputs.diff-storage }}-not-found) ]] then { - pycobertura diff --no-color --no-source ${{ inputs.diff-storage }}/data/${{ inputs.diff-branch }}/coverage.xml \ + pycobertura diff --no-color --no-source ${{ inputs.diff-storage }}/data/${{ inputs.diff-branch }}/${{ inputs.storage-subdirectory }}/coverage.xml \ ${{ inputs.path }} \ --output .coverage-output.diff && pycobertura_status=$? || pycobertura_status=$? # Save status both in case of success and failure. echo "pycobertura_status=$pycobertura_status" >> $GITHUB_ENV cat .coverage-output.diff } else { - echo "${{ inputs.diff-storage }}/data/${{ inputs.diff-branch }}/coverage.xml not found! Not diffing." + echo "${{ inputs.diff-storage }}/data/${{ inputs.diff-branch }}/${{ inputs.storage-subdirectory }}/coverage.xml not found! Not diffing." } fi shell: bash @@ -161,8 +166,7 @@ runs: echo "coverage_total=$(cat .coverage-total)" >> $GITHUB_OUTPUT BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} echo "diff_storage_branch=$BRANCH" >> $GITHUB_ENV - mkdir -p ${{ inputs.diff-storage }}/data - mkdir -p ${{ inputs.diff-storage }}/data/${BRANCH} + mkdir -p ${{ inputs.diff-storage }}/data/${BRANCH}/${{ inputs.storage-subdirectory }} shell: bash # Use the output from the `coverage_percent` step @@ -182,7 +186,7 @@ runs: steps.coverage_percent.outputs.coverage_total > 30 && 'red,red,orange' || steps.coverage_percent.outputs.coverage_total > 20 && 'red,red,red,orange' || 'red' }} - path: ${{ inputs.diff-storage }}/data/${{ env.diff_storage_branch }}/badge.svg + path: ${{ inputs.diff-storage }}/data/${{ env.diff_storage_branch }}/${{ inputs.storage-subdirectory }}/badge.svg - name: Commit badge working-directory: ${{ inputs.diff-storage }}/data @@ -191,7 +195,7 @@ runs: git config --global user.name "github-actions[bot]" git switch ${{ inputs.diff-storage }} || true git pull origin ${{ inputs.diff-storage }} - git add "${{ env.diff_storage_branch }}/badge.svg" + git add "${{ env.diff_storage_branch }}/${{ inputs.storage-subdirectory }}/badge.svg" git commit -m "Add/Update badge: ${{ github.sha }}" || true shell: bash @@ -224,7 +228,7 @@ runs: then { # URL encoding for branch name URL_ENCODED_BRANCH=$(python3 -c 'import urllib.parse; print(urllib.parse.quote_plus("${{ env.diff_storage_branch }}"))') - echo -e "![badge](https://raw.githubusercontent.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ inputs.diff-storage }}/data/${URL_ENCODED_BRANCH}/badge.svg)\n\n" > .coverage-output.final + echo -e "![badge](https://raw.githubusercontent.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ inputs.diff-storage }}/data/${URL_ENCODED_BRANCH}/${{ inputs.storage-subdirectory }}/badge.svg)\n\n" > .coverage-output.final } else { echo -e "🧪 Test coverage: ${{ steps.coverage_percent.outputs.coverage_total }}%\n\n" > .coverage-output.final @@ -280,8 +284,8 @@ runs: git switch ${{ inputs.diff-storage }} git pull origin ${{ inputs.diff-storage }} filename=$(basename ${{ inputs.path }}) - mv ../coverage-action/${filename} ./data/${{ env.diff_storage_branch }}/coverage.xml - git add -f "./data/${{ env.diff_storage_branch }}/coverage.xml" + mv ../coverage-action/${filename} ./data/${{ env.diff_storage_branch }}/${{ inputs.storage-subdirectory }}/coverage.xml + git add -f "./data/${{ env.diff_storage_branch }}/${{ inputs.storage-subdirectory }}/coverage.xml" git commit -m "Coverage report for ${{ github.sha }}" || true shell: bash