DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

Weekend Lab β€” Git GitHub Pull Request CI

🎯 Goal

By the end of this lab you should understand this workflow:

Create Project
      ↓
Git
      ↓
Feature Branch
      ↓
Change Code
      ↓
Commit
      ↓
Push
      ↓
GitHub
      ↓
Pull Request
      ↓
Merge
      ↓
git pull
      ↓
GitHub Actions
      ↓
CI
Enter fullscreen mode Exit fullscreen mode

Important: Do the lab yourself. Don't just copy commands. After every important command, ask yourself: What did this command just do?


PART 1 β€” Create Your Project

Open Terminal.

Create a new project:

cd ~

mkdir weekend-devops-lab

cd weekend-devops-lab
Enter fullscreen mode Exit fullscreen mode

Check your location:

pwd
Enter fullscreen mode Exit fullscreen mode

Create:

touch index.html
Enter fullscreen mode Exit fullscreen mode

Open it:

nano index.html
Enter fullscreen mode Exit fullscreen mode

Add:

<!DOCTYPE html>
<html>
<head>
    <title>My DevOps Project</title>
</head>

<body>

<h1>Welcome to My DevOps Project</h1>

<p>Created by YOUR NAME</p>

<h2>Skills</h2>

<ul>
    <li>Linux</li>
    <li>Git</li>
    <li>GitHub</li>
    <li>AWS</li>
</ul>

</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Save.

Check:

ls
Enter fullscreen mode Exit fullscreen mode

PART 2 β€” Initialize Git

Run:

git init
Enter fullscreen mode Exit fullscreen mode

Then:

git status
Enter fullscreen mode Exit fullscreen mode

Question

Why does Git show:

untracked
Enter fullscreen mode Exit fullscreen mode

Answer this yourself before continuing.

Now:

git add index.html
Enter fullscreen mode Exit fullscreen mode

Check again:

git status
Enter fullscreen mode Exit fullscreen mode

Create your first commit:

git commit -m "Create initial website"
Enter fullscreen mode Exit fullscreen mode

Check history:

git log --oneline
Enter fullscreen mode Exit fullscreen mode

PART 3 β€” Create GitHub Repository

Go to GitHub.

Create a repository named:

weekend-devops-lab
Enter fullscreen mode Exit fullscreen mode

For this exercise, create it empty.

Don't add README, .gitignore, or License when creating it.

Connect your local repository to GitHub using the repository URL GitHub gives you:

git remote add origin YOUR-GITHUB-REPOSITORY-URL
Enter fullscreen mode Exit fullscreen mode

Check:

git remote -v
Enter fullscreen mode Exit fullscreen mode

Rename your main branch if needed:

git branch -M main
Enter fullscreen mode Exit fullscreen mode

Push:

git push -u origin main
Enter fullscreen mode Exit fullscreen mode

Now refresh GitHub.

You should see:

index.html
Enter fullscreen mode Exit fullscreen mode

PART 4 β€” Create a Feature Branch

Do NOT change main directly.

First:

git branch
Enter fullscreen mode Exit fullscreen mode

Create:

git switch -c feature-about
Enter fullscreen mode Exit fullscreen mode

Check:

git branch
Enter fullscreen mode Exit fullscreen mode

You should see:

* feature-about
  main
Enter fullscreen mode Exit fullscreen mode

Question

What does * mean?


PART 5 β€” Change Your Website

Open:

nano index.html
Enter fullscreen mode Exit fullscreen mode

Add:

<h2>About Me</h2>

<p>I am learning DevOps Engineering.</p>

<p>This website is managed using Git and GitHub.</p>
Enter fullscreen mode Exit fullscreen mode

Save.

Now do not immediately add it.

First:

git status
Enter fullscreen mode Exit fullscreen mode

Then:

git diff
Enter fullscreen mode Exit fullscreen mode

Look at what changed.

Then:

git add index.html
Enter fullscreen mode Exit fullscreen mode

