博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
emberjs_如何与Circle CI,EmberJS和GitHub进行持续集成
阅读量:2520 次
发布时间:2019-05-11

本文共 9360 字,大约阅读时间需要 31 分钟。

emberjs

什么是持续集成,为什么要这么做? (What is Continuous Integration and why should we do it?)

Continuous Integration (CI) is the process of automating the building and testing of code. This happens every time a project team member commits changes to version control.

持续集成(CI)是使代码的构建和测试自动化的过程。 每当项目团队成员提交对版本控制的更改时,都会发生这种情况。

For example, you make changes to your GitHub repository’s code and push that change to the master branch. This triggers a CI process to build a virtual environment and run commands. The commands configure the environment as it would be on a production server. Then they run the automated test suite you wrote to test your code.

例如,您对GitHub存储库的代码进行更改,并将更改推送到master分支。 这会触发CI流程以构建虚拟环境并运行命令。 这些命令可以像在生产服务器上那样配置环境。 然后他们运行您编写的自动化测试套件来测试您的代码。

CI is often used to:

CI通常用于:

  • validate separate branches that a developer is working on. Branches are well tested before getting merged into the main branch of the project.

    验证开发人员正在处理的单独分支。 在合并到项目的主分支之前,对分支进行了充分的测试。
  • to validate and deploy the latest versions of a project as branches pass validation.

    在分支通过验证时验证和部署项目的最新版本。

Having code continuously integrated into the project and testing it reduces:

将代码连续集成到项目中并对其进行测试可以减少:

  • merge conflicts

    合并冲突
  • hard to fix bugs

    难以修复的错误
  • diverging code strategies

    不同的代码策略
  • duplicated efforts

    重复的努力

It keeps the master branch clean. Read more about Continuous Integration .

它使主分支保持干净。 阅读有关持续集成的更多信息。

教程目标 (Tutorial Goals)

This is your first step into the Continuous Integration process. So, let’s keep things very simple. Our goal is to create a repository on GitHub and run CI on that repository every time a new commit is pushed. We’ll also display a badge that indicates the status of our current build.

这是您进入持续集成过程的第一步。 因此,让我们保持简单。 我们的目标是在GitHub上创建一个存储库,并在每次推送新提交时在该存储库上运行CI。 我们还将显示一个指示当前构建状态的标志。

The tools we’ll use for this demo:

我们将在此演示中使用的工具:

Now let’s get started.

现在开始吧。

设置一个Github帐号 (Setup a Github account)

If you don’t have one already, get yourself a .

如果您还没有一个,请给自己一个 。

Next, head over to the and enter your payment information. Don’t worry about getting charged. We’ll have 1000 minutes monthly of free build minutes with the option we will choose (Circle CI). That’s more than enough for this demo project.

接下来,转到“ 然后输入您的付款信息。 不用担心被充电。 我们将每月提供1000分钟的免费构建时间,并提供(Circle CI)选项。 对于这个演示项目来说,这绰绰有余。

Finally, create a new repository called ci-ember-demo. Do not initialize it.

最后,创建一个名为ci-ember-demo的新存储库。 不要初始化它。

创建一个基本的Ember应用程序 (Create a basic Ember application)

安装Ember CLI (Install Ember CLI)

Let’s use NPM to install . It includes the tools we need to generate a basic project.

让我们使用NPM安装 。 它包括我们生成基本项目所需的工具。

npm install -g ember-cli

创建一个Ember项目 (Create an Ember Project)

Let’s create a project called ci-ember-demo using Ember CLI:

让我们使用Ember CLI创建一个名为ci-ember-demo的项目:

# cd into the desktop  cd ~/desktop/# create a new project  ember new ci-ember-demo# cd into the directory  cd ci-ember-demo# run the server  ember s

Now, head over to http://localhost:4200 and you should see this screen:

现在,转到http://localhost:4200 ,您应该看到以下屏幕:

The base Ember project is running as expected. You can shut down the server with ctrl+C.

基本的Ember项目正在按预期运行。 您可以使用ctrl+C关闭服务器。

检查默认测试是否通过 (Check that the default tests are passing)

