travis ci_PHP和与Travis CI的持续集成

travis ci

Continuous integration (CI) allows a team to commit their work quickly, which means there will be multiple commits to a repository daily. Every time there is a commit it is verified by an automated build (including test) to alert you of any build or test errors immediately. Once the process of integrating and verifying your work into the master becomes automatic you are able to develop cohesive software rapidly.

持续集成(CI)使团队可以快速提交其工作,这意味着每天将有多个提交到存储库。 每次提交时,都会通过自动构建(包括测试)对其进行验证,以立即提醒您任何构建或测试错误。 一旦将您的工作集成和验证到母版中的过程自动完成,您就可以快速开发具有凝聚力的软件。

什么是Travis CI? (What is Travis CI?)

Travis CI automatically sets up a CI environment and makes it simple for anyone to test and deploy their app. Their build system supports many different languages, you just have to define which language this project is and Travis CI will take care of the rest. You can find more information about all the other environments they offer in their docs, but for this article we will focus on adding Travis CI to a PHP repository on GitHub.

Travis CI自动设置CI环境,使任何人都可以轻松测试和部署其应用程序。 他们的构建系统支持许多不同的语言,您只需要定义该项目是哪种语言,其余的就由Travis CI负责。 您可以在文档中找到有关它们提供的所有其他环境的更多信息,但是对于本文,我们将重点介绍将Travis CI添加到GitHub上PHP存储库中。

Public repositories on Github can use Travis CI for free, but they share community boxes and sit in queues. To use a private repository with Travis CI you can subscribe to one of their plans and get your project built without waiting, plus you can have concurrent jobs.

Github上的公共存储库可以免费使用Travis CI,但它们共享社区信箱并排在队列中。 要将私有存储库与Travis CI配合使用,您可以订阅他们的计划之一,而无需等待就可以构建项目,此外,您还可以进行并发作业。

