How to Create Automated Workflows with GitHub Actions
GitHub Actions lets you automate repetitive development tasks directly inside your repository. In this GitHub Actions tutorial, you will learn how to create simple workflows for build, test, and deployment tasks. It is a practical way to improve CI/CD GitHub workflows, reduce manual steps, and support better DevOps automation.
What GitHub Actions Does
GitHub Actions runs workflows based on events in your repository, such as a push, pull request, or release. Each workflow is defined in a YAML file stored in .github/workflows/. A workflow contains one or more jobs, and each job contains steps such as checking out code, installing dependencies, and running tests.
This makes GitHub Actions useful for linting, building applications, automated testing GitHub pipelines, publishing packages, and deployment.
Create Your First Workflow
Start by creating a file named .github/workflows/ci.yml. The example below runs when code is pushed or when a pull request is opened against the main branch.
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm testThis workflow has a single job called test. It checks out the repository, sets up Node.js, installs dependencies, and runs tests. For many teams, this is the foundation of CI/CD GitHub workflows.
Understand the Core Parts
Triggers
The on section defines when the workflow runs. Common triggers include push, pull_request, workflow_dispatch, and release. Use workflow_dispatch when you want to run a workflow manually from GitHub.
Jobs
Jobs are groups of steps executed on a runner. Jobs can run independently or depend on each other. For example, you might have one job for testing and another for deployment.
Steps
Steps are the individual tasks inside a job. A step can either run shell commands or call a reusable action from the GitHub Marketplace.
Add Automated Testing
One of the most common uses of GitHub Actions is automated testing GitHub repositories before merge. This helps catch bugs early and keeps the main branch stable. You can also add linting to enforce code quality.
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run lint
- run: npm testWith this setup, every pull request can be validated automatically. That saves review time and strengthens your DevOps automation process.
Create a Simple Deployment Workflow
After tests pass, you may want to deploy automatically. A basic approach is to run deployment only after the test job succeeds.
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo "Tests passed"
deploy:
needs: test
runs-on: ubuntu-latest
steps:
- run: echo "Deploying application"In real projects, replace the placeholder command with your cloud, container, or hosting deployment command. Store secrets like API keys in GitHub repository secrets instead of hardcoding them in workflow files.
Best Practices for GitHub Actions
Keep workflows small
Start with one focused workflow for testing, then expand to build and deploy stages as needed.
Use official actions
Prefer trusted actions such as actions/checkout and actions/setup-node for reliability and security.
Protect secrets
Use GitHub Secrets for tokens, credentials, and environment variables used by CI/CD GitHub workflows.
Monitor runs
Check the Actions tab in GitHub to review logs, debug failures, and optimize runtime.
Conclusion
GitHub Actions is a fast and accessible way to automate builds, tests, and deployments. With a simple YAML file, you can create reliable CI/CD GitHub workflows, improve automated testing GitHub processes, and build stronger DevOps automation into your development lifecycle. If you are just getting started, begin with one test workflow and expand it gradually as your project grows.