Useful snippets

Github Actions

It’s a common pattern to auto-deploy your Modal as part of your CI/CD pipeline. To get you started, here’s a sample Github Actions workflow that deploys your app on every push to the main branch.

This requires you to create a Modal token and add it as a secret for your Github Actions workflow. Finally, you can create a new workflow file in your repository at .github/workflows/ci-cd.yml with the following contents (be sure to replace my_package.my_file with your actual entrypoint).

name: CI/CD

on:
  push:
    branches:
      - main

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest
    env:
      MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
      MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}

    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4

      - name: Install Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.10'

      - name: Install Modal
        run: |
          python -m pip install --upgrade pip
          pip install modal


      - name: Deploy job
        run: |
          modal deploy my_package.my_file