Table of Contents
What is GitHub Actions?
GitHub Actions is a platform which allows you to automate the developer workflows.
Workflows such as :-
- Continous Delivery
- Continous Deployement
- Automation
- Security
GitHub Actions are Similar to Devops but has much wider coverage in terms of any automation. It allows you to automate any event that happens in the repository and perform certain automated actions.
Core Components of GitHub Actions
GitHub Actions workflow can be triggered when an event occurs into the repository such as pushing change into master, creating pull request against master, creating/publishing your changes. Workflow contains one/multiple actions which can run sequential or parallel on there dedicated machines/containers.
1. Workflow
Workflow is a configurable process that will run one or more jobs. Workflows are often defined into a yaml/yml file which are part of you repository and can be triggered on an event.
All workflows are defined under .github/workflows directory in the repository.
Each workflow can perform different tasks as :-
- Building an application
- Testing an application/changes
- Deploying your changes after every release.
- Adding label in Jira when ticket is opened.
2. Events
Event can be defined as an activity which triggers a workflow inside the repository. Any event can also be triggered at a specific time.
3. Jobs
A job is a set of steps in a workflow that is executed on the same runner. Each step can be a shell script or an action. These steps are executed in order and are dependent on each other. Since all these steps are on same runner data can be shared between them. For Example you can have a step that build your application followed by a step that tests the application.
4. Actions
An action is a custom application for GitHub actions platform that performs a complex but frequently repeated task. It helps in code re-usability of repeated tasks. An action can pull your Git repository from GitHub, set up the correct toolchain for your build environment , or set up the authentication to your cloud provider.
You can also write your own actions, or you can find actions to use in your workflows in the GitHub Marketplace.
5. Runner
A runner is a server that runs your workflows when they’re triggered. Each runner can run a single job at a time. GitHub provides Ubuntu Linux, Microsoft Windows, and macOS runners to run your workflows. Each workflow run executes in a fresh, newly-provisioned virtual machine.
GitHub Actions YAML Workflow Example
Now Lets understand below workflow example . This workflow builds the project Java Project with maven as build tool on certain actions like push/pull into the repository.
name – Defines the workflow name
on – Event on which workflow will be triggered
jobs – set of steps which will be executed for current workflow
runs – Defines the runner on which all steps will run
actions – pre-defined keyword for invoking different actions
steps – dependent steps which are scripts or pre-defined actions.
name: Java CI with Gradle
on:
push:
branches: [ "main" ]
pull request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
- name: Build with Gradle Wrapper
run: ./gradlew build
dependency-submission:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
GitHub Actions vs Jenkins Pipelines: Key Differences
Over traditional Jenkins pipelines GitHub Actions provides many advantages
Feature | GitHub Actions | Jenkins Pipeline |
Setup | Configuration is in Simple yaml Files. | Configuration is done in Groovy Scripting Language. |
Integration | Actions are natively integrated with GitHub. | Jenkins needs hooks and explicit CI/CD Servers. |
Flexibility | Everything is event based. Which are flexible in nature. | Flexible but configuration is needed for each and every step. |
Maintenance | Managed by dev team as part of application code. | Devops teams are needed to manage. |
Leave a Reply