Now in the terminal let’s run the tests that were generated with the project:

现在,在终端中,运行由项目生成的测试:

npm test# alternativelyember test

You should see a series of six default tests run. All should pass.

您应该看到一系列六个默认测试运行。 一切都会过去。

The idea is that these and other tests you write as you develop your project will be continually run as you push changes to the repository.

想法是,在将更改推送到存储库时,在开发项目时编写的这些测试和其他测试将连续运行。

将您的项目推送到Github (Push your project to Github)

Head over to the ci-ember-demo project folder to edit the README.md file. Replace what’s there with something like:

转到ci-ember-demo项目文件夹以编辑README.md文件。 用以下内容替换其中的内容:

## ci-ember-demo
This is a basic Ember CI demo application. Check out the tutorial: 'First Step into Continuous Integration with Circle CI'.

获取并设置远程URL (Get your remote URL and set it)

Head back to your GitHub repository and grab the remote URL which should look like this:

回到您的GitHub存储库并获取应该如下所示的远程URL:

git@github.com:username/repo_name.git

Inside the ci-ember-demo folder initialize the repository:

ci-ember-demo文件夹中,初始化存储库:

git init

Then so Git knows where we’re pushing our files to:

然后以便Git知道我们要将文件推送到的位置:

git remote add origin git@github.com:username/repo_name.git# check that it's been set, should display the updated origin  git remote -v

Time to push our code to Github:

是时候将我们的代码推送到Github了:

# add all changes  git add .# create a commit with a message  git commit -m "[INIT] Project"# push changes to the repo's master branch  git push origin master

The remote Git repository updates with the changes we’ve pushed:

远程Git存储库使用我们推送的更改进行更新:

Now we have a main project directory and a repository. It’s time to set up the CI platform.

现在,我们有了一个主项目目录和一个存储库。 现在是时候建立CI平台了。

设置CircleCI —持续的集成和交付平台 (Setup CircleCI — A continuous integration and delivery platform)

will be our tool of choice for Continuous Integration. It’s straightforward, popular, and comes with 1000 free monthly build minutes.

将成为我们进行持续集成的首选工具。 它简单明了,很受欢迎,并且每月有1000个免费的构建分钟。

Head over to and set up a plan.

前往并制定计划。

Select the Free plan.

选择免费计划。

Next head over to CircleCI and :

接下来前往CircleCI并 :

Once you’re in, go to the Add Project section. You’ll see a list of all your GitHub repositories.

进入后,转到“ 添加项目”部分。 您将看到所有GitHub存储库的列表。

Click Setup Project on our ci-ember-demo.

单击我们的ci-ember-demo上的Setup Project

Then select Linux as our operating system and Node for language.

然后选择Linux作为我们的操作系统,选择Node作为语言。

Click Start Building. The project will attempt to build and do what continuous integration processes do.

单击开始构建 。 该项目将尝试构建并执行持续集成过程所要做的事情。

Since we have no configuration settings the process will almost immediately fail.

由于我们没有配置设置,因此该过程几乎会立即失败。

Head over to the Builds tab that lists any Jobs that ran, you should see that failure like so:

转到列出所有已运行作业的“ 构建”选项卡,您应该看到这样的失败:

This is what we expected. Nothing really works because the CI process isn’t configured.

这就是我们所期望的。 由于未配置CI流程,因此没有任何效果。

在Ember项目中配置CI (Configure CI in the Ember Project)

获取减价以显示我们项目的CI状态 (Get the markdown to display our project’s CI status)

CircleCI provides embeddable status badges. They display the status of your latest build. Before we go let’s get the markdown for a status badge.

CircleCI提供可嵌入的状态徽章。 它们显示您最新版本的状态。 在我们开始之前,让我们为状态徽章打折。

Go to Settings → Projects → ember-ci-demo’s settings → Status Badges.

转到设置→项目→ ember-ci-demo的设置→状态徽章。

Copy the embed code in Markdown.

将嵌入代码复制到Markdown中。

In the ci-ember-demo's README.md file, paste the embed code under the title. It will look something like this:

ci-ember-demoREADME.md文件中,将嵌入代码粘贴到标题下。 它看起来像这样:

