Calmcode - github actions: dependencies

GitHub Actions that Depend on Eachother

1 2 3 4 5 6

You can also configure jobs to run with dependencies in GitHub actions. Like in the image below.

In this case, the "build" job and the "style" job need to both run without issues before any of the "windows" steps can run. Setting up dependencies like this can be a great way to prevent unnecessary code from running. The only downside is

Example

If you want to run GitHub actions with dependencies yourself, you can use the example below.

name: Python Unit

on:
  pull_request:
    branches:
    - main

jobs:
  style:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: "3.7"
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        python -m pip install -r requirements.txt
        python -m pip install -r dev-requirements.txt
    - name: Test with pytest
      run: |
        flake8

  build:
    strategy:
      matrix:
        python-version: ['3.7', '3.8', '3.9', '3.10']
        os: [ubuntu-latest]
    runs-on: ${{ matrix.os }}

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v4
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        python -m pip install -r requirements.txt
        python -m pip install -r dev-requirements.txt
    - name: Test with pytest
      run: |
        pytest --verbose

  windows:
    strategy:
      matrix:
        python-version: ['3.7', '3.8', '3.9', '3.10']
        os: [windows-latest]
    runs-on: ${{ matrix.os }}
    needs: [style, build]

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v4
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        python -m pip install -r requirements.txt
        python -m pip install -r dev-requirements.txt
    - name: Test with pytest
      run: |
        pytest --verbose