Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add storage-subdirectory input #36

Merged
merged 5 commits into from
Dec 6, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ inputs:
description: Branch to diff against.
required: false
default: main
test-type:
description: |
Name of test type e.g. unit, integration, etc.
In case this action is run multiple times for different test types for the same repository,
test coverage will be compared between branches for each given test type separately.
walkowif marked this conversation as resolved.
Show resolved Hide resolved
required: false
default: ""
walkowif marked this conversation as resolved.
Show resolved Hide resolved
diff-storage:
description: Branch where coverage reports are stored for diff purposes.
required: false
Expand Down Expand Up @@ -79,6 +86,15 @@ runs:
id: branch-names
uses: tj-actions/branch-names@v6.3

- name: Set variables
run: |
if [[ "${{ inputs.test-type }}" != "" ]]; then
echo "test_type_subdirectory=${{ inputs.test-type }}/" >> $GITHUB_ENV
else
echo "test_type_subdirectory=" >> $GITHUB_ENV
fi
shell: bash

- name: Generate text report
run: |
mkdir -p coverage-action
Expand Down Expand Up @@ -132,19 +148,20 @@ runs:
- name: Generate diff against ${{ inputs.diff-branch }}
if: contains(inputs.diff, 'true')
run: |
echo "test_type_subdirectory = '${{ env.test_type_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 }}/${{ env.test_type_subdirectory }}coverage.xml" && (! -f ${{ inputs.diff-storage }}-not-found) ]]
walkowif marked this conversation as resolved.
Show resolved Hide resolved
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 }}/${{ env.test_type_subdirectory }}coverage.xml \
walkowif marked this conversation as resolved.
Show resolved Hide resolved
${{ 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 }}/${{ env.test_type_subdirectory }}coverage.xml not found! Not diffing."
walkowif marked this conversation as resolved.
Show resolved Hide resolved
}
fi
shell: bash
Expand All @@ -163,6 +180,7 @@ runs:
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}/${{ env.test_type_subdirectory }}
walkowif marked this conversation as resolved.
Show resolved Hide resolved
shell: bash

# Use the output from the `coverage_percent` step
Expand All @@ -182,7 +200,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 }}/${{ env.test_type_subdirectory }}badge.svg
walkowif marked this conversation as resolved.
Show resolved Hide resolved

- name: Commit badge
working-directory: ${{ inputs.diff-storage }}/data
Expand All @@ -191,7 +209,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 }}/${{ env.test_type_subdirectory }}badge.svg"
walkowif marked this conversation as resolved.
Show resolved Hide resolved
git commit -m "Add/Update badge: ${{ github.sha }}" || true
shell: bash

Expand Down Expand Up @@ -224,7 +242,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}/${{ env.test_type_subdirectory }}badge.svg)\n\n" > .coverage-output.final
walkowif marked this conversation as resolved.
Show resolved Hide resolved
}
else {
echo -e "🧪 Test coverage: ${{ steps.coverage_percent.outputs.coverage_total }}%\n\n" > .coverage-output.final
Expand Down Expand Up @@ -280,8 +298,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 }}/${{ env.test_type_subdirectory }}coverage.xml
git add -f "./data/${{ env.diff_storage_branch }}/${{ env.test_type_subdirectory }}coverage.xml"
walkowif marked this conversation as resolved.
Show resolved Hide resolved
git commit -m "Coverage report for ${{ github.sha }}" || true
shell: bash

Expand Down