Set Up GitHub Action, add test to partner's repo
Tags: opensource
Published: 2021-11-17 19:53:49

# GitHub Action
* This week, I set up GitHub Action for my Static Site Generator ([SSG](https://github.com/kiennguyenchi/potato-generator)). There are several options with C++ language and I picked *C/C++ with Make* to implement.
* It auto generates a yml file with default contents. I had to change a few things. The structure of yml looks like this:
```
name: C/C++ CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: compile
      run: g++ pgprogram.cpp HTMLFile.h HTMLFile.cpp MainPage.h MainPage.cpp -o pgprogram --std=c++17
    - name: Program Test
      run: g++ test/test.cpp test/catch.hpp HTMLFile.h HTMLFile.cpp -o programtest --std=c++17
```
* First, I set *push* and *pull_request* to run the test whenever it is pushed or pulled to the main branch:
```
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
```
* Second, I set the *run* command of *compile* option to the command to compile my program:
```
g++ pgprogram.cpp HTMLFile.h HTMLFile.cpp MainPage.h MainPage.cpp -o pgprogram --std=c++17
```
* Third, I added option to test my program with testing command:
```
g++ test/test.cpp test/catch.hpp HTMLFile.h HTMLFile.cpp -o programtest --std=c++17
```
* Finally, the GitHub Action Workflow runs successfully on the project:
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wtkd9kwk4ar4ew5k6iqg.JPG) 
* Take a look at how it runs: [GitHub Actions Run](https://github.com/kiennguyenchi/potato-generator/runs/4242038652?check_suite_focus=true)

# Add Test to partner Repo
* I picked [Gus's SSG](https://github.com/gusmccallum/GAS-ssg) to work on. I had work on his project before because we use the same C++ language. We use same testing framework, which is Catch2. So I generally understand how his SSG and Testing Tool work.
* I tested his project with his existing 10 test cases and it showed:
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l9svwf5em4thfezivdv2.JPG) 
* I'm kind of ignoring failed tests for now and add my tests.
* On his existing test cases, I saw he had 4 functions to check for correct file/folder input. He only had the test cases to test if these functions are returning true values. 
```
TEST_CASE("isText() Testing", "[istext]") {
	REQUIRE(isText("The Adventure of the Speckled Band.txt") == true);
}
TEST_CASE("isMarkDown() Testing", "[ismarkdown]") {
	REQUIRE(isMarkDown("readme.md") == true);
}
TEST_CASE("isFolder() Testing", "[isfolder]") {
	REQUIRE(isFolder("./dist") == true);
}

TEST_CASE("isJson() Testing", "[isjson]") {
	REQUIRE(isJson("ssg-config.json") == true);
}
```
* I added test cases to test if these functions are returning false values correctly.
```
TEST_CASE("isText() Testing (not .txt file)", "[istext]") {
	REQUIRE(isText("The Adventure of the Speckled Band.md") == false);
	REQUIRE(isText("The Adventure of the Speckled Band") == false);
}

TEST_CASE("isMarkDown() Testing (not .md file)", "[ismarkdown]") {
	REQUIRE(isMarkDown("The Adventure of the Speckled Band.txt") == false);
	REQUIRE(isMarkDown("The Adventure of the Speckled Band") == false);
}

TEST_CASE("isFolder() Testing (not folder)", "[isfolder]") {
	REQUIRE(isFolder("The Adventure of the Speckled Band.txt") == false);
	REQUIRE(isFolder("The Adventure of the Speckled Band.json") == false);
}

TEST_CASE("isJson() Testing (not .json file)", "[isjson]") {
	REQUIRE(isJson("The Adventure of the Speckled Band.txt") == false);
	REQUIRE(isJson("The Adventure of the Speckled Band") == false);
}
```
* After adding 4 tests, all tests worked perfectly. 
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n8undauy90mz7fdhtfrq.JPG)
* Take a look at my [Pull Request](https://github.com/gusmccallum/GAS-ssg/pull/24).

# Conclusion 
Overall, it is really useful to add GitHub Action Workflow to my project. The future pull requests, commits, etc will needed to be checked through my compiling command and my test. It is absolutely a safeguard for the project.
Furthermore, it is interesting this week that I can contribute adding tests to my partner's repo. Hopefully, my test cases will be useful for your project.