## ci-ember-demo[![CircleCI](https://circleci.com/gh/username/ci-ember-demo.svg?style=svg)](https://circleci.com/gh/username/ci-ember-demo)...

添加配置项 (Add the CI configuration)

In the root of ember-ci-demo create a folder named .circleci and create a file called config.yml. This is where all of our configuration settings will go. Add the following:

ember-ci-demo的根目录中,创建一个名为.circleci的文件夹,并创建一个名为config.yml的文件。 这是我们所有配置设置的去向。 添加以下内容:

version: 2jobs:  build:    docker:      - image: circleci/node:7.10-browsers        environment:          CHROME_BIN: "/usr/bin/google-chrome"    steps:      - checkout      - run: npm install      - run: npm test

Let’s stop and take a look at what’s happening here.

让我们停下来看看这里发生了什么。

# set the version of CircleCI to use.# we'll use the latest version.version: 2

Next, we’ll set up jobs to run when the CI is triggered.

接下来,我们将设置作业以在触发CI时运行。

jobs:  # tell CI to create a virtual node environment with Docker  # specify the virtual image to use  # the -browsers suffix tells it to have browsers pre-installed  build:    docker:      - image: circleci/node:7.10-browsers                # use Google Chrome to run our tests        environment:          CHROME_BIN: "/usr/bin/google-chrome"

Finally, let’s tell it what to do once the environment is setup:

最后,让我们告诉它设置环境后该怎么做:

steps:  - checkout    # install the required npm packages  - run: npm install  # run the test suite  - run: npm test

将更改推送到master分支。 (Push the changes to the master branch.)

Review your changes and push them up to the master branch of the repository.

查看您的更改,并将其推送到存储库的master分支。

Now, head back to CircleCI and check out the Jobs tab. You’ll now see a passing build. It was able to take the settings from config.yml, set up the correct virtual environments, and run our tests just as we did locally when we first generated the project.

现在,返回CircleCI并检查“ 作业”选项卡。 现在,您将看到一个通过的构建。 它能够从config.yml获取设置,设置正确的虚拟环境,并像最初生成项目时在本地所做的那样运行测试。

If you look at the repository on GitHub, you’ll see the CircleCI status badge in green. This indicates again that the latest build is passing.

如果您查看GitHub上的存储库,则会看到绿色的CircleCI状态徽章。 这再次表明最新版本已通过。

结论 (Conclusion)

That’s it! Now whenever you create a new pull request or push any changes to master, the CI will run all the tests. The status of that job will be displayed in CircleCI and the badge on your repository. Pass or fail, you get the right information you need to develop well.

而已! 现在,无论何时创建新的拉取请求或将任何更改推送到主请求,CI都将运行所有测试。 该作业的状态将显示在CircleCI和存储库中的徽章上。 通过或失败,您将获得正确发展所需的正确信息。

Congratulations on taking your first steps into Continuous Integration!

祝贺您迈出了持续集成的第一步!

资料来源 (Sources)

翻译自:

emberjs

转载地址:http://bywzd.baihongyu.com/

你可能感兴趣的文章
地鼠的困境SSL1333 最大匹配
查看>>
flume+elasticsearch+kibana遇到的坑
查看>>
【MM系列】在SAP里查看数据的方法
查看>>
C#——winform
查看>>
CSS3 transform制作的漂亮的滚动式导航
查看>>
《小强升职记——时间管理故事书》读书笔记
查看>>
Alpha 冲刺(3/10)
查看>>
Kaldi中的Chain模型
查看>>
spring中的ResourceBundleMessageSource使用和测试示例
查看>>
css规范 - bem
查看>>
电梯调度程序的UI设计
查看>>
转自 zera php中extends和implements的区别
查看>>
Array.of使用实例
查看>>
【Luogu】P2498拯救小云公主(spfa)
查看>>
如何获取网站icon
查看>>
几种排序写法
查看>>
java 多线程的应用场景
查看>>
dell support
查看>>
转:Maven项目编译后classes文件中没有dao的xml文件以及没有resources中的配置文件的问题解决...
查看>>
MTK android 设置里 "关于手机" 信息参数修改
查看>>