3d-group / unity-package-template

Template repository for creating Unity game engine packages
MIT License
49 stars 18 forks source link

Enable running tests for other branches than main #11

Open antja0 opened 3 years ago

antja0 commented 3 years ago

See manifest.json at https://github.com/3d-group/unity-package-template/blob/main/Samples/ExampleUnityProject/Packages/manifest.json

Currently tests work so that the package is imported via git url. This means main branch. Perhaps there is syntax to allow cloning from different branch eg. https://git-repository.git@branch ?

It is possible to get current branch name inside github actions with github ref parameter. See eg. https://stackoverflow.com/questions/58033366/how-to-get-current-branch-within-github-actions

Or perhaps develop way to do this to the test runner action: https://github.com/webbertakken/unity-test-runner/issues/71

jaibeer72 commented 3 years ago

Hey, I am not sure if this helps.

But unity has a built-in system to get packages that are UPM compatible.

https://docs.unity3d.com/ScriptReference/PackageManager.Client.html I am sure using https://docs.unity3d.com/ScriptReference/PackageManager.Client.Add.html

which is Client.Add() in a test can basically with the branch you wanna test can here is an example https://docs.unity3d.com/Manual/upm-git.html

they have mentioned here to get access to a particular branch the syntax is "https://github.example.com/myuser/myrepository.git#my-branch"

Do you think it's a good idea to make a base class that can basically Add setup then remove the package by just passing in the git+branch for the package and run it on the branch? or just GitHub actions basically detect with branch it's running on and based on that pull that branch for running it?

PS: I am hoping I got the issue being tackled here. My apologies if I messed something up. New to contributing.

antja0 commented 3 years ago

@jaibeer72 thank you for your input, you are on the correct track I think! 😄

I didn't know about that Unity built-in-system - thanks for pointing that out - that is interesting feature but not sure if it makes things any more easier for us 🤔

The issue (if I remember correctly) is that the package that this template repository generates can only run tests on the main branch.

How it works currently:

  1. Let's say user generates new package with this repository template called "awesome-unity-package"
  2. push events triggers github actions in awesome-unity-package
  3. github actions runs tests in awesome-unity-package/Samples/ExampleUnityProject
  4. the ExampleUnityProject has the awesome-unity-package (from main branch) as a dependency.

I think what you said is the easiest way to go about it right now:

or just GitHub actions basically detect with branch it's running on and based on that pull that branch for running it?

So new github action would after checkout replace the line awesome-unity-package#main from ExampleUnityProject's manifest.json file with proper branch name: so awesome-unity-package#branch-name, then build the ExampleUnityProject and run tests as usual.

Replace can be done inside github action with eg. linux sed command https://linuxhint.com/replace_string_in_file_bash/

This would enable running tests in eg. PR's with the correct branch - currently it can run the tests only after merge to main because it always checksout main.