Hello World in GitHub Actions
Welcome to the first video in our GitHub Actions series! In this tutorial, we'll learn how to create your very first automation workflow.
🎯 What is GitHub Actions?
GitHub Actions is a CI/CD (Continuous Integration and Continuous Delivery) platform that allows you to automate your build, test, and deployment pipeline. You can create workflows that build and test every pull request to your repository, or deploy merged pull requests to production.
📄 The Workflow Code
Create a file at .github/workflows/hello-world.yml and paste the following code:
# Place this file at: .github/workflows/hello-world.yml
#
# WHAT THIS DOES:
# Every time you push code, GitHub will automatically run
# a small job that prints "Hello from Coding Adda!"
# That's GitHub Actions in action (pun intended).
# ============================================================
name: Hello World - My First Action # Display name in GitHub UI
on: # TRIGGER: When should this workflow run?
push: # → On every git push
workflow_dispatch: # → Also allow manual run from GitHub UI
jobs: # A workflow is made of one or more JOBS
say-hello: # Job ID (you choose the name)
runs-on: ubuntu-latest # Which machine to run on (GitHub provides this for free)
steps: # A job is made of sequential STEPS
- name: Print a greeting # Step 1
run: echo "Hello from Coding Adda! 🚀"
- name: Show current date # Step 2
run: date
- name: Show who triggered this # Step 3
run: |
echo "Triggered by: ${{ github.actor }}"
echo "On branch: ${{ github.ref_name }}"
echo "Repository: ${{ github.repository }}"
- name: Run a multi-line script # Step 4 - multi-line commands
run: |
echo "----------------------------"
echo "GitHub Actions is working!"
echo "This is Demo 1 of the series"
echo "----------------------------"🧠Deep Dive: Understanding the YAML
1. The Trigger (on)
The on key defines what events will trigger your workflow. In our case, we have two triggers:
- push
This workflow will run every time you push code to any branch in your repository.
- workflow_dispatch
This allows you to manually trigger the workflow from the "Actions" tab in the GitHub UI.
2. The Job (jobs)
A workflow is composed of one or more jobs that can run in parallel or sequentially.
- say-hello
This is our Job ID. You can name it whatever you like!
- runs-on: ubuntu-latest
This specifies the type of machine to run the job on. GitHub provides several runners, including Ubuntu, Windows, and macOS.
3. The Steps (steps)
Each job is made of sequential tasks called steps. Each step can run commands or call other "Actions".
- Print a greeting
Uses
echoto print a message to the console. - Show current date
Uses the unix
datecommand to show the current timestamp. - Show who triggered this
This step uses GitHub Contexts (
${{ github.actor }}) to display dynamic information about the repository and the person who triggered the run. - Multi-line script
Using the
|character allows you to write multiple lines of bash commands in a single step.
Next Steps
Now that you've built your first Hello World action, in the next section, we’ll:
Secrets Management
Learn how to store sensitive information like API keys securely.
Environment Variables
Understand how to use variables across different steps and jobs.
