Published on

GitHub Actions for Python: Set Up Your First Workflow in 10 Minutes

GitHub Actions is an automation tool that lets you run scripts every time you push code to GitHub, helping you catch errors in your Python projects within minutes. By creating a simple YAML (Yet Another Markup Language - a human-readable data format) file, you can automatically run tests, check code formatting, and deploy your application. Most beginners can set up their first automated workflow in under 10 minutes to ensure their code never breaks when shared with others.

What is the benefit of using GitHub Actions?

GitHub Actions provides a way to implement CI/CD (Continuous Integration and Continuous Deployment). CI (Continuous Integration) is the practice of frequently merging code changes into a central repository where automated builds and tests run. CD (Continuous Deployment) is the process of automatically sending those code changes to a live server once they pass testing.

Using this tool means you don't have to manually run tests on your laptop before every update. The system handles the heavy lifting on GitHub’s servers, which saves you time and prevents "it works on my machine" syndrome. We've found that this automation is the single best way to build confidence when you are just starting to share your code with the world.

Automation also helps you maintain high standards by checking your code against the latest industry versions. In 2026, this means ensuring your project remains compatible with Python 3.14 or the newly released Python 3.15. It acts like a digital assistant that watches your back every time you click "Commit."

What do you need to get started?

Before setting up your first workflow, you need a few basic things ready to go. Don't worry if you haven't used all of these before; the setup process is very forgiving.

  • A GitHub Account: You will need a free account to host your code.
  • A Python Project: A simple folder containing at least one Python file and a requirements.txt file (a list of libraries your project needs to run).
  • Python 3.13 or 3.14: These are the standard stable versions for 2026.
  • A Test File: A basic script using a framework like pytest (a tool that helps you write and run code tests) to verify your logic.

How do you create your first workflow file?

GitHub looks for instructions in a specific folder within your project. You must name this folder .github/workflows exactly for the automation to trigger. Inside this folder, you will create a file ending in .yml.

Step 1: Create the folder structure In your main project directory, create a new folder named .github. Inside that folder, create another folder named workflows.

Step 2: Create the YAML file Create a new file inside the workflows folder named python-tests.yml. This file will hold the instructions for GitHub to follow.

Step 3: Define the "Trigger" You need to tell GitHub when to run this script. Usually, you want it to run when you "push" (upload) code or create a "pull request" (a request to merge your changes into the main code).

name: Python Quality Check

# This tells GitHub to run the script on every push to the 'main' branch
on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

What instructions should go in the workflow?

A workflow is made of "jobs" and "steps." A job is a series of steps that run on a fresh virtual machine provided by GitHub.

Step 4: Set up the environment You need to choose an operating system for your code to run on. Most Python developers use ubuntu-latest because it is fast and reliable.

jobs:
  build:
    # We use the latest Ubuntu runner available in 2026
    runs-on: ubuntu-latest

    steps:
    # Step 5: Check out your code
    - name: Checkout repository code
      uses: actions/checkout@v5 # This tool copies your code onto the runner

    # Step 6: Install Python
    - name: Set up Python 3.14
      uses: actions/setup-python@v7 # This tool installs the specific Python version
      with:
        python-version: '3.14' 

Step 7: Install dependencies Once Python is ready, the runner needs to install the libraries your project uses. This is why having a requirements.txt file is vital.

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
        pip install pytest # Installing the testing tool

Step 8: Run your tests Finally, tell the runner to execute your tests. If the tests fail, GitHub will show a red "X" on your project page.

    - name: Run tests with pytest
      run: |
        pytest

How do you check if it worked?

After you save your .yml file and push it to GitHub, the automation starts immediately. You can track the progress directly in your browser.

Step 9: Visit the "Actions" tab Go to your repository on GitHub.com and click the "Actions" tab at the top of the page. You should see a new entry with the name "Python Quality Check."

Step 10: Inspect the results Click on the specific run to see the logs. You will see a list of the steps we defined earlier, such as "Install dependencies" and "Run tests."

If everything is green, your code passed. If a step is red, click on it to see the error message. Usually, this means a test failed or a library was missing from your requirements.txt file.

What are common mistakes beginners make?

It is perfectly normal to run into errors on your first few tries. Most issues come from small formatting details or version mismatches.

  • Indentation Errors: YAML files are very picky about spaces. Ensure your levels of indentation (the empty spaces at the start of lines) match the examples exactly.
  • Missing Requirements: If your code uses a library like pandas or requests but you didn't list it in requirements.txt, the "Install dependencies" step will fail.
  • Incorrect File Path: Ensure your file is in .github/workflows/. If you miss the "s" in "workflows" or forget the dot in front of "github," the script won't run.
  • Outdated Actions: By 2026, using actions/checkout@v2 might cause warnings. Always try to use the latest versions like v5 or v6 for the best security and speed.

How can you use AI to improve your workflows?

Modern AI models can help you write more complex workflows without needing to memorize the syntax. If you want to add features like automatic deployment to a cloud provider, you can ask an AI for help.

We recommend using Claude Sonnet 4 or GPT-5 to generate specific YAML configurations. For example, you can prompt the AI: "Create a GitHub Action for a Python 3.15 project that runs pytest and checks for security vulnerabilities using Bandit."

The AI will provide a code block that you can paste into your workflows folder. Just remember to read through the generated code to ensure the Python versions match what you are using in your local environment.

Next Steps

Now that you have automated your tests, you can explore more advanced features. You might want to add "Linting" (a process that checks your code for style and potential bugs) using tools like Ruff or Flake8. You could also set up your workflow to run on multiple Python versions (like 3.13, 3.14, and 3.15) at the same time to ensure total compatibility.

As you grow as a developer, these automated checks will become your most trusted tools. They allow you to experiment boldly, knowing that the system will catch any mistakes before they reach your users.

For more detailed guides, visit the official Python documentation.