Note: The open source site ends in ‘.org’ (https://travis-ci.org/) and the private repository site ends with ‘.com’ (https://travis-ci.com/).

注意: 开源站点以“ .org”( https://travis-ci.org/ )结尾,私有存储库站点以“ .com”( https://travis-ci.com/ )结尾。

Travis CI入门 (Getting Started With Travis CI)

To follow along just fork this example repository. Please feel free to change it’s files and see what the settings do.

要继续学习,只需分叉此示例存储库。 请随时更改其文件并查看设置。

步骤1:登入 (Step 1: Sign In)

alt

Sign in to Travis CI with your GitHub account by clicking the Sign In link at the top right.

通过单击右上方的“ 登录”链接,使用您的GitHub帐户登录Travis CI

On this page you will see off to the left a list of public repositories being built. To watch their build live just click one of them.

在此页面上,您会在左侧看到正在构建的公共存储库的列表。 要观看其实时构建,只需单击其中之一。

步骤2:同步您的GitHub Repos (Step 2: Sync Your GitHub Repos)

alt

After you’ve signed in Travis CI will synchronize your public repositories to your account under your profile page. You will then need to click the switch button into the On position. Now every time you commit to this repository GitHub will make a call to Travis CI and automatically initiate the build process.

登录后,Travis CI会将您的公共存储库同步到您的个人资料页面下的帐户。 然后,您需要将开关按钮单击到“打开”位置。 现在,每次您提交到此存储库时,GitHub都会调用Travis CI,并自动启动构建过程。

If you create a repository and you do not see it listed click Sync now on your profile page and your newly created repository will appear there.

如果创建存储库,但未在列表中看到该存储库,请在个人资料页面上单击立即同步 ,新创建的存储库将显示在此处。

步骤3:将.travis.yml文件添加到您的存储库 (Step 3: Add .travis.yml file to your repository)

alt

To tell Travis CI what environments you want your repository built and tested under you’ll need to add a .travis.yml to the root of your repository. Travis CI will run your tests against a matrix of all possible combinations of your configuration using:

要告诉Travis CI,您希望在什么环境下构建和测试存储库,您需要在存储库的根目录中添加.travis.yml 。 Travis CI将使用以下配置对配置的所有可能组合进行测试:

  • Runtimes you specified under php

    您在php下指定的运行时

  • Environment variables you define with env

    env定义的环境变量

  • Exclusions, inclusions, and allowed failures

    排除,包含和允许的失败

Learn more about build matrices

了解有关构建矩阵的更多信息

# Required to run your project under the correct environment.
language: php

# Versions of PHP you want your project run with.
php:
  - 5.4
  - 5.5
  - 5.6
  - hhvm

# Commands to be run before your environment runs.
before_script:
  - composer self-update
  - composer install --prefer-source --no-interaction --dev

# Commands you want to run that will verify your build.
script: phpunit

# allow_failures: Allow this build to fail under the specified environments.
# fast_finish: If your build fails do not continue trying to build, just stop.
matrix:
  allow_failures:
    - php: 5.6
    - php: hhvm
  fast_finish: true

# Customize when the notification emails are sent.
notifications:
    on_success: never
    on_failure: always

Example Configurations

示例配置

Learn more about .travis.yml PHP options

了解有关.travis.yml PHP选项的更多信息

步骤4:使用Git Push触发构建 (Step 4: Trigger A Build With a Git Push)

Your first build must be triggered by a commit and push from GitHub, not the Restart Build button.

您的第一个构建必须由GitHub上的提交和推送触发,而不是由“重新启动构建”按钮触发。

Every time you push a commit to a branch on your repository, Travis CI will initiate the build process. Once a worker is available it will start building your project. You can navigate to https://travis-ci.org/GITHUB_USERNAME/REPO_NAME to watch it’s build progress live.

每次将提交提交到存储库中的分支时,Travis CI都会启动构建过程。 一旦有工作人员可用,它将开始构建您的项目。 您可以导航到https://travis-ci.org/GITHUB_USERNAME/REPO_NAME以实时查看其构建进度。

If you want to restart your build, click the Restart Build button and you will see your project start building once a worker is available.

如果要重新开始构建,请单击“ 重新开始构建”按钮,并且一旦有工作线程可用,您将看到项目开始构建。

alt

步骤5:调整构建配置 (Step 5: Tweaking your build configuration)

In the example repository you will find a .travis.yml file that includes the basics with a few extras to some show of the potential Travis CI has. If you want to customize your configuration you can configure almost everything about your build environment.

在示例存储库中,您将找到一个.travis.yml文件,其中包括基础知识以及一些额外的内容,以显示潜在的Travis CI所具有的功能。 如果要自定义配置,则可以配置有关构建环境的几乎所有内容。

Learn more about Travis CI’s PHP configuration.

了解有关Travis CIPHP配置的更多信息

步骤6:测试 (Step 6: Test it)

To see if you configured your repository correctly edit your README.md file on GitHub and commit your edit. Go over to that repository’s Travis CI page and all the circles under Job should become yellow and once the build is running the duration should start incrementing.

要查看您是否配置了存储库,请正确编辑GitHub上的README.md文件并提交您的编辑。 转到该存储库的Travis CI页面,“ 作业”下的所有圆圈应变为黄色,并且在构建运行后,持续时间应开始增加。

Once the build is complete and the light goes red click it and read the output in the console. You can also setup Travis CI to send you an email letting you know what happened via the notifications option. If your build doesn’t start try validating against a YAML Validator to make sure there are no mistakes in your configuration file.

构建完成并且指示灯变为红色后,请单击它并在控制台中读取输出。 您还可以将Travis CI设置为通过notifications选项向您发送电子邮件,让您知道发生了什么。 如果您的构建没有开始,请尝试使用YAML验证程序进行验证 ,以确保配置文件中没有错误。

学到更多 (Learn more)

Travis CI workers come with many different services that you might depend on and there are guides for all of them.

Travis CI工作者提供了许多您可能依赖的服务,并且为所有这些人提供了指南。

构建状态图像 (Build Status Images)

Travis CI provides a status image that you can place in your project’s README or general documentation. Then visitors can immediately see it’s build status.

Travis CI提供了状态图像,您可以将其放置在项目的README或常规文档中。 然后访问者可以立即看到它的构建状态。

Here’s a status image from the example repository. Hopefully it’s green right now.

这是示例存储库中的状态图像。 希望现在是绿色的。

alt
Travis CI PHP Example
===========

[![Build Status](https://travis-ci.org/clouddueling/travis-ci-php-example.svg?branch=master)](https://travis-ci.org/clouddueling/travis-ci-php-example)

Image URL Format: https://travis-ci.org/USERNAME/REPO_NAME.svg?branch=BRANCH_NAME

图片网址格式: https://travis-ci.org/USERNAME/REPO_NAME.svg?branch=BRANCH_NAMEhttps://travis-ci.org/USERNAME/REPO_NAME.svg?branch=BRANCH_NAME

快速概述 (Quick Overview)

当前 (Current)

All of the builds that you have defined with your configuration options will appear here with a colored icon next to them noting their build status.

您使用配置选项定义的所有构建都将显示在此处,旁边带有彩色图标,以指示其构建状态。

  • Blank screen: You have yet to run your first build

    黑屏:您尚未运行首次构建
  • Yellow: In progress

    黄色:进行中
  • Red: Error, check the console

    红色:错误,请检查控制台
  • Green: Success!

    绿色:成功!
alt

建立历史 (Build History)

Every time a build is run it receives a build number and creates a history that you can see what commit triggered the build, a link to the commit on GitHub, the duration of the build, and when it happened.

每次运行构建时,它都会收到一个构建号并创建一个历史记录,您可以查看触发该构建的提交,到GitHub上的提交的链接,构建的持续时间以及发生的时间。

alt

拉取请求 (Pull Requests)

To give project managers a good idea of whether or not a pull request would break your build, Travis CI automatically builds your project with that pull request and shows it’s status on the PR.

为了使项目经理更好地了解拉取请求是否会中断您的构建,Travis CI会自动使用该拉取请求构建您的项目,并在PR上显示其状态。

alt

分行总结 (Branch Summary)

Travis CI not only builds your master branch but also all other branches and the Branch Summary tells you the current build status of each one.

Travis CI不仅会构建您的主分支,还会构建所有其他分支,并且“分支摘要”会告诉您每个分支的当前构建状态。

alt

结论 (Conclusion)

As you can see, Travis CI is a robust and feature rich service aimed at keeping your projects alive and kicking through any and all contributions. Have you implemented it in your projects? Got tricks to share? Let us know!

如您所见,Travis CI是一项功能强大且功能强大的服务,旨在使您的项目保持活跃并完成所有贡献。 您在项目中实现了吗? 有分享技巧吗? 让我们知道!

翻译自: https://www.sitepoint.com/php-continuous-integration-travis-ci/

travis ci

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值