The goal of my current setup is to run multiple Python versions (3.8, 3.9, and 3.10) as part of a test matrix. I want only one of these jobs—specifically the one using Python 3.10—to trigger a deploy step once the tests pass and the branch is main
. I’m using the stages
feature to separate testing and deployment.
Despite deploy
being limited to the last stage, Travis tries to run it on all matrix jobs unless I manually hack around it. When I use:
deploy:
provider: script
script: ./scripts/deploy.sh
on:
branch: main
condition: $TRAVIS_PYTHON_VERSION = "3.10"
Here’s a shortened version of my .travis.yml
:
language: python
python:
- "3.8"
- "3.9"
- "3.10"
stages:
- test
- name: deploy
if: branch = main AND type != pull_request AND python = "3.10"
jobs:
include:
- stage: test
script: pytest tests/
- stage: deploy
script: ./scripts/deploy.sh