GitHub Actions: Setting up poetry and running CI
This weekend, I set up my first GitHub Action
to run continuous integration using Pytest for one of my repositories.
Dependencies and virtual environment managment is done via Poetry.
For example, the following file, placed in .github/workflows/python-app.yml of a GitHub
repository, does the following:
- checkout the repository
- install Python
- install Poetry
- install dependencies using Poetry in a virtual environment
- run pytest against a local test suite in
tests/ Run the above for both Python 3.8 and 3.9.
name: Python application on: push: branches: [ master ] pull_request: branches: [ master ] jobs: build: strategy: fail-fast: false matrix: python-version: [3.8, 3.9] poetry-version: [1.1.4] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - name: Install poetry ${{ matrix.poetry-version }} run: | python -m ensurepip python -m pip install --upgrade pip python -m pip install poetry==${{ matrix.poetry-version }} - name: View poetry --help run: poetry --help - name: Install dependencies shell: bash run: python -m poetry install - name: Test with pytest run: | python -m poetry run python -m pytest -v tests
For more information, see for example a GitHub repo here using the mechanism.
