Skip to content

Merge pull request #25 from trendmicro/fix/pypa-action #86

Merge pull request #25 from trendmicro/fix/pypa-action

Merge pull request #25 from trendmicro/fix/pypa-action #86

Workflow file for this run

name: coverage
on:
push:
branches: [main, develop]
pull_request:
branches: [develop]
jobs:
coverage:
runs-on: ubuntu-latest
outputs:
total: ${{ steps.cov.outputs.total }}
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install dependencies
run: pip install -e ".[dev]"
- name: Run pytest coverage
id: cov
shell: bash {0}
run: |
pytest --mock-url="${{ secrets.MOCK_URL }}" --cov-fail-under=95 --cov-report=term-missing --cov-report=xml --cov=pytmv1 --log-cli-level="DEBUG" --verbose
rc=$?
echo "total=$(head -2 coverage.xml|grep -Po 'line-rate="\K\d{1}\.?\d{0,4}' |awk '{print $1 * 100}'|cut -d. -f1)" >> $GITHUB_OUTPUT
exit $rc
badge:
runs-on: ubuntu-latest
needs: coverage
if: ${{ always() && github.event_name == 'push' && needs.coverage.outputs.total != '' }}
steps:
- name: Install curl
run: sudo apt install -y curl
- if: ${{ needs.coverage.outputs.total < 25 }}
run: echo "color=red" >> $GITHUB_ENV
- if: ${{ needs.coverage.outputs.total >= 25 && needs.coverage.outputs.total < 50 }}
run: echo "color=orange" >> $GITHUB_ENV
- if: ${{ needs.coverage.outputs.total >= 50 && needs.coverage.outputs.total < 75 }}
run: echo "color=yellow" >> $GITHUB_ENV
- if: ${{ needs.coverage.outputs.total >= 75 && needs.coverage.outputs.total < 90 }}
run: echo "color=yellowgreen" >> $GITHUB_ENV
- if: ${{ needs.coverage.outputs.total >= 90 && needs.coverage.outputs.total < 95 }}
run: echo "color=green" >> $GITHUB_ENV
- if: ${{ needs.coverage.outputs.total >= 95 }}
run: echo "color=brightgreen" >> $GITHUB_ENV
- name: Update coverage badge
run: |
curl \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GIST_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/gists/6c39ef59cc8beb9595e91fc96793de5b \
-d '{
"files": {
"coverage.json": {
"content": "{\n\"schemaVersion\": 1,\n\"label\": \"coverage\",\n\"message\": \"${{ needs.coverage.outputs.total }}%\",\n\"color\": \"${{ env.color }}\"\n}"
}
}
}'