30 Continuous Integration Preview

Create a tiny CI job that runs automatically after a push.

Introduction

In this lab, you will create a minimal Continuous Integration (CI) job and watch it run automatically after you push a commit.

This lab is designed as a preview. If you run out of time, stop at any point. We will cover CI in depth in the next session.

Prerequisites

You should have:

  • the course lab repository cloned locally
  • Git working on your machine
  • a GitHub account and access to a repository you can push to

Repository setup

For this lab, you must work in your own copy of the repository on GitHub.

You need a GitHub account to complete this lab.
If you do not already have one, create it before continuing.

During this lab, you will create new files and directories yourself.
For example, the scripts/ directory does not exist initially and will be created as part of the exercises.

Create a CI preview branch

Create a new branch for this lab:

Terminal window
git switch -c feature/ci-preview

Confirm your status:

Terminal window
git status

Add a script that CI can run

Create a new script file:

Terminal window
mkdir -p scripts

Create scripts/ci-preview.sh with the following content:

#!/usr/bin/env bash
set -euo pipefail
echo "CI preview: hello from $(uname -s)"
echo "Current directory:"
pwd
echo "Repository status:"
git status
echo "Done."

Make the script executable:

Terminal window
chmod +x scripts/ci-preview.sh

Run it locally to confirm it works:

Terminal window
./scripts/ci-preview.sh

Add a minimal CI configuration

Add a minimal GitHub Actions workflow that runs after every push.

GitHub Actions workflow

Create the workflow directory:

Terminal window
mkdir -p .github/workflows

Create .github/workflows/ci.yml:

name: CI Preview
on:
push:
jobs:
preview:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run preview script
run: ./scripts/ci-preview.sh

Commit and push

Stage your changes:

Terminal window
git add scripts .github/workflows/ci.yml

Commit:

Terminal window
git commit -m "Add CI preview job"

Push your branch to your remote:

Terminal window
git push -u origin feature/ci-preview

Observe the CI run

Open your repository on GitHub and go to the Actions tab.

You should see a workflow run named CI Preview for your branch.

Open the job logs and confirm you can find these lines:

  • CI preview: hello from
  • Repository status:
  • Done.

Troubleshooting

CI cannot find the script

Confirm the script exists and is executable:

Terminal window
ls -la scripts

Permission denied when running the script

Re-apply executable permissions and commit the change:

Terminal window
chmod +x scripts/ci-preview.sh
git add scripts/ci-preview.sh
git commit -m "Make CI preview script executable"
git push

No CI run appears after pushing

Confirm you pushed to the correct remote and branch:

Terminal window
git remote -v
git branch --show-current

If you are using GitHub Actions, confirm the workflow file exists:

Terminal window
ls -la .github/workflows

Wrap-up

You have created a minimal CI job that runs automatically after a push.

In the next session, you will expand this into a real pipeline with checks like formatting, linting, and tests.