vrchat-community / template-package

WIP Package Template Repository
https://vrchat-community.github.io/template-package/
58 stars 18 forks source link

Added support for automatic Unit Tests and Code Coverage Report generation. #12

Closed dustuu closed 1 year ago

dustuu commented 1 year ago

This pull request adds optional support for automatically running Unit Tests via GitHub Actions and generating Code Coverage Reports from those tests. Configuration steps for this feature are outlined here. If this feature is not configured by a user, it will simply be skipped over during workflow execution.

Two configurable badges have also been added to the README file; one badge which displays the package's current VPM version, and another which shows the results of the Code Coverage Report (if the new automatic unit tests feature is enabled). These badges are outlined here. When set up properly, they look like this:

Clicking on the VPM badge opens the repository's VPM Listing Page, while clicking on the Code Coverage badge opens the the generated Code Coverage Report.

:warning: Note: The Code Coverage badge currently does not render in my forked repository's README: Code Coverage This is because I have already changed it to point back to the source vrchat-community/template-package repository in preparation for being merged. If merged, this badge will render properly in the vrchat-community/template-package repository's README after the new Build Release workflow has been run at least one time with the Automatic Unit Tests feature enabled. Users who don't use the Automatic Unit Testing feature can simply remove this badge from their README files.

Additionally, this pull request removes the need for users to manually edit any of the workflow files. It does this by using repository variables to pass values into the workflows. Users can now create a repository variable named PACKAGE_NAME with the name of their package, such as com.vrchat.demo-template in this demo, instead of manually editing the workflow files. This step has been added to the README file here.

If automatic unit testing is enabled, repository secrets can also be used for Unity License configuration, which are outlined here. There are also several more non-secret repository variables to be entered at this step.

In this template repository, these are the current configurations of all of the repository variables used: Variable Name Value
PACKAGE_NAME com.vrchat.demo-template
ASSEMBLY_NAME VRChatPackageTemplate
REQUIRED_COVERAGE 100
UNITY_VERSION 2019.4.31f1

If the user requests for Code Coverage percentages to be enforced by setting the REQUIRED_COVERAGE variable to something greater than 0, the Build Release workflow will enforce their configured Code Coverage target. It does this by using my own custom fork of a GitHub Action that runs in a Docker Container: Kemocade.Unity.Coverage.Action. This Container is built during the start of the Build Release workflow's test job, and executed later in that same job's Enforce Code Coverage step.

The Build Release workflow previously only contained one job, build. It now contains three jobs: config, test, and build:

From this template repository, I've created 8 example repositories that show how the updated workflows respond to various possible configurations of repository variables, asset changes, or both:

Beyond the main features of Unit Tests, Code Coverage, and Repository Variable Configuration, this pull request also includes a few small additional changes.

Previously, zip releases were made with a third-party GitHub Action that used relative paths to back outwards from the package itself:

- name: Create Zip
  uses: thedoctor0/zip-release@09336613be18a8208dfa66bd57efafd9e2685657
  with:
    type: "zip"
    directory: "Packages/${{env.packageName}}/"
    filename: "../../${{env.zipFile}}" # make the zip file two directories up, since we start two directories in above

I have changed this to use the native Bash zip command, as well as absolute paths built from ${{ github.workspace }}.

- name: Create Package Zip
  working-directory: "${{ env.packagePath }}"
  run: zip -r "${{ github.workspace }}/${{ env.zipFile }}" .

This new approach is also used to build the Code Coverage Report zip, if Automatic Unit Testing is enabled.

Finally, names and comments have been added to all workflow steps which did not previously have them. All workflow steps which use other actions via the uses keyword have also been set to use their source's commit ID instead of tags, keeping in line with how this was done in most of the original workflows.

This pull request has been built on top of the existing work done in the approved but still-pending PR #11. Therefore, this pull request can be merged in place of or on top of that one with no merge conflicts.

momo-the-monster commented 1 year ago

First - thank you very much @dustuu for submitting this helpful and very well documented PR! I'm happy with the changes to use Repository Variables instead of requiring code changes. I'm a little worried that the automation and information about the test suite will be an overload for most of our package creators, who are not likely to create and run tests like this for their packages. I don't want anyone scared away because of how complicated it may look. Any thoughts on that, @Faxmashine?

dustuu commented 1 year ago

@momo-the-monster No worries! I thought that might be the case.

I can open a new PR with a subset of the changes from this one.

Would you like me to include only the Repository Variable changes, or are you also interested in including the workflow cleanup changes such as the new zip step or the updated comments & action versions?

momo-the-monster commented 1 year ago

@dustuu - I'm interested in all the workflow cleanup changes too, thanks!

dustuu commented 1 year ago

@momo-the-monster I've opened a new PR #13 which has the reduced scope you're looking for. I'll go ahead and close this PR now. 🍍👍