Check:

git status
Enter fullscreen mode Exit fullscreen mode

Commit:

git commit -m "Add About section"
Enter fullscreen mode Exit fullscreen mode

Check:

git log --oneline
Enter fullscreen mode Exit fullscreen mode

PART 6 β€” Push Your Feature Branch

Push:

git push -u origin feature-about
Enter fullscreen mode Exit fullscreen mode

Open GitHub.

You should now have:

main

feature-about
Enter fullscreen mode Exit fullscreen mode

Question

Is the About section already inside main?

Think before continuing.


PART 7 β€” Pull Request

On GitHub create a:

Pull Request

Use:

base: main

compare: feature-about
Enter fullscreen mode Exit fullscreen mode

Before merging, look at:

Files changed

Read your own changes.

Then merge the Pull Request.

Now:

feature-about
       ↓
Pull Request
       ↓
Review
       ↓
Merge
       ↓
main
Enter fullscreen mode Exit fullscreen mode

PART 8 β€” Very Important Test

Go back to Terminal.

Switch to:

git switch main
Enter fullscreen mode Exit fullscreen mode

Now look at your file:

cat index.html
Enter fullscreen mode Exit fullscreen mode

STOP HERE.

Ask yourself:

I merged the PR on GitHub. Why might my local main still not have the newest change?

Because:

LOCAL != REMOTE
Enter fullscreen mode Exit fullscreen mode

Now run:

git pull origin main
Enter fullscreen mode Exit fullscreen mode

Then:

cat index.html
Enter fullscreen mode Exit fullscreen mode

Check history:

git log --oneline
Enter fullscreen mode Exit fullscreen mode

Your local main should now contain the merged change.


PART 9 β€” Push / Pull / Clone Challenge

Without looking at notes, answer:

I changed code locally and want to send it to GitHub.

Command = ?
Enter fullscreen mode Exit fullscreen mode
Someone changed GitHub and I already have the repository.

Command = ?
Enter fullscreen mode Exit fullscreen mode
I am a new employee and don't have the repository at all.

Command = ?
Enter fullscreen mode Exit fullscreen mode

Answers:

git push

git pull

git clone
Enter fullscreen mode Exit fullscreen mode

PART 10 β€” Create Your First CI

Now add GitHub Actions.

Make sure you're on main:

git switch main
Enter fullscreen mode Exit fullscreen mode

Update it:

git pull origin main
Enter fullscreen mode Exit fullscreen mode

Create the workflow directory:

mkdir -p .github/workflows
Enter fullscreen mode Exit fullscreen mode

Create:

nano .github/workflows/ci.yml
Enter fullscreen mode Exit fullscreen mode

Add:

name: Weekend CI

on:
  push:

jobs:

  test:

    runs-on: ubuntu-latest

    steps:

      - name: Say Hello
        run: echo "Hello from my CI pipeline"

      - name: Check Runner
        run: |
          whoami
          pwd

      - name: Finish
        run: echo "CI PASSED"
Enter fullscreen mode Exit fullscreen mode

Save.


PART 11 β€” Before You Push

Run:

git status
Enter fullscreen mode Exit fullscreen mode

Ask:

What new file does Git see?

Then:

git add .github/workflows/ci.yml
Enter fullscreen mode Exit fullscreen mode

Commit:

git commit -m "Add first CI workflow"
Enter fullscreen mode Exit fullscreen mode

Push:

git push origin main
Enter fullscreen mode Exit fullscreen mode

PART 12 β€” Watch CI

Go to:

GitHub β†’ Repository β†’ Actions

Find:

Weekend CI
Enter fullscreen mode Exit fullscreen mode

Open it.

Find the job:

test
Enter fullscreen mode Exit fullscreen mode

Open the steps.

You should see:

Say Hello
βœ“

Check Runner
βœ“

Finish
βœ“
Enter fullscreen mode Exit fullscreen mode

Congratulations β€” you triggered a CI workflow.

