unity-test-runner icon indicating copy to clipboard operation
unity-test-runner copied to clipboard

What's the "correct way" to provide the test runner with some secrets/credentials?

Open alexiscatnip opened this issue 2 years ago • 4 comments

Context:

  1. I am trying to give the unity test runner some secrets. Namely, a username and (plaintext)password

  2. The reason is so that my test can authenticate to the live game server in my test, using these credentials.

  3. I am using environment variables to store the secrets. It works on a local Ubuntu PC. The test is successful.

On Ubuntu, i can simply export USERNAME_SECONDLIFE="thevalue" inside the bash.rc file. And the unity editor will be able to read the env values using Environment.GetEnvironmentVariable( "USERNAME_SECONDLIFE" )

Issue:

However, the unity test runner cannot find such environment variables (Environment.GetEnvironmentVariable() returns null string). I have added them into my env @ the test-runner job section:

// https://github.com/alexiscatnip/RaindropViewer/blob/2d895a25fb84e93047f80131a99a2949389ba198/.github/workflows/main.yml
    
    # Test
      - name: Run tests
        uses: game-ci/unity-test-runner@v2
        env:
          UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
          UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
          UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
      >    USERNAME_SECONDLIFE: ${{ secrets.USERNAME_SECONDLIFE }}
      >    PASSWORD_SECONDLIFE: ${{ secrets.PASSWORD_SECONDLIFE }}
      >    GRIDFRIENDLYNAME_SECONDLIFE: ${{ secrets.GRIDFRIENDLYNAME_SECONDLIFE }}
        with:
          githubToken: ${{ secrets.GITHUB_TOKEN }}
          unityVersion: ${{ matrix.unityVersion }}

alexiscatnip avatar Jul 16 '22 13:07 alexiscatnip

Looking at https://github.com/game-ci/unity-test-runner/blob/3d5d2f58348b293ae1fe6b7cca24deccaf505b2f/src/model/docker.ts , I think I can modify the command line string, by adding in my env variables (hard-code...).

But that might be thinking too much inside the box?

alexiscatnip avatar Jul 16 '22 13:07 alexiscatnip

By using the shell of the github runner VM, I am able to read the envs. https://github.com/alexiscatnip/github_action_experiment/tree/main

My present suspicion is 'the envs of the github VM are not inherited by the docker container, and instead must be defined in the CLI arguments as a flag like --env MYENVVAR"

alexiscatnip avatar Jul 16 '22 14:07 alexiscatnip

You are correct in your observation that we're not passing non-specific env variables into the container.

You can use customParameters to pass any parameters into the image and read them from your code.

Here's an example of how to read the variables that you've passed from builder. Effectively the same can be done in your test setup.

Let me know if this sufficiently answers your question.

webbertakken avatar Jul 17 '22 19:07 webbertakken

@webbertakken 👍 thanks so much! I am presently not familiar with building docker (only know how to docker run).

I will investigate one of these days... For now I just quickly forked the repo and hard-coded my 3 values to pass in; something like -env MY_SECRET_FROM_GITHUB_SECRETS. It more or less works... :'')

alexiscatnip avatar Jul 27 '22 14:07 alexiscatnip