
Automate your Tasks with Travis CI
5 June, 2023
10
10
0
Contributors
Introduction
Hello, everyone! My name is Hasnain Makada, and I am currently serving as a Founding Creator and Chief Creative Officer (CCO) at Showwcase. I am also an MLSA beta at Microsoft. In this role, I have the opportunity to explore and learn about various technology tools while sharing my knowledge with the community through blogs on Hashnode and Showwcase.
In this blog, I am going to give you an introduction to Travis CI, we're going to see how Travis CI works and I will also show you how to use Travis CI in your GitHub Projects.
So without wasting any furthermore time, Let's get started.
What is TravisCI?
TravisCI is a continuous integration platform which is completely hosted on the web. It is used to perform testing on projects which are hosted on GitHub, BitBucket, GitLab etc... with the help of TravisCI, you can easily test out certain tasks such as building up certain parts frequently or performing tests at a scheduled time of the day etc. TravisCI was the first open-source CI service which provided its platform for free to open-source projects and continues to do so. Though it also has a free plan which provides custom deployments of a proprietary version on the customer's own hardware.
The main goal of Travis CI is to provide a continuous integration development platform that enables software teams to build, test, and deploy their projects with confidence. It serves as a middleman that helps prevent breaking the code by integrating new blocks of code with the primary code branch.
Features of TravisCI
There are so many features of TravisCI, some of which are discussed below 👇
- Continues Integration
Travis CI allows you to build, test and deploy your code whenever any changes are pushed to your main repository. The user just needs to add a .travis.yml
file and they are good to go, Travis CI also supports various programming languages so it is efficient for the user to try out Travis CI on various languages.
- Multiple Platform Support
Since Travis CI is a web-based tool, it is supported in multiple operating systems such as Linux, Windows and macOS.
- Deployment Options
Once you are done with the CI part in Travis C, you can easily deploy your code to multiple platforms such as AWS, Google Cloud, Heroku, Vercel etc... Travis CI provides support for various cloud integration inside it.
- Build Notifications
Once you've successfully integrated Travis CI inside your GitHub Project, you can easily opt for the build notifications status. Travis CI provides real-time notifications about build status and results through various channels, including email, chat applications, and version control system integration
- Customization and Extensibility
Travis CI provides customizations through its configurations file, you can define your own build steps, your environment variable, your personal OS on which you want your project to run and many more things, so with the help of Travis CI, you can scale your project as per your need.
Getting Started with Travis CI
To get started with Installing Travis CI, it's pretty easy, Head over to Travis-ci.com and Sign up with Github. Then it will ask for some verifications and once you are done with it, it will automatically redirect you to the web portal of TravisCI
If you still have any further doubts, go to the 👇
Once you are done with the installation, Let's get started with the Project.
Testing out Travis CI
In this section, we're going to see the hands-on demo of Travis CI in Flutter, I am going to create a Flutter app inside which I'll create the .travis.yml
file and inside the file I am going to write the building and testing steps of my Flutter app.
So Let's begin 🔥
1. Creating the Flutter App
Open your terminal and run the below command for creating the Fluter app,
flutter create travis_ci_example
Wait for a few seconds and your app will get created successfully.
2. Define the configuration file
We're generally going to use the simple counter app which Flutter provides to us every time we create a new project in it. So right now, we're not going to design itbut you can do it if you wish.
cd travis_ci_example
touch .travis.yml
Note: The name of the file should be.travis.yml
only and not.travis.yaml
as it can not differentiate between.yml
and.yaml
Flutter.
Now inside the configuration file, paste these configurations for our Flutter app 👇
os:
- linux
sudo: false
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- libstdc++6
- fonts-droid-fallback
before_script:
- git clone https://github.com/flutter/flutter.git -b beta
- ./flutter/bin/flutter doctor
script:
- ./flutter/bin/flutter pub get
cache:
directories:
- $HOME/.pub-cache
os
:- The
os
section specifies the operating system(s) on which the build will run. In this case, it is set tolinux
, indicate that the build will be performed on a Linux-based system.
- The
sudo: false
:- This line disables sudo (superuser) access for the build, indicating that the build doesn't require administrative privileges.
addons
:- The
addons
section defines additional packages and sources to be installed on the build system. apt
refers to the Advanced Package Tool, used in Debian-based Linux distributions.sources
specifies the package repositories to be added. Here,ubuntu-toolchain-r-test
is added as a source.packages
lists the packages to be installed. In this case,libstdc++6
andfonts-droid-fallback
are included.
- The
before_script
:- The
before_script
section contains the commands that will be executed before the actual script. git clone
https://github.com/flutter/flutter.git
-b beta
clones the Flutter SDK repository from GitHub, specifically thebeta
branch../flutter/bin/flutter doctor
runs theflutter doctor
command, which checks the Flutter environment and prints diagnostic information.
- The
script
:- The
script
section contains the commands that will be executed as the main build script. ./flutter/bin/flutter pub get
runs theflutter pub get
command, which fetches and updates the project's dependencies using the Flutter package manager (pub
).
- The
cache
:- The
cache
section defines directories that Travis CI should cache between builds to speed up subsequent builds. $HOME/.pub-cache
refers to the.pub-cache
directory located in the user's home directory. It is the location where Flutter stores downloaded packages.
- The
In summary, this Travis CI configuration sets up a Linux-based build environment, installs additional packages (libstdc++6
and fonts-droid-fallback
), clones the Flutter SDK repository, checks the Flutter environment, fetches project dependencies usingflutter pub get
, and caches the .pub-cache
directory for future builds.
Push the code to GitHub
Now that we've defined the configuration file for our Flutter app, push the code.
git add .
git commit -m '[add] .travis.yml'
git remote add origin <add-your-repo-url>
git push origin <branch-name>
Head over to Travis CI
After pushing your code to GitHub, Head over to your Travis CI dashboard.
Go to more options 👇
And click on trigger build, wait for a few minutes and your build will get completed successfully.
You can see the build logs also to check whether your build provided you with your expected output or not.
More to explore
What we saw in the above sections was just a demo of Travis CI, I've gone through testing out Travis CI in a simple counter app of Flutter, but you can explore more of its features from the official documentation, Try it, test it and explore enormous features from here 👇
FAQ's
- What is Travis CI?
- Travis CI is a popular continuous integration and deployment platform that automates the building, testing, and deployment of software projects. It helps streamline the development process by providing a robust infrastructure for running tests and deploying applications.
- How does Travis CI work?
- Travis CI integrates with your version control system (such as GitHub or Bitbucket) and monitors your repositories for changes. When changes occur, Travis CI automatically triggers a build process according to your configuration file. It then builds your project, runs tests, and can deploy the application if all tests pass.
- What programming languages does Travis CI support?
- Travis CI supports a wide range of programming languages, including popular ones like JavaScript, Python, Ruby, Java, C/C++, and more. It provides language-specific build environments and tools to accommodate different project requirements.
- Can I use Travis CI for open-source projects?
- Absolutely! Travis CI has extensive support for open-source projects. It offers free plans specifically designed for open-source repositories, allowing developers to benefit from continuous integration without incurring additional costs.
- Can I deploy my application using Travis CI?
- Yes, Travis CI provides deployment capabilities. It supports deploying applications to various platforms and services, such as cloud providers (e.g., AWS, Azure, Google Cloud), hosting services (e.g., Heroku, GitHub Pages), or custom servers. You can configure the deployment settings in your Travis CI configuration file.
Wrapping Up!!!
I hope that this blog has provided you with a general overview of what TravisCI is and how we can use it to make our projects easier to manage. If you have any doubts related to Flutter or DevOps, feel free to reach out on Twitter and Showwcase.
Till then, Happy Coding 😃
github
devops
cicd
automation
travisci