But don't stop at the green checkmark.

You must understand what happened:

git push
    ↓
GitHub received new commit
    ↓
push triggered workflow
    ↓
GitHub created a Runner
    ↓
Runner executed Job
    ↓
Job executed Steps
    ↓
Commands executed
    ↓
CI PASSED
Enter fullscreen mode Exit fullscreen mode

PART 13 β€” Explain Your YAML

Be prepared to explain these on Monday:

name:
Enter fullscreen mode Exit fullscreen mode

What does it mean?

on:
  push:
Enter fullscreen mode Exit fullscreen mode

What does it mean?

jobs:
Enter fullscreen mode Exit fullscreen mode

What is a Job?

runs-on: ubuntu-latest
Enter fullscreen mode Exit fullscreen mode

What is a Runner?

steps:
Enter fullscreen mode Exit fullscreen mode

What are Steps?

run:
Enter fullscreen mode Exit fullscreen mode

What does run do?


PART 14 β€” Troubleshooting Challenge

I don't want them to only follow a happy path.

Change:

- name: Finish
  run: echo "CI PASSED"
Enter fullscreen mode Exit fullscreen mode

temporarily to:

- name: Test Failure
  run: exit 1
Enter fullscreen mode Exit fullscreen mode

Then:

git add .
git commit -m "Test CI failure"
git push
Enter fullscreen mode Exit fullscreen mode

Go to GitHub Actions.

Your pipeline should fail.

Find:

❌
Enter fullscreen mode Exit fullscreen mode

Open the failed job.

Find the failed step.

Then fix the workflow by changing it back to:

- name: Finish
  run: echo "CI PASSED"
Enter fullscreen mode Exit fullscreen mode

Commit and push again:

git add .
git commit -m "Fix CI workflow"
git push
Enter fullscreen mode Exit fullscreen mode

Your goal:

❌ FAILED
     ↓
Investigate
     ↓
Fix
     ↓
Commit
     ↓
Push
     ↓
βœ“ PASSED
Enter fullscreen mode Exit fullscreen mode

This is much closer to what DevOps engineers actually do.


PART 15 β€” Bonus: Deploy It to EC2

Students who finish early should continue.

On Ubuntu EC2:

sudo apt update
sudo apt install git nginx -y
Enter fullscreen mode Exit fullscreen mode

Then:

git clone YOUR-GITHUB-REPOSITORY-URL
Enter fullscreen mode Exit fullscreen mode

Enter repository:

cd weekend-devops-lab
Enter fullscreen mode Exit fullscreen mode

Deploy:

sudo cp index.html /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode

Check:

sudo systemctl status nginx
Enter fullscreen mode Exit fullscreen mode

Test locally:

curl localhost
Enter fullscreen mode Exit fullscreen mode

Then open:

http://YOUR-EC2-PUBLIC-IP
Enter fullscreen mode Exit fullscreen mode

Now your complete architecture is:

Developer
   ↓
Git
   ↓
GitHub
   ↓
CI
   ↓
Repository
   ↓
EC2
   ↓
Nginx
   ↓
Port 80
   ↓
Browser
Enter fullscreen mode Exit fullscreen mode

What Students Must Submit

Each student should send you one GitHub repository link plus screenshots showing:

  1. Repository with index.html
  2. Feature branch
  3. Pull Request
  4. Merged PR
  5. .github/workflows/ci.yml
  6. Successful GitHub Actions run βœ“
  7. Failed CI run ❌ and the later fixed successful run βœ“
  8. Bonus: website running from EC2/Nginx

And prepare a 2–3 minute presentation for Monday explaining:

What is Git?
What is GitHub?
What is a Branch?
What is a Pull Request?
What does git push do?
What does git pull do?
What is CI?
What triggered your workflow?
What is a Runner?
What is a Job?
What is a Step?
Why did your CI fail?
How did you fix it?
Enter fullscreen mode Exit fullscreen mode

Top comments (0)