The previous weekly assignment created unit test for Static Site Generator(ssg). In this week, we extend previous weekly task to implement test automation on Github action with Continuous Integration(CI).
The setting of Github Action CI Workflow is very straight forward. I have used suggested Workflows template for .NET from Github. Therefore, I just needed to configure the steps for test automation and lint.
The first step is setting up .NET action. The .NET action finds a specific version of .NET from my SSG. My version of .NET is 5.0.x. Here is the code:
- name: Setup .NET uses: actions/setup-dotnet@v1 with: dotnet-version: 5.0.x
The second step is installing dependencies.
- name: Install dependencies run: dotnet build ./kimchi-ssg/kimchi-ssg.csproj
dotnet build compiles the SSG, reads through its dependencies specified in the project file, and publishes the resulting on virtual machine.
The third step is setting up
Run Formatter & Linter.
- name: Run Formatter & Linter run: | dotnet tool install --global dotnet-format --version 5.1.250
I have installed
dotnet-format for detecting lint from my code.
dotnet-format --check --folder ./kimchi-ssg
This code check the lint all the file from
The last step is unit testing
- name: Test run: dotnet test ./UnitTest/UnitTest.csproj
UnitTest.csproj includes test code for
Kimchi-ssg. The implementation code is same as I did on the
The final code is
name: .NET on: push: branches: [ main ] pull_request: branches: [ main ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup .NET uses: actions/setup-dotnet@v1 with: dotnet-version: 5.0.x - name: Install dependencies run: dotnet build ./kimchi-ssg/kimchi-ssg.csproj - name: Run Formatter & Linter run: | dotnet tool install --global dotnet-format --version 5.1.250 dotnet-format --check --folder ./kimchi-ssg - name: Test run: dotnet test ./UnitTest/UnitTest.csproj
I created a pull request for testing Lint. The CI throws error like this
CONTRIBUTING.md for providing how to test in his application. Therefore, the testing on my partner's repo is straightforward.
The CI is very excellent automate tool to prevent the code that includes lint and unit test the code. Sometimes I forgot to run
Linter command before I commit my code to repo. Since this application is open source project, other people can have unformatted code. Now I do not have to worry because CI automatically block my PR if I have lint on my code!