Introduction: Continous Integration

  1. Create a repository on Github, call it what you want.

  2. Next clone it to your system.

  3. Create the following directory

    Terminal

    $ mkdir -p .github/workflows
    
  4. Create the following the following file inside of .github/workflows/ called check_readme.yml and place the following inside the that file:

    Code

    name: README Check
    
    on:
    push:
        branches:
        - main  # Change this to your main branch name if different
    
    jobs:
    check-readme:
        name: Check README
        runs-on: ubuntu-latest
        
        steps:
        - name: Checkout repository
        uses: actions/checkout@v2
        
        - name: Check for README.md
        run: |
            if [ ! -f README.md ]; then
            echo "ERROR: README.md not found!"
            exit 1
            fi
        
        - name: Check README headings - Level 1
        run: |
            if ! grep -q '^# Introduction' README.md; then
            echo "ERROR: Introduction heading missing!"
            exit 1
            fi
            if ! grep -q '^# Description' README.md; then
            echo "ERROR: Description heading missing!"
            exit 1
            fi
        
        - name: Check README headings - Level 2
        run: |
            if ! grep -q '^## Author' README.md; then
            echo "ERROR: Author heading missing!"
            exit 1
            fi
            if ! grep -q '^## License' README.md; then
            echo "ERROR: License heading missing!"
            exit 1
            fi
    
  5. Here is what is going on:

  • This line specifies the name of the workflow. It will be displayed in the Actions tab of your GitHub repository.

    Terminal

    name: README Check
    
  • This section defines when the workflow should be triggered. In this case, it triggers on every push to the main branch. You can adjust the branch name if your main branch is named differently.

    Code

    on:
    push:
        branches:
        - main  # Change this to your main branch name if different
    
  • This part starts defining the jobs to be executed. In this case, there is only one job named check-readme. It runs on an Ubuntu environment (specifically, the latest version).

    Code

    jobs:
    check-readme:
        name: Check README
        runs-on: ubuntu-latest
    
  • This step checks out the code from the repository using the actions/checkout@v2 action. It ensures that the workflow has access to the codebase.

    Code

    steps:
    - name: Checkout repository
    uses: actions/checkout@v2
    
  • This step runs a shell script to check if the README.md file exists in the repository. If the file doesn't exist, it prints an error message and exits the workflow with a non-zero status code.

    Code

        - name: Check for README.md
      run: |
        if [ ! -f README.md ]; then
          echo "ERROR: README.md not found!"
          exit 1
        fi
    
  • This step checks for level 1 headings (# Heading) in the README.md file. It uses grep to search for the specific heading. If the heading is not found, it prints an error message and exits the workflow with a non-zero status code.

    Code

    - name: Check README headings - Level 1
    run: |
    if ! grep -q '^# Introduction' README.md; then
        echo "ERROR: Introduction heading missing!"
        exit 1
    fi
    if ! grep -q '^# Description' README.md; then
        echo "ERROR: Description heading missing!"
        exit 1
    fi
    
  • Similar to the previous step, this one checks for level 2 headings (## Heading) in the README.md file. It uses grep to search for the specific headings (Author and License). If any of the headings are not found, it prints an error message and exits the workflow with a non-zero status code.

    Code

    - name: Check README headings - Level 2
        run: |
        if ! grep -q '^## Author' README.md; then
            echo "ERROR: Author heading missing!"
            exit 1
        fi
        if ! grep -q '^## License' README.md; then
            echo "ERROR: License heading missing!"
            exit 1
        fi
    
  1. Create a README.md and add the # Introduction to the first line

  2. $ git commit -am "add: add README.md and check_readme.yaml

  3. $ git push

  4. Now go to the repo on line and watch the actions unfold.

  5. Try to pass each test.

    Copyright © 2025 • Created with ❤️ by CompEng0001

Page last updated: Thursday 26 June 2025 @ 14:13:31 | Commit: 812dc97