Total Pageviews

Showing posts with label travis ci. Show all posts
Showing posts with label travis ci. Show all posts

Friday, 20 February 2026

Automate Deploys With Travis

 

Using Travis CI is a great way to automate repetitive tasks like building and testing your projects. But recently I've been using it to automate deployments to github pages and it's been great. I have read a few tutorials that outlined similar steps, but they didn't quite have the results I wanted so I decided to write my own. To automate deploying to github pages with Travis, here's the steps I followed:

  1. Get a personal access token from github.com Note: You only get to see this key once.

  2. Setup your repository in Travis (at https://travis-ci.org/) I also suggest limiting concurrent builds to 1 in the repo's Travis settings so that builds run sequentially.

  3. npm install -g travis-encrypt (https://www.npmjs.com/package/travis-encrypt)

  4. travis-encrypt -r [repository slug] GITHUB_TOKEN=[personal access token] Note: The repository slug includes your username.

  1. Then setup your .travis.yml file, you need to changes the GITHUB_REPO and secure options.
language: node_js
node_js:
  - "6.9"
sudo: false
branches:
  only:
    - master
install:
- npm install
script:
- npm run build
after_success:
- bash ./travis-deploy.sh
env:
  global:
    - GITHUB_REPO: [repository slug]
    - secure: [result from travis-encrypt command]
  1. And include the travis-deploy script:
#!/bin/bash
set -o errexit

# Info.
echo "Running deploy script"
echo "Branch: $TRAVIS_BRANCH"
echo "Is a Pull Request: $TRAVIS_PULL_REQUEST"

# Exit if the branch is not the master branch.
if [ "$TRAVIS_BRANCH" != "master" ]
then
  echo "This commit was made against the $TRAVIS_BRANCH and not the master. No deploy."
  exit 0
fi

# Exit if the commit is a pull request.
# We only want to build / deploy when pull requests are merged into master.
if [ "$TRAVIS_PULL_REQUEST" != "false" ]
then
  echo "This commit is a pull request. No deploy."
  exit 0
fi

# Git config.
git config --global user.email "nobody@nobody.org"
git config --global user.name "Travis CI"

# Build steps (taken care of beforehand)

# Deploy.
cd build
git init
git add .
git commit -m "Deploy to Github Pages"
git push --force --quiet "https://${GITHUB_TOKEN}@github.com/${GITHUB_REPO}.git" master:gh-pages > /dev/null 2>&1
  1. Also, make the gh-pages branch on github before running the above script from travis-ci just to be safe.

This will deploy to the gh-pages branch on any commits into master as long as the build finishes successfully [even if not done through a pull request in case of emergencies ;)]. On pull requests, travis will still try and build the branch to make sure that succeeds, but it won't push any of the changes to gh-pages branch.

from  https://blog.timscanlin.net/posts/2016/automated-deploys-with-travis/

related post:  https://briteming.blogspot.com/2016/07/create-static-site-with-hakyll-github.html

Sunday, 17 December 2023

学会使用Travis CI

了解持续集成的做法,学会使用Travis CI.

操作步骤

(1)注册 Github 的账户。如果你已经注册过,跳过这一步。

(2)访问这个代码库github.com/ruanyf/travis-ci-demo,点击右上角的Fork按钮,将它克隆到你自己的空间里面。

(3)将你fork的代码库,克隆到本地。注意,要将下面网址之中的[your_username]改成你的 Github 用户名。

// Linux & Mac
$ git clone git@github.com:[your_username]/travis-ci-demo.git

// Windows
$ git clone https://github.com:[your_username]/travis-ci-demo

(4)使用你的 Github 账户,登录 Travis CI 的首页。然后,访问 Profile 页面,选定travis-ci-demo代码库运行自动构建。

(5)回到命令行,进入你本地的travis-ci-demo目录,切换到demo01分支。

$ cd travis-ci-demo
$ git checkout demo01

项目根目录下面有一个.travis.yml文件,这是 Travis CI 的配置文件。如果没有这个文件,就不会触发 Travis CI 的自动构建。打开看一下。

language: node_js
node_js:
  - "node"

上面代码指定,使用 Node 完成构建,版本是最新的稳定版。

指定 Node 的版本号也是可以的。

language: node_js
node_js:
  - "4.1"

上面代码指定使用 Node 4.1 版。

(6)Travis CI 默认依次执行以下九个脚本。

  • before_install
  • install
  • before_script
  • script
  • after_success 或者 after_failure
  • after_script
  • before_deploy(可选)
  • deploy(可选)
  • after_deploy(可选)

用户需要用到哪个脚本,就需要提供该脚本的内容。

对于 Node 项目,以下两个脚本有默认值,可以不用自己设定。

"install": "npm install",
"script": "npm test"

(7)打开当前分支的package.json,可以发现它的test脚本是一个lint命令。

"scripts": {
  "test": "jshint hello.js"
},

(8)在项目根目录下,新建一个新文件NewUser.txt,内容是你的用户名。提交这个文件,就会触发 Travis CI 的自动构建。

$ git add -A
$ git commit -m 'Testing Travis CI'
$ git push

(9)等到 Travis CI 完成自动构建,到页面上检查构建结果。

(10)切换到demo02分支,打开package.json,可以看到test脚本,现在需要完成两步操作了。

  "scripts": {
    "lint": "jshint hello.js hello.test.js",
    "test": "npm run lint && mocha hello.test.js"
  },
(11)重复上面第 8 步和第 9 步。

Monday, 18 November 2019

awesome-ci

List of Continuous Integration services

List of Continuous Integration services

Build Status Awesome
Join chat t.me/sqaunderhood and subscribe to receive notificatons with updates.
There are a lot of cloud continuous integration services. All of them have different set of functionality, some of them require payment, some of them are free. I have created a list of such services to make easy comparison of them and choose more suitable for you.
Some of CI services has open source code thus you can setup them in standalone mode. Pay attention to the column "Features".
There is a similar comparison on Wikipedia.
Name Description Features Supported repositories Documentation Price
Abstruse CI Self-Hosted, Open-Source CI Platform. Based on NodeJS and Docker. Languages: everything that can be installed on Linux GitHub, GitLab, BitBucket, Gogs Documentation Open Source
App Center CI Platform. It connects with Hockeyapp where you can store installers and send their by email Compatible with Android, iOS, Xamarin, React Native, Unity, Cordova, macOS, tvOS GitHub, BitBucket, VSTS Documentation Free with limitations
Appveyor AppVeyor automates building, testing and deployment of .NET applications. Languages: C#, Xamarin, F#, VB.NET, C/C++, Node.js, Ruby, TypeScript, Go, Java, Python, Perl, Erlang GitHub, BitBucket Documentation Free with limitations
Assertible Automated post-deployment testing and web service monitoring Example Integrations GitHub Documentation Free with limitations
AWS CodeBuild Fully managed continuous integration service in AWS Docker AWS S3, AWS CodeCommit, Github, Bitbucket Documentation First 100 minutes per month for free, pay-as-you-go later
Azure DevOps (formerly Visual Studio Team Services) Cloud-based collaboration services for version control, agile planning, continuous delivery, and analytics application for Visual Studio, Eclipse, Xcode.
Azure DevOps, GitHub, Custom Documentation Free with monthly build limits
Badwolf Docker based continuous integration and code lint review system for BitBucket Source code is available BitBucket Documentation Free (Open source)
Bamboo Bamboo is a continuous integration and continuous deployment server
Bitbucket (for Bitbucket Cloud), Stash (for Bitbucket Server), Git, GitHub (for GitHub and GitHub Enterprise), Mercurial, Subversion, CVS, Perforce, Custom via plugins Documentation Full Atlassian stack for 10 users: 10$/year ( 100% of payments to charity)
Bitrise Mobile Continuous Integration and Delivery. Source code is available GitHub, BitBucket, Gitlab, Custom Documentation Free with limitations
Buildkite A build automation platform which gives you complete control, without the pain of running your own CI system. Languages: Ruby, Python, Node.js, JavaScript, PHP, Go, Rust, Erlang, Elixir, Java, Clojure, Scala, C/C++, Objective-C, Swift, .NET/C#
Source code is available: Buildkite Agent
GitHub, Bitbucket, GitLab, Custom Documentation 14-day Trial, Free for Education, Open Source
Chrono CI Continuous Integration Security Languages: Ruby on Rails, Python, Node.js, Solidity C, Java, Go GitHub Documentation Free for 100 tests per month
Circle CI Continuous Integration and Deployment
GitHub, Bitbucket Documentation Free for 1 container
CDS Enterprise-Grade Continuous Delivery & DevOps Automation Open Source Platform Languages: everything Github, Bitbucket Server, Gitlab Documentation Free Open Source
Cirrus CI Bring-Your-Own-Infrastructure CI with modern cloud technologies, matrix builds and simple-yet-powerful configuration Flexible execution environment: any Unix or Windows VM, any Docker container, any amount of CPUs, optional SSDs and GPUs GitHub, BitBucket (planned) Documentation Free for Open Source, per-second billing for private projects
Codacy Automated code reviews & code analytics Languages: Scala, Java, JavaScript, Python, Ruby, PHP, Apex, JSP, XML, Velocity, VisualForce, C#, JSON, Kotlin, Markdown GitHub, BitBucket Documentation Free for open-source projects
Code Climate Hosted platform to continuously measure and monitor code quality Languages: Ruby, Javascript, PHP GitHub, Custom Documentation 14-day Trial
CodeFresh Codefresh is a Docker-native CI/CD platform. Instantly build, test and deploy Docker images to Kubernetes Languages: Ruby, Python, Node.js, JavaScript, PHP, Go, Rust, Java, etc GitHub, BitBucket, GitLab, Webhooks Documentation Pricing
Codeship One more cloud based CI service: running tests and deployment Languages: Dart, Elixir, Go, Java and JVM based languages, PHP, Python, Node.JS, Ruby GitHub, BitBucket Documentation Free ebook Free for opensource projects or 100 builds per month
Concourse CI Self-hosted CI solution written in Golang
GitHub, generic oAuth Documentation Free (Open source)
continuousphp Continuous Integration and deployment for projects writtn in PHP Languages: PHP GitHub, BitBucket, GitLab Documentation Free for Open source and educational projects
Coveralls Coveralls works with your continuous integration server to give you test coverage history and statistics. Languages: Ruby, Javascript, Python, PHP, C, Objective-C, Scala, GO GitHub, BitBucket Documentation Free for opensource projects
Coverity Code analysis, test analysis Languages: C/C++, Java, C#
None Free for opensource projects
Drone Continuous Integration service Source code is available. GitHub,BitBucket, Google Code, Custom Documentation Pricing
Ebert Ebert does continuous static analysis of your GitHub repositories and delivers it straight to your Pull Requests, helping your team to focus on what's important and deliver better software. Languages: Apex, C, Clojure, CoffeeScript, CSS, Elixir, Go, Haskell, Haxe, JavaScript, Markdown, PHP, Python, Ruby, SCSS, Shell, Swift, Vim script. GitHub Documentation 100% free for public repositories on GitHub
Evergreen Evergreen is a distributed continuous integration system built by MongoDB. It dynamically allocates hosts to run tasks in parallel across many machines.
GitHub Documentation
GoCD Open source, on-premises continuous delivery tool.
Git, Perforce, Mercurial,Subversion, TFS, Custom Documentation Open Source
GitLab GitLab is a single application for the entire DevOps lifecycle Languages: everything that can be installed on Linux. Compatible with Linux, Windows, Android and iOS GitLab, GitHub, Bitbucket Documentation Open Source plus Free with limitations hosted version
GitGud Free & Reliable Git hosting site powered by GitLab Everything that GitLab does but for free GitLab, Bitbucket, GitHub, Gitea, Clone by URL Documentation Completely Free
Hound CI Hound integrates with your existing workflow by reviewing and commenting on code. Languages: Bash, Elixir, Go, HAML, JavaScript, CoffeeScript, TypeScript, Markdown, PHP, Python, Ruby, Sass/SCSS, Swift GitHub
Public repositories for free
Hydra Nix-based continuous build system

Documentation Opensource (GNU GPLv3)
Jenkins With thousands of plugins to choose from, Jenkins can help teams to automate any task that would otherwise put a time-consuming strain on your software team. Languages: Embedded, PHP, Python, Ruby, Java, Android, C/C++. Any VCS that supports git, mercurial, cvs, subversion Documentation Open Source
Kritika Coverage, Duplications, Code violations Languages: Perl GitHub Documentation Free for public repositories
Peakflow CI builds, error reporting and uptime monitoring Languages: Ruby, PHP, Javascript and anything you can set up yourself. Github Documentation Free for private projects
Previs Use Travis configuration to run stuff locally in a clean environment. Everything that Travis support or almost Your computer, it's running locally! Documentation It's free! Since you are hosting everything locally on your computer!
Probo.CI Continuous Collaboration - break down the barriers between software developers and the other stakeholders involved in a software development project Underlying engine is OSS, offers several Ubuntu base images, asset pre-upload helps build speed. GitHub, BitBucket Documentation 2 month free trial then starts at $30. Pricing
Rocro INSPECODE Review less, move faster. Speed up your software development with Inspecode’s continuous code inspection and automated code correction. Languages: Java, JavaScript, C, C++, Python, Ruby, PHP, Go, Scala, TypeScript, Clojure and more... GitHub, BitBucket Documentation Free with limitations
Saucelabs Automated testing in the cloud for CI

Documentation 14-day Trial
Scrutinizer Build quality software, better Sources are available GitHub, BitBucket Documentation 14-day Trial
Semaphore Hosted continuous integration and delivery solution for open source and private projects. Ruby, Node.js, JavaScript, Go, Clojure, Elixir, Erlang, Java, PHP, Scala, C/C++ GitHub, BitBucket Documentation Free for Open Source, pay only for what you use, first $20 every month on Semaphore (up to 1,300 service minutes)
Shippable Continuous Delivery Languages: Ruby, Python, Java, Node.js, Scala, PHP, Go; Databases: MongoDB, MySQL, Redis, Postgres, CouchDB, RethinkDB, Neo4j, and SQLite GitHub, BitBucket, GitLab Documentation Free with limitations
Sider Increase code review efficiency and deliver products with confidence. Sider helps development teams accomplish more, allowing them to deliver more value to their customers. Supported Analysis Tools GitHub Documentation Free 14-day trial for private repositories, and forever free for open source
StyleCI The Web Coding Style Service, used by Cachet and Laravel. Languages: PHP, JavaScript, TypeScript, Flow, CSS, SCSS, Less, Vue.js, Python GitHub, BitBucket, GitLab Documentation Free for opensource projects
TeamCity A Java-based build management and continuous integration server from JetBrains. Support wide variety of web browsers and build tools Git, Subversion, Perforce, Team Foundation Server, Mercurial, CVS, SourceGear Vault 6 and 7, Borland StarTeam 6 and up, IBM Rational ClearCase, Base and UCM modes, Microsoft Visual SourceSafe 6 and 2005 Documentation Free with limitations
Travis CI Hosted continuous integration service for open source and private projects. Languages: C, C++, Clojure, D, Erlang, Go, Groovy, Haskell, Java, Javascript (with Node.js), Objective-C, Perl, PHP, Python, Ruby, Rust, Scala. Source code is available. GitHub Documentation Free for opensource projects
Wercker Continuous delivery platform
Docker Hub Documentation





Friday, 10 March 2017

把静态博客跟travis ci集成在一起

Step 1 - generate a personal access token at Github

Step 2 - add an environment variable to your Travis-CI project.

  1. Go to project Settings and choose Environment Variables
  2. Variable Name: DEPLOY_REPO
  3. Variable Value: https://{github_access_token}@github.com/{github_username}/{repository_name}.git (for example: https://8260b82839xx2d19387a51bafca4d5425da7@github.com/ruanyl/ruanyl.github.io.git)

Step 3 - edit .travis.yml file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
language: node_js
node_js:
    - "0.12"

before_install:
    - npm install -g hexo

install:
    - npm install

before_script:
    - git config --global user.name 'ruanyl'
    - git config --global user.email 'ruanyu1@gmail.com'

script:
    - hexo generate

after_success:
    - mkdir .deploy
    - cd .deploy
    - git init
    - git remote add origin $DEPLOY_REPO
    - cp -r ../public/* .
    - git add -A .
    - git commit -m 'Site updated'
    - git push --force --quiet origin master

Notice! If you have 3rd party themes installed

You have to add the theme repo as a gitmodule, add a file named: .gitmodules under the root dir of your hexo blog and add:
1
2
3
[submodule "alex"]
    path = themes/alex
    url = https://github.com/ruanyl/hexo-theme-alex.git

from http://blog.bigruan.com/2015-03-09-Continuous-Integration-Your-Hexo-Blog-With-TravisCI/