Introduction: Continous Integration
-
Create a repository on Github, call it what you want.
-
Next clone it to your system.
-
Create the following directory
-
Create the following the following file inside of
.github/workflows/
calledcheck_readme.yml
and place the following inside the that file: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
-
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.
-
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.
-
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).
-
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. -
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.
-
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.
-
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.
-
Create a
README.md
and add the# Introduction
to the first line -
$ git commit -am "add: add README.md and check_readme.yaml
-
$ git push
-
Now go to the repo on line and watch the actions unfold.
-
Try to pass each test.