Automatically build and publish via Travis CI and Github

This is a simple guide about how to automatically build and publish via Travis CI and Github.

biicode, Travis CI and Github: a C/C++ dev environment

GitHub allows us to create a remote repository to develop collaboratively.
Travis CI provides continuous integration inside our projects.

logotravis

Import from GitHub!

First of all make sure you’ve installed biicode and Git.
Once both you got both of them, you can clone the github repository you want to make a new biicode block.

clone

Create the new BIICODE project (as usual) and create q working local copy in your biicode block:

Now we’ve got everything we need to start working locally.

Automatically build your projects via Travis CI

Travis CI provides continuous integration inside your project, to use it, just create a file named “.travis.yml” inside your project folder.

Write on your “.travis.yml” file, the commands to build your project, and if it successes publish it automatically to BIICODE.

First of all sign up in Travis CI with your GitHub account and once there, go to your profile, sync your repos and enable Travis CI building:travis-ci

To use Travis CI in your project you’ve got to be using a Linux machine (you can use: Koding, Cloud9IDE or just a virtual machine on your computer). Once in your linux machine check if ruby is installed:

if you see a path such as /usr/bin/ruby, Ruby is installed.

If ruby is not installed:

When ruby is installed:

Please check Travis docs or stackoverflow related issues if your having any troubles installing travis gem.

Now, create your “.travis.yml” file like the example below on your block folder, this file is to building and automatically publishing to biicode, after that it will check if your biicode.conf file [parents] have been updated while publishing and committing the changes to github. This is the one I’m using, don’t forget to adjust the config and “the env” it to your needs:

“.travis.yml”

Let’s take a deeper look this file, as you can see there are 6 different parts in the Build Lifecycle as explained in Travis CI docs (language, compiler, before_install, install, script, after_success):

  • Language and compiler are totally clear (this is where you choose the language and compiler that Travis CI will use).
  • Before_installing, stablishes our automatic commit must be ignored and configures git to push later, on the after_success part.
  • Install provides the tools necessary to test our code with BIICODE.
  • Script part creates, builds and runs the project and checks if the project successes.
  • After_success part is to publish your project to biicode as STABLE with VERSION_TAG if tagged in github, otherwise it publishes as DEV. Also, if your biicode.conf file is updated, this commits its changes to github without launching a new build.
  • env: replace all environment values with your own ones. Don’t delete the ***travis***  text, as it is the one needed to specify that commit should skip build, avoiding entering an endless build loop.

Encrypting

Create a GitHub Personal Access Token

Use this GitHub guide to create your personal access token.

Encode your password

And now, encode your github token and biicode password (to archive this you’ve got to locate in your block’s folder). This command automatically writes the value returned to your “.travis.yml” file:

The lines added should look like this one:

To more information about this, you can take a look at Travis CI docs.

It’s a good practice to add to your readme the build status image Travis CI gives you here:

 

badge_travis

Update your GitHub!

Once you’ve updated your repo locally, add all files and updates via git:

and commit your updates:

Now, send those updates to your remote repository:

Build each commit

So whenever you want to check your build, just press the build status image and it will directly get into the Travis CI build.

travis2

So this is it, enjoy!

Check it out

Post’s original marterial is:

If you liked this post please comment below. If you want to try biicode just click on the sidebar button and if you have any doubts check our docs, forum, Stackoverflow tag and Github repos.


Related Posts
  • Pingback: How to upload to biicode. Example 4: Oscpack by Ross Bencina - biicode Blog()

  • Pingback: biicode 2.0 is out! - biicode Blog()

  • Pingback: Blog de la Escuela de Educación Secundaria Técnica N 8 de Quilmes()

  • http://blog.florianwolters.de Florian Wolters

    I am using a Microsoft Windows operating system with Ruby 2.0.0 and Travis 1.74. I followed the instructions in the article but I can not generate an encrypted value with the travis CLI tool: not logged in, please run travis login --pro. Is now a professional account required to encrypt data?! I’ve tried logging in via travis login --pro --github-token , but then I get the following error message: has not granted Travis CI the required permissions, please log in via magnum.travis-ci.com. I granted all permissions to the token. Do you have any hints for me? Maybe I try it again with a *-nix VM… Off-topic: CMake 3.1.0 is out, do you plan to host that version too?

    • biicode

      Hi Florian,

      thanks for the comment. Could you post it either in our forum or in Stackoverflow to be properly addressed by our team? You have the links to both the Forum and the Stackoverflow tag at the end of the article.

      Thanks again and happy Xmas.

      • http://blog.florianwolters.de Florian Wolters

        Thanks four your reply. I’ve just tested it again with a openSuSE VM and it seems like a “Travis Pro” account is required. It would be nice to mention that in your blog post. With the current situation biicode/Travis CI integration does not make sense for private non-commercial users, since a Travis CI Pro membership costs 129 USD per year.

        Hint: https://magnum.travis-ci.com represents “Travis CI Pro”, wheras https://travis-ci.com represents the normal “Travis CI”.

        I will try a simple Git hook as described in your blog post http://blog.biicode.com/git-hooks next…

        Happy New Year!

        • biicode

          Hi Florian,

          We do not have premium accounts in Travis CI. We wish!! This is the official example of how we deploy to Travis:

          https://github.com/Manu343726/CppMath

          If you follow strictly what we describe in the example a Travis CI premium account is not required at all.

          • http://blog.florianwolters.de Florian Wolters

            Hi again,

            thanks. The encoding with travis is working for me now (both with Microsoft Windows and openSuSE 13.1). The problem has been on my side, something was messed up with the Travis CI integration because I renamed my GitHub repository.

            I will keep using Git hooks anyway, since that way I don’t have code specific to Biicode in my Git repositories. I think that is much cleaner (example: https://github.com/FlorianWolters/cpp-component-util-singleton/blob/master/.travis.yml).
            The only thing I have to figure out is how-to detect tags in a Git commit and forward them to Biicode. With such a workflow both Git and Biicode don’t rely on each other.

            Glad, you could also fix some errors in your post.

            Regards.

          • biicode

            Thank you Florian! Happy New Year.

          • biicode

            Thank you Florian!

          • María

            Hi Florian,

            You may be intrested in checking: http://blog.biicode.com/appveyor-ci-windows-biicode/, this relys totally on github, it even updates your repo’s biicode.conf [parents] section after publishing to biicode.

            Also you can add your tag to your travits build like this:

            bii publish –tag STABLE –versiontag=$TRAVIS_TAG

  • Pingback: Getting started with OpenSSL, Git and Github - biicode Blog()