language: python
python:
- "3.7"
- "3.8"
- "3.9"
# Command to install dependencies
install:
- pip install -r requirements.txt
- pip install pytest pytest-cov
# Command to run tests
script:
- pytest --cov=./ tests/
# Specify branches to build
branches:
only:
- main
- develop
# Cache pip dependencies
cache: pip
# Run jobs in parallel
jobs:
include:
- name: "Lint"
python: "3.9"
before_script:
- pip install flake8
script:
- flake8 .
- name: "Docs"
python: "3.9"
before_script:
- pip install sphinx
script:
- sphinx-build -b html docs docs/_build
after_success:
- pip install coveralls
- coveralls
notifications:
email:
on_success: never
on_failure: always
language: node_js
node_js:
- "12"
- "14"
- "16"
# Specify the operating system
os:
- linux
- osx
# Cache dependencies
cache:
directories:
- node_modules
# Install dependencies
install:
- npm ci
# Run tests
script:
- npm run test
- npm run build
# Run jobs in parallel
jobs:
include:
- stage: lint
node_js: "16"
script: npm run lint
- stage: coverage
node_js: "16"
script: npm run test:coverage
# Deploy to npm
deploy:
provider: npm
email: "[email protected]"
api_key: $NPM_TOKEN
on:
tags: true
branch: main
# Notifications
notifications:
email:
on_success: never
on_failure: always
slack:
rooms:
- secure: "encrypted-slack-webhook-url"
language: java
jdk:
- openjdk11
- openjdk14
# Cache dependencies
cache:
directories:
- $HOME/.m2
# Build stages
stages:
- test
- name: deploy
if: branch = main
jobs:
include:
- stage: test
name: "Unit Tests"
script: mvn test
- stage: test
name: "Integration Tests"
script: mvn verify -Pintegration-tests
- stage: deploy
name: "Deploy to Staging"
script: mvn deploy -Pstaging
# Notifications
notifications:
email:
recipients:
- [email protected]
on_success: change
on_failure: always
# Before install steps
before_install:
- chmod +x mvnw
# Main build script
script:
- ./mvnw clean install
# After success steps
after_success:
- bash <(curl -s https://codecov.io/bash)
# Only build these branches
branches:
only:
- main
- develop
language: cpp
compiler:
- gcc
- clang
before_install:
- sudo apt-get update
- sudo apt-get install -y cmake
script:
- mkdir build
- cd build
- cmake ..
- make
- make test
notifications:
email: false
language: php
php:
- 7.4
- 8.0
- 8.1
before_script:
- composer self-update
- composer install --no-interaction
script:
- vendor/bin/phpunit
- vendor/bin/phpcs
cache:
directories:
- $HOME/.composer/cache
notifications:
email: false
language: rust
rust:
- stable
- beta
- nightly
matrix:
allow_failures:
- rust: nightly
fast_finish: true
cache: cargo
before_script:
- rustup component add clippy
script:
- cargo build --verbose
- cargo test --verbose
- cargo clippy -- -D warnings
notifications:
email: false
language: go
go:
- 1.16.x
- 1.17.x
- 1.18.x
- tip
matrix:
allow_failures:
- go: tip
fast_finish: true
before_install:
- go get -t -v ./...
script:
- go test -race -coverprofile=coverage.txt -covermode=atomic
- go vet ./...
- diff -u <(echo -n) <(gofmt -d .)
after_success:
- bash <(curl -s https://codecov.io/bash)
notifications:
email: false
language: csharp
mono: none
dotnet: 6.0.100
install:
- dotnet restore
script:
- dotnet build
- dotnet test
notifications:
email: false
branches:
only:
- main
- develop
cache:
directories:
- $HOME/.nuget/packages
language: ruby
rvm:
- 2.6
- 2.7
- 3.0
install:
- bundle install
script:
- bundle exec rake test
after_success:
- bundle exec rake coveralls:push
notifications:
email:
recipients:
- [email protected]
on_success: always
on_failure: always
language: python
python:
- "3.7"
- "3.8"
- "3.9"
env:
- DJANGO_VERSION=2.2
- DJANGO_VERSION=3.0
- DJANGO_VERSION=3.1
matrix:
include:
- python: "3.9"
env: DJANGO_VERSION=3.2
exclude:
- python: "3.7"
env: DJANGO_VERSION=3.1
allow_failures:
- python: "3.9"
env: DJANGO_VERSION=3.2
before_install:
- pip install -U pip
- pip install -U setuptools
- pip install -q Django==$DJANGO_VERSION
install:
- pip install -r requirements.txt
script:
- python manage.py test
after_success:
- coveralls
notifications:
email: false
针对不同版本的运行时或依赖项(甚至多种语言)运行测试,以便在走向生产的过程中实现全面的自动化和绝对的质量保证。
language: python
python:
- "3.8"
services:
- mongodb
- redis
- mysql
env:
- DB=mongodb
- DB=redis
- DB=mysql
before_script:
- if [[ "$DB" == "mongodb" ]]; then mongo mydb_test
--eval 'db.createUser({user:"travis",pwd:"test",roles:
["readWrite"]});'; fi - if [[ "$DB" == "mysql" ]];
then mysql -e 'CREATE DATABASE IF NOT EXISTS mydb_test;
'; fi
script:
- if [[ "$DB" == "mongodb" ]]; then python
test_mongodb.py; fi
- if [[ "$DB" == "redis" ]]; then python
test_redis.py; fi
- if [[ "$DB" == "mysql" ]]; then python
test_mysql.py; fi
快速将复杂操作(如单元测试和集成测试)拆分成多个作业,以便更快速地以可视化的方式了解代码质量和结果,不再需要等待管道完成,可以立即回到 IDE 中。
language: python
python:
- "3.8"
# Install dependencies
install:
- pip install -r requirements.txt
# Run tests
script:
- pytest
# Integration with Slack for notifications
notifications:
slack: your-slack-workspace:your-slack-token
# Integration with Codecov for code coverage reports
after_success:
- pip install codecov
- codecov
# Integration with GitHub Pages for documentation deployment
deploy:
provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN
on:
branch: main
无需浪费时间在不必要的复杂粘合代码上,即可启用必备功能,例如构建状态图像、静态代码分析和密钥管理。对于其他所有功能,Travis CI API 可以为您提供帮助。
language: python
python:
- "3.8"
script:
- python -m pytest tests/
notifications:
email:
recipients:
- [email protected]
on_success: change
on_failure: always
slack:
rooms:
- secure: "encrypted-slack-webhook-url"
on_success: always
on_failure: always
template:
- "Build <%{build_url}|#%{build_number}>
(<%{compare_url}|%{commit}>) of %{repository_slug}
@%{branch} by %{author} %{result} in %{duration}"
webhooks:
urls:
- https://webhook.site/your-unique-id
on_success: change
on_failure: always
irc:
channels:
- "irc.freenode.org#myproject"
template:
- "%{repository} (%{commit}) : %{message}"
- "Build details: %{build_url}"
pushover:
api_key: "pushover-api-key"
users:
- "pushover-user-key"
template: "%{repository} (%{commit}) :
%{message} - %{duration}"
after_failure:
- cat /home/travis/build/your-github-username/
your-repo-name/tests/test-suite.log
启用高度可定制的通知功能,发送到电子邮件、Slack、Opsgenie、任何 Webhook 目标以及更多其他目标。您只需要提供 API 令牌,并添加两行 YAML 代码即可。
language: python
python:
- "3.8"
stages:
- test
- name: deploy
if: branch = main
jobs:
include:
- stage: test
name: "Unit Tests"
script: python -m unittest discover tests/unit
- stage: test
name: "Integration Tests"
script: python -m unittest discover tests/integration
- stage: deploy
name: "Deploy to Production"
script:
- pip install awscli
- aws s3 sync . s3://my-bucket/ --delete
env:
global:
- PYTHONPATH=$PYTHONPATH:$TRAVIS_BUILD_DIR
before_install:
- pip install -r requirements.txt
branches:
only:
- main
- develop
notifications:
email:
on_success: never
on_failure: always
将复杂的 CI/CD 管道无限制地组织成组,这些组只有在其他并行作业成功完成后才会运行。更快地发现错误,或添加智能条件以发现其他 CI/CD 工具无法识别的问题。
language: generic
jobs:
include:
# Linux builds
- os: linux
arch: amd64
- os: linux
arch: arm64
# macOS builds
- os: osx
osx_image: xcode12.5
# Windows builds
- os: windows
script:
- echo "Running tests on $TRAVIS_OS_NAME $TRAVIS_CPU_ARCH"
- # Add your build and test commands here
notifications:
email: false
在比任何其他 CI/CD 工具更灵活的组合上并行测试您的代码。混合搭配 amd64、ppc64le、s390x、arm64 和 arm64-graviton2 CPU,以及 Linux、macOS 和 Windows 环境,确保您的构建能够应对各种情况。
这是一个棘手但合理的问题。我们仍然为想要使用精密工具而不是臃肿平台的开发者提供最简单、最可扩展的 CI/CD。
Travis CI 帮助您独具特色地拥有代码质量,与您的同事更好地协作,并共同拥有您创造的结果。
符合 GDPR 和 PrivacyShield 标准。构建隔离机制以防止干扰。每次构建都使用干净的虚拟机。
此外,您可以轻松扩展以使用 HashiCorp Vault 集成、协作者管理、范围限定的凭据、签名工件以及更多功能来保护您的软件供应链。
我们的 CI/CD 专家随时为您提供帮助。在您加入之前有任何问题,或者想了解 Travis CI Enterprise?
无论您是需要扩展管道的提示还是构建自定义 API 集成的代码示例,我们的 CI/CD 专家社区都会竭诚相助。