diff --git a/.github/workflows/gtest.yml b/.github/workflows/gtest.yml new file mode 100644 index 0000000..409531a --- /dev/null +++ b/.github/workflows/gtest.yml @@ -0,0 +1,27 @@ +name: gtest + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Cache gtest library + uses: actions/cache@v2 + env: + cache-name: cache-gtest-lib + with: + key: $${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('/usr/local/lib/libgtest.a') }} + path: /usr/local/lib/libgtest.a + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + - name: Install gtest manually + run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a + - name: Check out the code + uses: actions/checkout@v2 + - name: Compile test code + run: g++ -Wall -g -o check_whitespace_test check_whitespace.c check_whitespace_test.cpp -lgtest -pthread + - name: Run test + run: ./check_whitespace_test diff --git a/.github/workflows/main_valgrind.yml b/.github/workflows/main_valgrind.yml new file mode 100644 index 0000000..83499e4 --- /dev/null +++ b/.github/workflows/main_valgrind.yml @@ -0,0 +1,29 @@ +name: main-valgrind + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Cache gtest library + uses: actions/cache@v2 + env: + cache-name: cache-gtest-lib + with: + key: $${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('/usr/local/lib/libgtest.a') }} + path: /usr/local/lib/libgtest.a + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + - name: Install gtest manually + run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a + - name: Install valgrind + run: sudo apt-get install -y valgrind + - name: Check out the code + uses: actions/checkout@v2 + - name: Compile code + run: gcc -Wall -g -o check_whitespace check_whitespace.c main.c + - name: Run test + run: valgrind -v --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./check_whitespace < main.c diff --git a/.github/workflows/test_valgrind.yml b/.github/workflows/test_valgrind.yml new file mode 100644 index 0000000..807bf65 --- /dev/null +++ b/.github/workflows/test_valgrind.yml @@ -0,0 +1,29 @@ +name: test-valgrind + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Cache gtest library + uses: actions/cache@v2 + env: + cache-name: cache-gtest-lib + with: + key: $${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('/usr/local/lib/libgtest.a') }} + path: /usr/local/lib/libgtest.a + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + - name: Install gtest manually + run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a + - name: Install valgrind + run: sudo apt-get install -y valgrind + - name: Check out the code + uses: actions/checkout@v2 + - name: Compile code + run: g++ -Wall -g -o check_whitespace_test check_whitespace.c check_whitespace_test.cpp -lgtest -pthread + - name: Run test + run: valgrind -v --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./check_whitespace_test diff --git a/README.md b/README.md index 784c34f..9f5ffb9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # C-programming-pre-lab +[![Tests](../../workflows/gtest/badge.svg)](../../actions?query=workflow%3A"gtest") +[![Main Valgrind](../../workflows/main-valgrind/badge.svg)](../../actions?query=workflow%3A"main-valgrind") +[![Test Valgrind](../../workflows/test-valgrind/badge.svg)](../../actions?query=workflow%3A"test-valgrind") + + This is a pre-lab to get you started started on compiling and running C programs and using `valgrind` to identify memory leaks. @@ -7,6 +12,7 @@ and using `valgrind` to identify memory leaks. - [Compiling and running a C program](#compiling-and-running-a-c-program) - [Compiling and running the tests](#compiling-and-running-the-tests) - [Using valgrind to find memory leaks](#using-valgrind-to-find-memory-leaks) +- [GitHub Actions and badges](#github-actions-and-badges) - [What to do](#what-to-do) ## Background @@ -313,6 +319,42 @@ Once you have everything happy, you will hopefully get a line like: at the end indicating that you now have 0 errors and all is well. +## GitHub Actions and badges + +We've set up GitHub Actions to automatically run three checks on your +code every time you push changes to GitHub: + +- The code compiles and the tests pass. +- Valgrind returns no errors when running the `main` function. +- Valgrind returns no errors when running the test code. + +You should be able to see the status of these in a commit or pull request +in GitHub. Here, for example, is a status from a pull request: + +![Screen grab of GitHub Action status showing success, failure, and pending](images/GitHub_action_status.png) + +We have all three possible status indicators here: + +- The red x indicates a failing check +- The orange dot indicates a check that's still in progress +- The green checkmark indicates a check that passed + +When you initially check out the code for the pre-lab, the `gtest` +check should pass (the tests pass), but the other two should fail +because there are memory issues with both the `check_whitespace` +`main()` and the tests. + +We have also added three badges to the top of this README that indicate +the status of each of these three status checks. The tests badge should +be green from the beginning (and stay green throughout the process). +The two `valgrind` badges will both start off red (because the `valgrind` +checks fail initially) but turn green after you've fixed the memory +management issue. + +> :warning: The badges won't update instantly, so don't fret if +> your status checks are green but the badge is still red. That +> should update in a few minutes. + ## What to do - [ ] Compile the program `check_whitespace` diff --git a/images/GitHub_action_status.png b/images/GitHub_action_status.png new file mode 100644 index 0000000..c4a3ea1 Binary files /dev/null and b/images/GitHub_action_status.png differ