Continuous Integration
Continuous Integration with GitHub Actions
Build a working repository check, deliberately make it fail, and use the CI results to improve a pull request.
Recognise event triggers, jobs, runners and steps in GitHub Actions YAML.
Validate the presence and structure of README.md with portable shell commands.
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
- workflows/
-
Create an empty repository on GitHub, then clone it. Replace
YOURUSERNAMEand 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 -
Create the workflow directory and a deliberately incomplete
README.md.mkdir -p .github/workflows printf '# Introduction\n\nLearning GitHub Actions.\n' > README.md -
Confirm which branch is checked out.
git branch --show-currentThe 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
-
Create
.github/workflows/check_readme.ymland 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 -
Inspect the sections of the workflow before committing it:
onselects the GitHub events and branches.permissionsgrants the job read-only repository access.runs-onrequests a GitHub-hosted Linux runner.usesinvokes the checkout action;runexecutes shell commands.
-
Commit the workflow and README.
git add -Ais intentional: a new workflow file would not be included bygit commit -am.git add README.md .github/workflows/check_readme.yml git commit -m "ci: validate README headings" git push -u origin main
-
Open the repository's Actions tab, choose README Check, and inspect the failing
Check required headingsstep. Identify which heading is absent. -
Add the required headings to
README.mdwhile retaining the introduction.printf '\n# Description\nA small Git exercise.\n\n## Author\nStudent\n\n## License\nClassroom demonstration.\n' >> README.md -
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 -
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
-
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 -
In GitHub, create a pull request from
feature/readme-reviewintomain. Confirm that README Check runs on the pull request. -
Review the diff and CI status. Merge the pull request only after checks pass and any required review is complete.