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

chore/deepsource coverage #9

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
102 changes: 101 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
name: CI
on: pull_request

permissions:
actions: write
checks: write
contents: write
deployments: write
id-token: write
issues: write
packages: write
pages: write
pull: write
repository: write
security: write
statuses: write


jobs:
ci:
strategy:
fail-fast: false
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}

- uses: actions/setup-python@v4
with:
python-version: "3.10"
Expand All @@ -19,5 +37,87 @@ jobs:
installer-parallel: true
- name: Install Dependencies
run: poetry install --no-interaction --no-root

- name: Test
run: poetry run pytest
id: test
run: |
poetry run pytest --cov=commitomatic --cov-report=xml --cov-report=html
curl https://deepsource.io/cli | sh
./bin/deepsource report --analyzer test-coverage --key python --value-file $PWD/coverage.xml
rate=$(grep -Pio 'line-rate="\K[^"]*' coverage.xml | head -n1)
percentage=$(echo "100 * $rate" | bc)
percentage_rounded=$(printf "%.f" $percentage)
echo "lines=${percentage_rounded}" >> $GITHUB_OUTPUT
echo "path=${BADGE_PATH}" >> $GITHUB_OUTPUT
echo "branch=badges" >> $GITHUB_OUTPUT
env:
DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }}
BADGE_PATH: test-coverage.svg

- name: Setup Pages
uses: actions/configure-pages@v2

- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
# Upload entire repository
path: 'htmlcov'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1

- name: Deploy Coverage Report to Pages
if: success()
uses: crazy-max/ghaction-github-pages@v2
with:
target_branch: gh-pages
build_dir: htmlcov
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/checkout@v3
with:
ref: badges

- name: Generate the badge SVG image
uses: emibcn/badge-action@v2.0.2
id: badge
with:
label: 'Test coverage'
status: ${{ steps.test.outputs.lines }}%
color: ${{
steps.test.outputs.lines > 90 && 'green' ||
steps.test.outputs.lines > 80 && 'yellow,green' ||
steps.test.outputs.lines > 70 && 'yellow' ||
steps.test.outputs.lines > 60 && 'orange,yellow' ||
steps.test.outputs.lines > 50 && 'orange' ||
steps.test.outputs.lines > 40 && 'red,orange' ||
steps.test.outputs.lines > 30 && 'red,red,orange' ||
steps.test.outputs.lines > 20 && 'red,red,red,orange' ||
'red' }}
path: ${{ steps.test.outputs.path }}

- name: Upload badge as artifact
uses: actions/upload-artifact@v3
with:
name: badge
path: ${{ steps.test.outputs.path }}
if-no-files-found: error

- name: Commit badge
continue-on-error: true
env:
BADGE: ${{ steps.test.outputs.path }}
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add "${BADGE}"
git commit -m "Add/Update badge"

- name: Push badge commit
uses: ad-m/github-push-action@master
if: ${{ success() }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ steps.test.outputs.branch }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![DeepSource](https://deepsource.io/gh/tiborpilz/commitomatic.svg/?label=active+issues&show_trend=true&token=HXOj050y_0e28wz3hpVDSbg6)](https://deepsource.io/gh/tiborpilz/commitomatic/?ref=repository-badge)
[![DeepSource](https://deepsource.io/gh/tiborpilz/commitomatic.svg/?label=resolved+issues&show_trend=true&token=HXOj050y_0e28wz3hpVDSbg6)](https://deepsource.io/gh/tiborpilz/commitomatic/?ref=repository-badge)
[![Coverage](https://raw.githubusercontent.com/tiborpilz/commitomatic/badges/test-coverage.svg)]()

# Commitomatic

Expand Down
88 changes: 87 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pyfzf = "^0.3.1"
openai = "^0.25.0"
pytest = "^7.2.0"
pytest-mock = "^3.10.0"

pytest-cov = "^4.0.0"

[build-system]
requires = ["poetry-core"]
Expand Down