Skip to content

Instantly share code, notes, and snippets.

@heiglandreas
Last active March 26, 2023 13:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heiglandreas/690fd84a3fff9a4aede2c54fba80bfaf to your computer and use it in GitHub Desktop.
Save heiglandreas/690fd84a3fff9a4aede2c54fba80bfaf to your computer and use it in GitHub Desktop.
Patch-Coverage as GitHub Action
jobs:
patch-coverage:
# Fail when untested lines are found
steps:
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
tools: "phive"
coverage: "xdebug"
- name: "Install tools"
if: ${{ github.ref != 'refs/heads/master' }}
run: "phive install --trust-gpg-keys 4AA394086372C20A"
- name: "create modified files list"
if: ${{ github.ref != 'refs/heads/master' }}
run: |
git fetch origin master:master
git diff `git merge-base master HEAD` > /tmp/patch.txt
- name: "Run tests"
run: "XDEBUG_MODE=coverage ./tools/phpunit --coverage-php /tmp/${GITHUB_SHA}_coverage.cov"
- name: "Check patch coverage"
if: ${{ github.ref != 'refs/heads/master' }}
run: |
./tools/phpcov patch-coverage --path-prefix $PWD /tmp/${GITHUB_SHA}_coverage.cov /tmp/patch.txt
jobs:
patch-coverage:
# Allow untested lines but report all untested lines as comment in the PR
steps:
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
tools: "phive"
coverage: "xdebug"
- name: "Install tools"
if: ${{ github.ref != 'refs/heads/master' }}
run: "phive install --trust-gpg-keys 4AA394086372C20A"
- name: "create modified files list"
if: ${{ github.ref != 'refs/heads/master' }}
run: |
git fetch origin master:master
git diff `git merge-base master HEAD` > /tmp/patch.txt
- name: "Run tests"
run: "XDEBUG_MODE=coverage ./tools/phpunit --coverage-php /tmp/${GITHUB_SHA}_coverage.cov"
- name: "Check patch coverage"
if: ${{ github.ref != 'refs/heads/master' }}
id: patchcoverage
run: |
RESULT=$(./tools/phpcov patch-coverage --path-prefix $PWD /tmp/${GITHUB_SHA}_coverage.cov /tmp/patch.txt || echo "")
PATHS=$(echo "$RESULT" | tail -n+6);
PATHS="${PATHS//'%'/'%25'}"
PATHS="${PATHS//$'\n'/'%0A'}"
PATHS="${PATHS//$'\r'/'%0D'}"
echo "::set-output name=paths::$(echo "$PATHS")"
echo "::set-output name=changed::$(echo "$RESULT" | head -n 3 | tail -n 1)"
- uses: jwalton/gh-find-current-pr@v1
id: findPr
- name: "Find Comment"
uses: "peter-evans/find-comment@v1"
if: ${{ steps.findPr.outputs.pr && github.ref != 'refs/heads/master' }}
id: fc
with:
issue-number: ${{ steps.findPr.outputs.pr }}
body-includes: "This PullRequest will introduce the following untested lines of code"
- name: "Create or update comment"
uses: "peter-evans/create-or-update-comment@v1"
if: ${{ steps.findPr.outputs.pr && github.ref != 'refs/heads/master'}}
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ steps.findPr.outputs.pr }}
body: |
**${{ steps.patchcoverage.outputs.changed }}**
This PullRequest will introduce the following untested lines of code:
${{ steps.patchcoverage.outputs.paths }}
edit-mode: replace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment