Module 4 · Git & GitHub: From First Commit to Pull Request
GitHub Pages and GitHub Actions: Publish and Automate
Publish a website straight from a repository with GitHub Pages, and meet GitHub Actions, the automation that runs checks and deployments every time you push. Write and read a real workflow file.
About 25 minutes
Your repository can do work for you
A repository is more than a folder of files. GitHub can host a website straight from it, and it can run commands automatically whenever something happens, such as a push or a pull request. This lesson covers both.
GitHub Pages: a free website from a repository
GitHub Pages takes the files in a repository (HTML, CSS, JavaScript, images) and serves them as a website, free, with HTTPS, at an address on github.io. There are two kinds:
| Kind | Repository name | Address |
|---|---|---|
| User site | your-username.github.io | https://your-username.github.io |
| Project site | any name, such as kitchen-site | https://your-username.github.io/kitchen-site |
To publish:
- Make sure your site's main file is called
index.htmlat the top of the repository. - On GitHub, open the repository, then Settings, then Pages.
- Under Build and deployment, set Source to Deploy from a branch, choose main and / (root), and Save.
- Wait a minute or two. GitHub shows the live address at the top of the Pages settings.
From then on, every push to main updates the site. Edit, commit, push, and your website is updated. Combine this with the pull request workflow and you have a real, professional process: changes are reviewed first, and merging publishes them.
GitHub Actions: automation that reacts
GitHub Actions runs workflows: small programs that start when an event happens in your repository. Teams use them to:
- Test the code on every push and pull request, so broken code is caught at once.
- Check style and formatting.
- Build and deploy a website or app when
mainchanges. - Do chores, like labelling issues or sending a message.
This is called CI/CD (continuous integration and continuous delivery): checking and shipping your work automatically, all the time. It is why companies can release many times a day.
Anatomy of a workflow
A workflow is a YAML file in a special folder: .github/workflows/. (YAML is a simple format of keys and values, where indentation matters: use spaces, never tabs.) Here is a small, complete one:
GitHub Actions workflow
name: CI
on:
push:
branches: [main]
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Get the code
uses: actions/checkout@v4
- name: Say hello
run: echo "The workflow is running"
- name: List the files
run: lsRead it from the top:
| Part | Meaning |
|---|---|
name: CI | A label that shows in the Actions tab |
on: | The events that start it: here a push to main, and any pull request |
jobs: | The work to do. Each job runs on its own fresh machine |
test: | A job's name (you choose it) |
runs-on: ubuntu-latest | The kind of machine (a Linux virtual computer) |
steps: | The commands, run in order |
uses: actions/checkout@v4 | Runs a ready-made action, here one that downloads your repository's code onto the machine |
run: ... | Runs a shell command, like the ones you type in the terminal |
Almost every workflow starts the same way: check out the code, then run your tests or build commands. A real Python project might add - run: pip install -r requirements.txt and - run: pytest. A website might build and deploy.
What you see on GitHub
After you push a workflow:
- The Actions tab lists every run, with a green tick (success) or red cross (failure).
- Click a run, then a job, to read the logs: exactly what each step printed. When something fails, the log tells you why. Reading logs is a core skill.
- On a pull request, the checks appear at the bottom, and a failing check can block the merge.
You can even show the status in your README with a badge, a small image that shows "passing" or "failing".
Secrets in Actions
Sometimes a workflow needs a password or key, for example to deploy. Never write it in the YAML file, because that is in your repository (lesson 9). Instead, store it in Settings, then Secrets and variables, then Actions, and use it in the workflow as ${{ secrets.MY_KEY }}. GitHub keeps the value hidden, even in the logs.
Try it
First, add a workflow to a repository. Create the file in the right folder, with the right content, and commit it.
Task
10 minAdd a GitHub Actions workflow to this repository at .github/workflows/ci.yml. It should run on: push, on a ubuntu-latest machine, check out the code with actions/checkout, and run at least one command with run:. Commit it.
Your repository is checked for
- The workflow file .github/workflows/ci.yml is committed
- It has a name and runs on push (on: and push)
- It runs on a machine: runs-on: ubuntu-latest
- It checks out the code with actions/checkout
- It runs at least one command with run:
- Everything is committed (clean)
Files in your project folder
Type a command below and press Enter. Type help for the commands you can use. Press the up arrow to bring back an earlier command.
Now write a workflow for a Python project. This is the shape of what many real repositories have.
Task
10 minWrite a GitHub Actions workflow in YAML for a Python project that runs its tests. Include a name:, on: push and pull_request, a job with runs-on: ubuntu-latest, a step that uses actions/checkout@v4, a step that installs requirements with pip install -r requirements.txt, and a step that runs pytest.
Your work is checked for
- A name: for the workflow
- on: with push and pull_request
- runs-on: ubuntu-latest
- It checks out the code (uses: actions/checkout@v4)
- It installs the requirements (pip install -r requirements.txt)
- It runs pytest
- It is indented with spaces (no tab characters)
Practice
In which folder of a repository must GitHub Actions workflow files be saved? Type the path.
Earn your badge
Take the module check
Questions on this module. Pass and you earn the GitHub Portfolio badge, free.
Create a free account to earn the badge