Skip to content

Commit

Permalink
[CI] Make coverage generate pull request comment instead of blocking …
Browse files Browse the repository at this point in the history
…validation (#938)

* [ci] moved coverage to dedicated file

* squashed test commits
  • Loading branch information
hugsy committed Apr 16, 2023
1 parent 9848239 commit b1a1b2a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/coverage.yml
@@ -0,0 +1,50 @@
name: CI Coverage

on: [pull_request]

jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Run test coverage
id: get_coverage
env:
ALLOWED_MARGIN: 0.01
MIN_COVERAGE: 70
run: |
sudo apt-get update
sudo apt-get install -y gdb-multiarch python3-dev python3-pip python3-wheel python3-setuptools git cmake gcc g++ pkg-config libglib2.0-dev gdbserver qemu-user
sudo python3 -m pip install --upgrade pip
echo PY_VER=`gdb -q -nx -ex "pi print('.'.join(map(str, sys.version_info[:2])))" -ex quit` >> $GITHUB_ENV
echo GEF_CI_NB_CPU=`grep -c ^processor /proc/cpuinfo` >> $GITHUB_ENV
echo GEF_CI_ARCH=`uname --processor` >> $GITHUB_ENV
python${{ env.PY_VER }} -m pip install --user --upgrade -r tests/requirements.txt
current_score=$(curl --silent https://hugsy.github.io/gef/coverage/gef_py.html | grep pc_cov | sed 's?.*<span class="pc_cov">\([^%]*\)%</span>?\1?g')
bash scripts/generate-coverage-docs.sh
new_score=$(cat docs/coverage/gef_py.html | grep pc_cov | sed 's?.*<span class="pc_cov">\([^%]*\)%</span>?\1?g')
diff_score=$(python -c "print(${new_score} - ${current_score})")
commit=$(git rev-parse HEAD)
echo "commit=${commit}" >> $GITHUB_OUTPUT
echo "new_coverage_score=${new_score}" >> $GITHUB_OUTPUT
echo "current_coverage_score=${current_score}" >> $GITHUB_OUTPUT
echo "diff_score=${diff_score}" >> $GITHUB_OUTPUT
- uses: actions/github-script@v6
env:
COMMIT: ${{ steps.get_coverage.outputs.commit }}
SCORE_OLD: ${{ steps.get_coverage.outputs.current_coverage_score }}
SCORE_NEW: ${{ steps.get_coverage.outputs.new_coverage_score }}
SCORE_DIFF: ${{ steps.get_coverage.outputs.diff_score }}
with:
script: |
const comment = `## 🤖 Coverage Update
* Commit: ${process.env.COMMIT}
* Current Coverage: ${process.env.SCORE_OLD}%
* New Coverage: ${process.env.SCORE_NEW}%
* Diff: ${process.env.SCORE_DIFF}
`;
const { owner, repo, number } = context.issue;
await github.rest.issues.createComment({ owner, repo, issue_number: number, body: comment });
12 changes: 0 additions & 12 deletions .github/workflows/run-tests.yml
Expand Up @@ -74,15 +74,3 @@ jobs:
run: |
python${{ env.PY_VER }} -m pylint --rcfile=$(pwd)/.pylintrc gef.py tests/*/*.py
- name: Run test coverage
if: matrix.os == 'ubuntu-22.04'
env:
ALLOWED_MARGIN: 0.01
MIN_COVERAGE: 70
run: |
current_score=$(curl --silent https://hugsy.github.io/gef/coverage/gef_py.html | grep pc_cov | sed 's?.*<span class="pc_cov">\([^%]*\)%</span>?\1?g')
bash scripts/generate-coverage-docs.sh
new_score=$(cat docs/coverage/gef_py.html | grep pc_cov | sed 's?.*<span class="pc_cov">\([^%]*\)%</span>?\1?g')
echo "New coverage score: ${new_score}% (current ${current_score}%)"
python${{ env.PY_VER }} -c "( ${new_score} < ${{ env.MIN_COVERAGE}} ) and exit(1)"
python${{ env.PY_VER }} -c "(( abs( ${current_score}-${new_score}) / ${current_score} ) >= ${{ env.ALLOWED_MARGIN}}) and exit(2)"

0 comments on commit b1a1b2a

Please sign in to comment.