0
0
Gitdevops~30 mins

GitHub Actions basics - Mini Project: Build & Apply

Choose your learning style9 modes available
GitHub Actions basics
📖 Scenario: You are working on a small project and want to automate a simple task using GitHub Actions. This will help you run commands automatically whenever you push code to your repository.
🎯 Goal: Create a basic GitHub Actions workflow file that runs a simple command when code is pushed to the main branch.
📋 What You'll Learn
Create a YAML file for GitHub Actions workflow
Set the workflow to trigger on push to the main branch
Add a job that runs on the latest Ubuntu runner
Add a step to run a simple shell command
💡 Why This Matters
🌍 Real World
Automating tasks like testing, building, or deploying code whenever changes are pushed to a repository.
💼 Career
Understanding GitHub Actions is essential for DevOps roles to implement continuous integration and continuous deployment pipelines.
Progress0 / 4 steps
1
Create the workflow file
Create a file named .github/workflows/main.yml with the initial YAML structure starting with name: CI and on: push to trigger on any push.
Git
Need a hint?

Start with the workflow name and the event trigger.

2
Specify the branch trigger
Modify the on: push section to trigger only when code is pushed to the main branch by adding branches: [main].
Git
Need a hint?

Use the branches key under push to limit triggers.

3
Add a job to run on Ubuntu
Add a job named build that runs on ubuntu-latest using runs-on key.
Git
Need a hint?

Jobs run on runners like Ubuntu. Use runs-on to set it.

4
Add a step to run a shell command
Inside the build job, add a steps section with one step that uses run: echo "Hello from GitHub Actions!".
Git
Need a hint?

Steps are a list of commands or actions. Use - run: to run shell commands.