GitHub Actions for Beginners: Automate Your Workflow in 30 Minutes
Introduction
GitHub Actions is a powerful automation tool built into GitHub that lets you define workflows to build, test, and deploy your code. With a simple YAML file, you can automate repetitive tasks like running tests, deploying apps, or sending notifications. This tutorial will walk you through setting up your first GitHub Action step by step.Step 1: Create a GitHub Repository
Go to GitHub and create a new repository, or use an existing one. Clone it locally if you’d like to follow along with code changes.Step 2: Create the Workflow File
Inside your repository, create a folder named.github/workflows
and then create a YAML file for your workflow, for example ci.yml
.
mkdir -p .github/workflows
nano .github/workflows/ci.yml
Paste the following starter workflow to run tests whenever you push to the main branch:
name: CI
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run a one-line script
run: echo "Hello, world!"
- name: Run a multi-line script
run: |
echo "Installing dependencies"
echo "Running tests"
Step 3: Commit and Push
Once the YAML file is created, add and push the changes:git add .github/workflows/ci.yml
git commit -m "Add CI workflow"
git push origin main
GitHub will automatically detect the new workflow and run it on push.