Skip to content

Instantly share code, notes, and snippets.

@mwakok
Last active January 12, 2022 20:12
Show Gist options
  • Save mwakok/f1a0f9bdb5e9c9b16cf2507ad971bccd to your computer and use it in GitHub Desktop.
Save mwakok/f1a0f9bdb5e9c9b16cf2507ad971bccd to your computer and use it in GitHub Desktop.
Workflow to test and build a python package
name: Build and test Python package
on:
push:
pull_request:
types: [opened, reopened]
jobs:
python_tests:
name: first code check / python-3.8 / ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Python info
run: |
which python
python --version
- name: Build package and create dev environment
run: |
python -m pip install --upgrade pip
pip install -e .[dev]
- name: Test with coverage
run: |
pytest --cov --cov-report term --cov-report xml --junitxml=xunit-result.xml
- name: Correct coverage paths
run: sed -i "s+$PWD/++g" coverage.xml
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
build_pypi:
name: Test pypi build
runs-on: ubuntu-latest
needs: python_tests
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Python info
run: |
which python
python --version
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools
- name: Build package
run: |
pip install wheel twine
python setup.py sdist bdist_wheel
- name: Check package
run: |
python -m twine check dist/*
- name: Install package
run: |
pip install -e .[dev]
- name: Show pip list again
run: |
pip list
- name: Run tests
run: |
pytest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment