Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Last updated: Monday 09 November 2026 @ 12:56:44

Continuous Integration

Git · Automation

Continuous Integration with GitHub Actions

Build a working repository check, deliberately make it fail, and use the CI results to improve a pull request.

GitHub ActionsYAMLTestingPull requests
Define a workflow

Recognise event triggers, jobs, runners and steps in GitHub Actions YAML.

Automate a check

Validate the presence and structure of README.md with portable shell commands.

Investigate results

Interpret a failing check, correct the repository and verify the next run.

Continuous Integration versus deployment

Continuous Integration (CI) is the practice of regularly integrating changes and automatically validating them. It does not itself mean releasing or deploying an application. In this example, a push or pull request triggers checks of repository documentation.

What we are going to build

  • git-ci-lab/
    • README.md
    • .github/
      • workflows/
        • check_readme.yml
  1. Create an empty repository on GitHub, then clone it. Replace YOURUSERNAME and the repository name with your own details. Alternatively, begin with a repository you already control.

    git clone https://github.com/YOURUSERNAME/git-ci-lab.git
    cd git-ci-lab
  2. Create the workflow directory and a deliberately incomplete README.md.

    mkdir -p .github/workflows
    printf '# Introduction\n\nLearning GitHub Actions.\n' > README.md
  3. Confirm which branch is checked out.

    git branch --show-current

    The example workflow targets main. If your repository uses a different main branch, change the branch names in the YAML before pushing.

Create a working workflow

  1. Create .github/workflows/check_readme.yml and enter the following YAML. Its indentation is meaningful.

    name: README Check
    
    on:
      push:
        branches: [main]
      pull_request:
        branches: [main]
    
    permissions:
      contents: read
    
    jobs:
      check-readme:
        name: Check README
        runs-on: ubuntu-latest
        steps:
          - name: Check out repository
            uses: actions/checkout@v4
    
          - name: Check README exists
            run: test -f README.md
    
          - name: Check required headings
            shell: bash
            run: |
              grep -Eq '^# Introduction[[:space:]]*$' README.md
              grep -Eq '^# Description[[:space:]]*$' README.md
              grep -Eq '^## Author[[:space:]]*$' README.md
              grep -Eq '^## License[[:space:]]*$' README.md
  2. Inspect the sections of the workflow before committing it:

    1. on selects the GitHub events and branches.
    2. permissions grants the job read-only repository access.
    3. runs-on requests a GitHub-hosted Linux runner.
    4. uses invokes the checkout action; run executes shell commands.
  3. Commit the workflow and README. git add -A is intentional: a new workflow file would not be included by git commit -am.

    git add README.md .github/workflows/check_readme.yml
    git commit -m "ci: validate README headings"
    git push -u origin main
  1. Open the repository's Actions tab, choose README Check, and inspect the failing Check required headings step. Identify which heading is absent.

  2. Add the required headings to README.md while retaining the introduction.

    printf '\n# Description\nA small Git exercise.\n\n## Author\nStudent\n\n## License\nClassroom demonstration.\n' >> README.md
  3. Run the same heading checks locally before pushing. The checks are intended to produce no output on success.

    grep -Eq '^# Introduction[[:space:]]*$' README.md
    grep -Eq '^# Description[[:space:]]*$' README.md
    grep -Eq '^## Author[[:space:]]*$' README.md
    grep -Eq '^## License[[:space:]]*$' README.md
  4. Commit and push the repair, then inspect the new workflow result.

    git add README.md
    git commit -m "docs: satisfy README checks"
    git push

Add a pull-request check

  1. Create a branch and make a small change to README.md.

    git switch -c feature/readme-review
    printf '\n## Verification\nThe repository uses automated documentation checks.\n' >> README.md
    git add README.md
    git commit -m "docs: add verification section"
    git push -u origin feature/readme-review
  2. In GitHub, create a pull request from feature/readme-review into main. Confirm that README Check runs on the pull request.

  3. Review the diff and CI status. Merge the pull request only after checks pass and any required review is complete.

References