Auto-Fetch Repository Changes on Push
Keep Valohai synced with your repository automatically. Every time you push code to GitHub, this action fetches the latest commits to Valohai without manual clicking.
Prerequisites
A Valohai project connected to a GitHub repository (public or private)
A valid
valohai.yamlwith at least one step definedThe repository branches you want to sync configured in Project Settings → Repository → Branch Configuration
Generate a Valohai API Token
Create an API token to authenticate your GitHub Action:
Click "Hi, <username>!" in the top-right corner
Go to My Profile → Authentication
Click Manage Tokens and scroll to the bottom
Click Generate New Token
Copy the token immediately — it's shown only once
⚠️ Keep your token safe. Store it as a GitHub secret, never commit it to your repository.
Add Token as GitHub Secret
Store your Valohai API token in GitHub:
Go to your GitHub repository
Navigate to Settings → Secrets and variables → Actions
Click New repository secret
Name:
VH_API_TOKENValue: Paste your Valohai API token
Click Add secret
Create the Fetch Script
Create a script that calls the Valohai API to fetch repository changes.
Create valohai-fetch-action/fetch.py in your repository root:
import requests
import os
# Authenticate with your Valohai API token
auth_token = os.getenv('VH_API_TOKEN')
headers = {'Authorization': f'Token {auth_token}'}
# Replace with your project ID
# Find it in Project Settings → General, or copy from your project URL
project_id = 'your-project-id-here'
# Fetch all new changes from configured branches
# This syncs commits from branches defined in Project Settings → Repository
fetch_url = f'https://app.valohai.com/api/v0/projects/{project_id}/fetch/'
response = requests.post(fetch_url, headers=headers)
response.raise_for_status()
print('✓ Successfully fetched latest commits to Valohai')💡 Find your project ID in Project Settings → General or extract it from your project URL:
https://app.valohai.com/p/owner/project-name/→ the ID appears in the page details.
Set Up GitHub Action
Create a workflow that runs the fetch script on every push to main.
Create .github/workflows/valohai-fetch.yml:
name: Fetch to Valohai
on:
push:
branches:
- main
jobs:
fetch:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: pip install requests
- name: Fetch commits to Valohai
env:
VH_API_TOKEN: ${{ secrets.VH_API_TOKEN }}
run: python valohai-fetch-action/fetch.pyVerify It Works
Push a commit to your main branch and watch the GitHub Action run:
Make a change to your code
Commit and push to main
Go to Actions tab in GitHub to see the workflow run
Check your Valohai project — the latest commit should appear automatically
The fetch makes your commits visible in Valohai. You can now manually trigger executions from these commits, or chain this action with automated execution creation.
Troubleshooting
"Failed to fetch" error:
Verify your
VH_API_TOKENsecret is set correctly in GitHubConfirm your project ID matches your Valohai project
Check that your repository is connected in Project Settings → Repository
Commits not appearing:
Ensure the branch is configured in Project Settings → Repository → Branch Configuration
The API fetches all configured branches — verify yours is listed there
Self-hosted Valohai: Replace https://app.valohai.com with your installation URL in fetch.py
Last updated
Was this helpful?
