DEV Community

WH yang
WH yang

Posted on

Meet GitHub Actions

Continuous Integration (CI) with GitHub Actions

What is CI?

Continuous Integration (CI) is a process that automatically tests the latest code to ensure everything works as expected. There are many ways to set up CI, but I find GitHub Actions the easiest to use when hosting a project on GitHub.


Why Use GitHub Actions?

GitHub Actions runs your project's tests automatically whenever you need it. For example, it can trigger tests when you:

  • Push a new commit
  • Open a pull request

This ensures that any new changes won’t break existing features. It gives me confidence before merging anything into the main branch.


Is It Free?

  • For public repositories: GitHub Actions is completely free.
  • For private repositories: You can still configure self-hosted runners and use them for free.

How to Set It Up?

  • Enable GitHub Actions

    Go to your repository, click the "Actions" tab, and enable it.

    GitHub Actions button

  • Add a YAML Configuration File

    Create a .yml file inside the .github/workflows folder. Here's an example from my Repopal project:

   name: Node.js CI

   on:
     pull_request:
       branches:
         - main
     push:
       branches:
         - main

   jobs:
     build:
       runs-on: ubuntu-latest

       steps:
         - uses: actions/checkout@v4
         - uses: volta-cli/action@v4
         - run: npm ci --no-audit
         - run: npm run lint --if-present
         - run: npm run prettier:check --if-present
         - run: npm test
         - run: npm run build --if-present
Enter fullscreen mode Exit fullscreen mode
  • Optimize Your Workflow Use options like --silent or --no-color in your commands to speed things up and reduce unnecessary output. If any command fails (returns a non-zero exit code), the job will be marked as failed.

GitHub also provides step-by-step tutorials to help you get started.


What’s Next?

Once your CI is up and running, you can focus on improving it:

  • Increase Test Coverage: Add more tests to cover different scenarios.
  • Static Code Scanning: Use tools like GitHub CodeQL (built-in) or third-party options like SonarQube to scan your code for issues.

Security is just as important as functionality, so integrating automated security checks is a great next step.

GitHub CodeQL

Top comments (0)