Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow github-act-runner as external runner #485

Open
ChristopherHX opened this issue Dec 20, 2024 · 2 comments
Open

Allow github-act-runner as external runner #485

ChristopherHX opened this issue Dec 20, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@ChristopherHX
Copy link
Owner

Currently only actions/runner and microsoft/azure-pipelines-agent are managed via --runner-version and the azpipelines event to use the ado agents.

@ChristopherHX ChristopherHX added the enhancement New feature or request label Dec 20, 2024
@ChristopherHX
Copy link
Owner Author

./bin/Runner.Worker content for --runner-path ./

#!/usr/bin/python3
# This script can be used to call Runner.Worker as github-act-runner worker on unix like systems
# You just have to create simple .runner file in the root folder with the following Content
# {"workFolder": "_work"}
# Then use `python3 path/to/this/script.py path/to/actions/runner/bin/Runner.Worker` as the worker args

import sys
import subprocess
import os
import threading
import codecs

if sys.argv[1] != "spawnclient":
    print("Unknown command", sys.argv[1])
    sys.exit(1)
readfd = int(sys.argv[2])
writefd = int(sys.argv[3])

rdr, rdw = os.pipe()

def redirectio():
    while(True):
        messageType = int.from_bytes(os.read(readfd, 4), sys.byteorder, signed=False)
        os.write(rdw, messageType.to_bytes(4, "big", signed=False))
        messageLength = int.from_bytes(os.read(readfd, 4), sys.byteorder, signed=False)
        message = os.read(readfd, messageLength)
        encoded = codecs.decode(message, "utf_16").encode("utf-8")
        os.write(rdw, len(encoded).to_bytes(4, "big", signed=False))
        os.write(rdw, encoded)

threading.Thread(target=redirectio, daemon=True).start()

code = subprocess.call(["/path/to/github-act-runner", "worker"], stdin=rdr, stdout=sys.stdout, pass_fds=(rdr, sys.stdout.fileno()))
print(code)
# https://github.com/actions/runner/blob/af6ed41bcb47019cce2a7035bad76c97ac97b92a/src/Runner.Common/Util/TaskResultUtil.cs#L13-L14
if code == 0:
    sys.exit(100)
else:
    sys.exit(1)

@ChristopherHX
Copy link
Owner Author

ChristopherHX commented Dec 22, 2024

Using both actions/runner pipe to github-act-runner stdio to actions/runner pipe works across stdio redirection. Better docker runtime than the modified actions/runner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant