CodeNewbie Community 🌱

UltraViolet33
UltraViolet33

Posted on

Automate testing with Github Actions

I assume you have a Python project, but you can adapt it to any languages / frameworks.

Create the .github/workflows folder and the yml file at the root of your project.

mkdir -p .github/workflows && touch .github/workflows/testing.yml
Enter fullscreen mode Exit fullscreen mode

The testing.yml file:

name: test
on:
  pull_request:
    branches:
      - main
      # Add any branch

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python 3.x
        uses: actions/setup-python@v4
        with:
          python-version: "3.10"
          architecture: "x64"
      - name: Display Python version
        run: python -c "import sys; print(sys.version)"

      - name: Install dependencies
      # Install necessary dependencies to run the tests
        run: |
          python -m pip install --upgrade pip
          pip install poetry
          poetry install

      - name: Run Tests
      # Add command to run test
        run: |
          make test


Enter fullscreen mode Exit fullscreen mode

Each time a PR is made to the main branch, the tests will run.
I am using a Python project, but you can easily find YAML template files for any language or framework.
You can then add a branch rule on GitHub to prevent merging a PR if the tests fail.

Top comments (0)