Skip to content

Commit 5cf7999

Browse files
authored
Merge pull request #13 from UMM-CSci-Systems/add-github-actions
Add GitHub Actions for this pre-lab
2 parents c4d2b4a + 2f803f4 commit 5cf7999

File tree

5 files changed

+127
-0
lines changed

5 files changed

+127
-0
lines changed

.github/workflows/gtest.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: gtest
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Cache gtest library
10+
uses: actions/cache@v2
11+
env:
12+
cache-name: cache-gtest-lib
13+
with:
14+
key: $${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('/usr/local/lib/libgtest.a') }}
15+
path: /usr/local/lib/libgtest.a
16+
restore-keys: |
17+
${{ runner.os }}-build-${{ env.cache-name }}-
18+
${{ runner.os }}-build-
19+
${{ runner.os }}-
20+
- name: Install gtest manually
21+
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
22+
- name: Check out the code
23+
uses: actions/checkout@v2
24+
- name: Compile test code
25+
run: g++ -Wall -g -o check_whitespace_test check_whitespace.c check_whitespace_test.cpp -lgtest -pthread
26+
- name: Run test
27+
run: ./check_whitespace_test
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: main-valgrind
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Cache gtest library
10+
uses: actions/cache@v2
11+
env:
12+
cache-name: cache-gtest-lib
13+
with:
14+
key: $${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('/usr/local/lib/libgtest.a') }}
15+
path: /usr/local/lib/libgtest.a
16+
restore-keys: |
17+
${{ runner.os }}-build-${{ env.cache-name }}-
18+
${{ runner.os }}-build-
19+
${{ runner.os }}-
20+
- name: Install gtest manually
21+
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
22+
- name: Install valgrind
23+
run: sudo apt-get install -y valgrind
24+
- name: Check out the code
25+
uses: actions/checkout@v2
26+
- name: Compile code
27+
run: gcc -Wall -g -o check_whitespace check_whitespace.c main.c
28+
- name: Run test
29+
run: valgrind -v --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./check_whitespace < main.c
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: test-valgrind
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Cache gtest library
10+
uses: actions/cache@v2
11+
env:
12+
cache-name: cache-gtest-lib
13+
with:
14+
key: $${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('/usr/local/lib/libgtest.a') }}
15+
path: /usr/local/lib/libgtest.a
16+
restore-keys: |
17+
${{ runner.os }}-build-${{ env.cache-name }}-
18+
${{ runner.os }}-build-
19+
${{ runner.os }}-
20+
- name: Install gtest manually
21+
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
22+
- name: Install valgrind
23+
run: sudo apt-get install -y valgrind
24+
- name: Check out the code
25+
uses: actions/checkout@v2
26+
- name: Compile code
27+
run: g++ -Wall -g -o check_whitespace_test check_whitespace.c check_whitespace_test.cpp -lgtest -pthread
28+
- name: Run test
29+
run: valgrind -v --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./check_whitespace_test

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# C-programming-pre-lab <!-- omit in toc -->
22

3+
[![Tests](../../workflows/gtest/badge.svg)](../../actions?query=workflow%3A"gtest")
4+
[![Main Valgrind](../../workflows/main-valgrind/badge.svg)](../../actions?query=workflow%3A"main-valgrind")
5+
[![Test Valgrind](../../workflows/test-valgrind/badge.svg)](../../actions?query=workflow%3A"test-valgrind")
6+
7+
38
This is a pre-lab to get you started started on compiling and running C programs
49
and using `valgrind` to identify memory leaks. The tools have been installed on the lab computers.
510
Be aware that if you want to use your own machine you will have to go through quite a few extra steps to
@@ -9,6 +14,7 @@ install the `gtest` test suite and the `valgrind` memory leak detection program
914
- [Compiling and running a C program](#compiling-and-running-a-c-program)
1015
- [Compiling and running the tests](#compiling-and-running-the-tests)
1116
- [Using valgrind to find memory leaks](#using-valgrind-to-find-memory-leaks)
17+
- [GitHub Actions and badges](#github-actions-and-badges)
1218
- [What to do](#what-to-do)
1319

1420
## Background
@@ -324,6 +330,42 @@ Once you have everything happy, you will hopefully get a line like:
324330

325331
at the end indicating that you now have 0 errors and all is well.
326332

333+
## GitHub Actions and badges
334+
335+
We've set up GitHub Actions to automatically run three checks on your
336+
code every time you push changes to GitHub:
337+
338+
- The code compiles and the tests pass.
339+
- Valgrind returns no errors when running the `main` function.
340+
- Valgrind returns no errors when running the test code.
341+
342+
You should be able to see the status of these in a commit or pull request
343+
in GitHub. Here, for example, is a status from a pull request:
344+
345+
![Screen grab of GitHub Action status showing success, failure, and pending](images/GitHub_action_status.png)
346+
347+
We have all three possible status indicators here:
348+
349+
- The red x indicates a failing check
350+
- The orange dot indicates a check that's still in progress
351+
- The green checkmark indicates a check that passed
352+
353+
When you initially check out the code for the pre-lab, the `gtest`
354+
check should pass (the tests pass), but the other two should fail
355+
because there are memory issues with both the `check_whitespace`
356+
`main()` and the tests.
357+
358+
We have also added three badges to the top of this README that indicate
359+
the status of each of these three status checks. The tests badge should
360+
be green from the beginning (and stay green throughout the process).
361+
The two `valgrind` badges will both start off red (because the `valgrind`
362+
checks fail initially) but turn green after you've fixed the memory
363+
management issue.
364+
365+
> :warning: The badges won't update instantly, so don't fret if
366+
> your status checks are green but the badge is still red. That
367+
> should update in a few minutes.
368+
327369
## What to do
328370

329371
- [ ] Compile the program `check_whitespace`

images/GitHub_action_status.png

39 KB
Loading

0 commit comments

Comments
 (0)