CI/CD with GitHub Actions

CI/CD with GitHub Actions

Written by Gopakumar Gopalan,
on Monday, May 4, 2020

CI/CD (Continuous Integration / Continuous Deployment) is an integral part of modern software development. Usually a CI/CD server like Jenkins which runs the task of compilation and deployment, or services like TravisCI, CircleCI, Buddy etc which access your remote GIT repo like GitHub and setup CI/CD workflows.

GitHub Actions is out now. With GitHub Actions you can build end-to-end continuous integration (CI) and continuous deployment (CD) capabilities directly in your repository.

GitHub Actions are enabled by default to all new repositories created. But for some old repositories it may not be enabled by default. In your GitHub repository check if you have an Actions tab.

Actions Tab

If you are not able to find the Actions tab, go to the Settings tab.

Settings Tab

And on side menu, go to Actions.

Actions Settings

If the Actions are disabled in the settings as above, Select Enable local and third party Actions for this repository.

Enable Actions

Now you have the Actions enabled for your GitHub repository. You can either choose a ready made action or create a custom action within the Actions tab. 

The best way of setting up an action is by creating an YAML file under .github/workflows/ directory in your project. Do the following commands to create a workflow file called build.yaml. You can name the file whatever you wish.

# Create workflow directory if not exists, skip if you already have the directory

mkdir -p .github/workflows

# Create a workflow file named build.yaml

touch .github/workflows/build.yaml

You must have a basic knowledge of YAML format. In the YAML file, you need to keep the indentation correct, else the workflow won't work. You can use the content of the GIST to create a workflow to compile and deploy a React.js application through FTP.

If you examine the build.yaml file. You see on top level (without any indentation) name which as name says the display name of the workflow, next is on, which determines on which event the workflow should be executed. It can be a push, pull_request, issue etc. You can find more about triggering events for GitHub actions here. Our build.yaml file will be triggered on a push to release branch.  Another top level element is jobs. This is where all the workflow logic is described. The secondary elements under jobs are job names which can be any thing. In our workflow, there is only one job called build. You can find more information on Workflow Syntax for GitHub Actions here.  The FTP host, username and password are saved in GitHub secret. Which you can accessed by ${{secrets.YOUR_SECRET_KEY}}. Please refer Creating and storing encrypted secrets for more information.

You may find more actions like kevinpainchaud/simple-ftp-deploy-action , found in the workflow which uses FTP to deploy the compiled files to the server, in GitHub Marketplace.

Is GitHub Actions free?

GitHub Actions is free for public repositories. For private repositories, we have a monthly free tier. It depends on the OS you are using for the workflow build process. In Linux you will get 2000 minutes every month. For window, 1000 minutes as the time multiplier is x2 and MacOS have a x10 time multiplier and you will get only 200 minutes. 

Any minute exceeding the free tier will be billed. You can find Billing for GitHub Actions here.

CI/CD (Continuous Integration / Continuous Deployment) is an integral part of modern software development. Usually a CI/CD server like Jenkins which runs the task of compilation and deployment, or services like TravisCI, CircleCI, Buddy etc which access your remote GIT repo like GitHub and setup CI/CD workflows.

GitHub Actions is out now. With GitHub Actions you can build end-to-end continuous integration (CI) and continuous deployment (CD) capabilities directly in your repository.

GitHub Actions are enabled by default to all new repositories created. But for some old repositories it may not be enabled by default. In your GitHub repository check if you have an Actions tab.

Actions Tab

If you are not able to find the Actions tab, go to the Settings tab.

Settings Tab

And on side menu, go to Actions.

Actions Settings

If the Actions are disabled in the settings as above, Select Enable local and third party Actions for this repository.

Enable Actions

Now you have the Actions enabled for your GitHub repository. You can either choose a ready made action or create a custom action within the Actions tab. 

The best way of setting up an action is by creating an YAML file under .github/workflows/ directory in your project. Do the following commands to create a workflow file called build.yaml. You can name the file whatever you wish.

# Create workflow directory if not exists, skip if you already have the directory

mkdir -p .github/workflows

# Create a workflow file named build.yaml

touch .github/workflows/build.yaml

You must have a basic knowledge of YAML format. In the YAML file, you need to keep the indentation correct, else the workflow won't work. You can use the content of the GIST to create a workflow to compile and deploy a React.js application through FTP.

If you examine the build.yaml file. You see on top level (without any indentation) name which as name says the display name of the workflow, next is on, which determines on which event the workflow should be executed. It can be a push, pull_request, issue etc. You can find more about triggering events for GitHub actions here. Our build.yaml file will be triggered on a push to release branch.  Another top level element is jobs. This is where all the workflow logic is described. The secondary elements under jobs are job names which can be any thing. In our workflow, there is only one job called build. You can find more information on Workflow Syntax for GitHub Actions here.  The FTP host, username and password are saved in GitHub secret. Which you can accessed by ${{secrets.YOUR_SECRET_KEY}}. Please refer Creating and storing encrypted secrets for more information.

You may find more actions like kevinpainchaud/simple-ftp-deploy-action , found in the workflow which uses FTP to deploy the compiled files to the server, in GitHub Marketplace.

Is GitHub Actions free?

GitHub Actions is free for public repositories. For private repositories, we have a monthly free tier. It depends on the OS you are using for the workflow build process. In Linux you will get 2000 minutes every month. For window, 1000 minutes as the time multiplier is x2 and MacOS have a x10 time multiplier and you will get only 200 minutes. 

Any minute exceeding the free tier will be billed. You can find Billing for GitHub Actions here.

Related Tags :

> @GKWrites > CI/CD with GitHub Actions