Skip to content

GitHub Actions

Actions is a hosted CI/CD solution provided by GitHub. It can take care of handling infrastructure and provide you with set of reusable scripts which can help speed up building your CI/CD pipeline.

Free

GitHub Actions comes with Free tier for public repository and its about 2,000 minutes per month. To control this and stay within your free limits, you should not run for every commit you do and its best practice to run this only on the main branch after you have completed a feature.

Installing Actions

There is no need to maintain any infrastructure or software for this purpose. GitHub manages it for you, hence its a SaaS or managed solution.

Sample Actions pipeline

To enable CI or CD on your code, all you need to do is include a file structure and a yaml file with the scripts.

.github
└── workflows
    └── node.js.yml
yml
name: Node.js CI
on:
  push:
    branches: [ "main" ]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js 18.x
      uses: actions/setup-node@v3
      with:
        node-version: 18.x
        cache: 'npm'
    - run: npm install
    - run: npm run build

Explanation

  1. This script defines a CI pipeline with one job build and triggered whenever there is a code push on main branch
  2. Each job runs on a specific instance and os ubuntu-latest
  3. Then the sequence of steps defined are run one by one.
  4. uses defines a predefined scripts to invoke or if for any custom commands uses run
  5. The sh command executes shell commands like building with Maven and running a deployment script.

Released under the MIT License. Some of the contents are generated using Gen AI