Github Action
Tags: opensource, github, cpp, ci
Published: 2021-11-19 22:45:53

For this week's lab I implemented [Github Actions](https://github.com/gusmccallum/GAS-ssg/actions/workflows/c-cpp.yml)  for my [GAS SSG](https://github.com/gusmccallum/GAS-ssg). First I went back and got my tests from last week [working](https://github.com/gusmccallum/GAS-ssg/commit/871c45b7f3ec06ef229d8db688fafc10b1d21009). Even though I implemented testing many of them were failing for reasons I didn't have time to get to, which I thankfully got the chance to get figured out this week. The biggest issue that held me up last week was file input not working if I didn't compile my program as I normally do, which I realized was because I hadn't changed my Visual Studio working directory - so my files were being compiled from one folder while the project was in another - obviously the path was wrong when compiling from the project folder. 

Next I started working on setting up Github Actions for continuous integration - the intention being that once it's set up my program and its tests will be automatically compiled and any compilation errors will be flagged. I worked on it for a bit last night and was having issues with the inclusion of `direct.h`. I was wondering if something to do with the compiler or the platform was the issue, but ultimately I realized the only function using `direct.h` was my `newFolder()` function. I took a look at how I was using it there and realized it was just being used to make a directory, which `std::filesystem` can already do. With that in mind, I removed the portion that used `direct.h` and left the directory creation to `std::filesystem`. 

In the meantime, I noticed I hadn't pulled from my repo last night so my Github Action was removed after pushing those other changes. I remade the `.yml` and tried again, and everything compiled smoothly.

Next I [added some additional tests](https://github.com/gusmccallum/GAS-ssg/pull/23/commits/b0e1fd794267f6437f6964f36ad3e2cdb5b7cb00) to my testing file. All functions are covered already, so I added some more types of tests to my `processText` function to cover other functionalities like getting input from within a folder and reading a `.md` in addition to a `.txt`. In doing so I moved my `contributing.md` to a contributing directory along with my linting and formatting scripts, changed the scripts to reflect the new filepath and also specified which source files to cover, so as to avoid formatting and linting `catch.hpp`. I created a [pull request](https://github.com/gusmccallum/GAS-ssg/pull/23) which [successfully passed](https://github.com/gusmccallum/GAS-ssg/pull/23/checks) the workflow I defined earlier. I [pushed a commit](https://github.com/gusmccallum/GAS-ssg/pull/23/commits/297358dba5e66b111c51785a4c213f7656558627) to cause the compilation stage of the workflow to fail, which it did, and then [reverted it](https://github.com/gusmccallum/GAS-ssg/pull/23/commits/8653b4bd7859fdc6d37cbb0bcb9f6159eb18b424).

Finally, I moved onto working on Kien's [potato SSG](https://github.com/kiennguyenchi/potato-generator). His setup with [catch2](https://github.com/catchorg/Catch2) is similar to mine, we both have it set up to provide us a main which we compile separately when we want to test it, rather than having it integrated into the program all the time. This made it easy to get started on his, I read his [contributing.md](https://github.com/kiennguyenchi/potato-generator/blob/main/CONTRIBUTING.md) which specified one should create a new source file to write their desired test cases, which I did. After messing around with file paths for a bit and figuring out how to get my test to pass, I pushed a commit and [created a pull request](https://github.com/kiennguyenchi/potato-generator/pull/16) with a test for his `HTMLFile.getTitle()` function. Unfortunately I realized with the workflow he had set up this wouldn't trigger his CI so I opted to insert my test case in `test.cpp` instead to see if it passed his workflow, which thankfully [it did](https://github.com/kiennguyenchi/potato-generator/pull/16/checks). 

This week's lab was pretty cool, I've seen these Github Actions all over the place while working on open source projects, as well as in some of my classes now. It was surprisingly easy to get set up and seems like something I'd definitely use in the future for how straightforward it is to add to a repo.