pythonmacosunity-game-enginegithub-actionsgithub-actions-self-hosted-runners

Github Self Hosted Runner on MacOS - Run Python Script with elevated permissions?


I am hosting a self-hosted runner, using python to automate some Unity tests. I have set up a .env file for local variables so eventually I can deploy the runner and the scripts onto any computer. However I am having an issue when I am triggering the script via GitHub Actions. If I use the terminal myself on my own machine, it runs just fine.

My question is, is there way to elevate the permissions of a runner, or am I missing a step?

The error in the Actions tab is

##[debug]Result: '$SELF_HOSTED_UNITY_TEST_SCRIPT {branch_name}'
##[debug]Loading env
Run $SELF_HOSTED_UNITY_TEST_SCRIPT pythonmacos
  $SELF_HOSTED_UNITY_TEST_SCRIPT pythonmacos
  shell: /bin/bash -e {0}
##[debug]/bin/bash -e {user_path}/actions-runner/_work/_temp/129fb3d0-cb43-49b5-b558-9f36543c0193.sh
{user_path}/actions-runner/_work/_temp/129fb3d0-cb43-49b5-b558-9f36543c0193.sh: line 1: {user_path}/dev-tools/test-runner/GithubActions/RunTests.py: Permission denied
Error: Process completed with exit code 1.
##[debug]Finishing: Mac - Run testing script

The first few lines in the python script:

if __name__ == '__main__':
    load_dotenv(find_dotenv())
    git_project_path = os.environ.get("GIT_PROJECT_PATH")

    parser = init_argparse()
    args = parser.parse_args()
    branch_name = args.branch_name[0]
    if not branch_name:
        exit(2)

The workflow script:

name: Testing on Self Hosted Runner
run-name: ${{ github.actor }} is running a test on a self hosted runner on branch ${{ github.head_ref }}.
on: pull_request

jobs:
  Create:
    runs-on: self-hosted
    steps:
      - name: Mac - Setup alias
        if: runner.os == 'macOS'
        run: |
          shopt -s expand_aliases

      - name: Mac - Run testing script
        if: runner.os == 'macOS'
        run: $SELF_HOSTED_UNITY_TEST_SCRIPT ${{ github.head_ref }}

I have the following imports in my RunTests.py script:

import argparse
import os
import subprocess
from os.path import join, dirname
from xml.etree import ElementTree

import git
from dotenv import load_dotenv, find_dotenv
from termcolor import cprint

Solution

  • I forgot that file permissions are a thing. Allowing the file to be executed using chmod -x {pythonScript.py} makes it work.