ci: add code coverage badge (and others) #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update Coverage Badge | |
on: | |
push: | |
branches: [ main ] | |
jobs: | |
coverage: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
- name: Install Poetry | |
uses: snok/install-poetry@v1 | |
with: | |
version: 1.8.3 | |
- name: Install dependencies | |
run: | | |
pip wheel --no-cache-dir --use-pep517 ml-dtypes | |
poetry install --all-extras | |
- name: Set Redis image name | |
run: | | |
echo "REDIS_IMAGE=redis/redis-stack-server:latest" >> $GITHUB_ENV | |
- name: Run tests with coverage | |
run: | | |
poetry run pytest --cov=langgraph --cov-report=term --cov-report=json | |
COVERAGE=$(python -c "import json; print(int(json.load(open('coverage.json'))['totals']['percent_covered']))") | |
echo "COVERAGE=${COVERAGE}" >> $GITHUB_ENV | |
# Set color based on coverage | |
if [ $COVERAGE -lt 70 ]; then | |
echo "COLOR=red" >> $GITHUB_ENV | |
elif [ $COVERAGE -lt 80 ]; then | |
echo "COLOR=yellow" >> $GITHUB_ENV | |
else | |
echo "COLOR=green" >> $GITHUB_ENV | |
fi | |
- name: Create Coverage Badge | |
uses: schneegans/[email protected] | |
with: | |
auth: ${{ secrets.GIST_TOKEN }} | |
gistID: ${{ secrets.GIST_ID }} | |
filename: langgraph-redis-coverage.json | |
label: Coverage | |
message: ${{ env.COVERAGE }}% | |
color: ${{ env.COLOR }} |