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 all 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
24 changes: 14 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down