Mastering GitHub Actions: A Hands-On Guide
Step-by-step tutorials for undergraduate developers to automate workflows.
Creating Your First Example Workflow
Learn the basics of GitHub Actions by creating a simple automated greeting [1, 2].
The Code (.github/workflows/hello-world.yml)
name: Greet User
on: [push]
jobs:
hello-job:
runs-on: ubuntu-latest
steps:
- name: Say Hello
run: echo "Hello, GitHub Actions!"
How-to Run
- Create a directory named
.github/workflowsin your repo root. - Save the code above as
hello-world.yml. - Commit and push to GitHub. Navigate to the Actions tab to see it run.
date command.
Building and Testing Code (Python Example)
Automate your Continuous Integration (CI) to ensure code quality with every push [1, 2].
The Code (.github/workflows/python-app.yml)
name: Python Package
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run Tests
run: pytest
How-to Run
Ensure your repo has a requirements.txt and a tests/ directory. Push your code, and GitHub will automatically install dependencies and run tests [2].
Creating Custom Actions
Go beyond pre-built tools by creating your own JavaScript or Composite actions [2, 3].
The Code (action.yml)
name: 'Hello World Action'
description: 'Greet someone'
inputs:
who-to-greet:
description: 'Who to greet'
required: true
default: 'World'
runs:
using: 'node20'
main: 'index.js'
How-to Run
Define your metadata in action.yml and your logic in index.js. You can then reference this action in any workflow using uses: ./path-to-action [3].
Managing Work with Actions
Automate project management tasks like labeling issues or closing inactive ones [2, 3].
The Code
name: Label Issues
on:
issues:
types: [opened]
jobs:
label_issue:
runs-on: ubuntu-latest
steps:
- name: Label as 'triage'
uses: actions/github-script@v7
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['triage']
})
How-to Run
This workflow triggers whenever a new issue is opened. It uses the GITHUB_TOKEN for authentication [1, 2].
Storing Data and Using Services
Learn to store workflow artifacts and use containerized services like Redis or PostgreSQL [2, 3].
The Code (Artifact Upload)
- name: Archive production artifacts
uses: actions/upload-artifact@v4
with:
name: dist-files
path: dist/
How-to Run
Use the upload-artifact action to save build results. For databases, use services in your job definition to spin up a Docker container [2].