Giter Club home page Giter Club logo

actions-playground's Introduction

Actions Playground

Creating a GitHub Actions workflow with non-trivial commands may be annoying. Especially, when you have to do some experiments first, e.g. what command will work or which dependencies you need. It can be even harder when you are working on an operating system different from the target OS. Pushing and re-running the workflow each time is a nightmare.

This repository tries to simplify this kind of work. With it, you can start a single job that waits for your commands. This way, you can prepare your commands for a workflow interactively without committing, pushing, and long waiting.

Usage

First, you have to do one-time preparation to setup VPN and your fork. Next, you can start the workflow and connect to the runner over HTTP, SSH, RDP or VNC. Finally, when you are connected, you can use dedicated tools to simplify your work on the runner.

Possible connection types depends on the runner OS:

runner OS HTTP SSH SFTP RDP VNC
Ubuntu yes yes yes no no
macOS yes yes yes no yes1
Windows yes yes yes yes no

1 - VNC server on macos-11 is broken.

One-time preparations

Setup VPN

  1. Install ZeroTier.
    https://www.zerotier.com/download/

  2. Create your private network, if you don't have it yet.
    https://my.zerotier.com/

  3. Create a new API Access Token.
    https://my.zerotier.com/account

  4. Connect to your private network from your machine using GUI or the following command:

    sudo zerotier-cli join <network ID>
    

Prepare your repository

  1. Fork this repository on GitHub.

  2. Add GitHub Actions secrets in your fork's settings:

    • NETWORK_ID - your private network id.
    • ACCESS_TOKEN - your API Access Token .
    • PASSWORD - a password that you want to use later for authentication.
    • IP - IP address. Make sure that it matches you virtual network configuration and it does not conflicts with IPv4 Auto-Assign or IPv6 Auto-Assign ranges or other network members.
  3. Run Generate New Keys workflow in your fork's Actions. It will generate new internal keys needed for the SSH and it will check your configuration.

  4. If you want to use certificate authentication in the SSH, you have to configure it. See Setup SSH authentication, for details.

Connecting to the runner

  1. Go to your fork's Actions, select Playground workflow and Run workflow. You can select which OS you want to start. For Windows, you can select default shell that will be available over HTTP and SSH.

  2. Runner will be ready to connect after approx. 3 min, when the Your work starts here step is running.

  3. Connect to your runner over HTTP, SSH, RDP or VNC.

    • Address: configured previously in the repository's IP variable/secret,
    • User name:runner on Ubuntu and macOS, runneradmin on Windows (user name is not needed for VNC legacy mode),
    • Password: configured previously in the repository's PASSWORD secret.

    For example, to connect:

    • over HTTP, type the following address to your browser:

      http://<your runner ip address>/
      
    • over SSH to Ubuntu or macOS runner:

      ssh runner@<your runner ip address>
      

      If you have a private key in a file, you can add -i <path to private key> option.

  4. When you are done, use following command to end the action:

    exit_job
    

Using dedicated tools on a runner

When you connect, SSH will show you a banner with information how to use tools to simplify work with the runner. You may need to scroll up a bit to see it.

macOS, Ubuntu and Windows bash banner

Hello!

You can play with the runner now.

. exit_job
    Exit current action job with success.

. load_job
    Load environment variables that are available inside job steps, for
    example variables starting with the "GITHUB_" prefix. If you are
    connecting over HTTP the environment is already loaded, you can
    skip this command.

/tmp/log
    A FIFO that redirects everything from it to the log on GitHub Action.
    For example, the following command will print bash history to log:

        history > /tmp/log

    WINDOWS ONLY: When using a bash-incompatible tools from bash shell,
    the FIFO may not work, but "\\.\pipe\log" may work instead.

$GH_ARTIFACT
    An environment variable set by ". load_job" script containing a path.
    Content of this directory will be published as a workflow artifact.
    For example, you can compress and send current directory to the artifact:

        tar -czf $GH_ARTIFACT/workspace.tgz .

    Artifact will be available only after successful finish of workflow run,
    so you have to call ". exit_job" when you're done.

ghctx
    Command outputs GitHub Actions context value. For example, show runner OS:

        ghctx runner.os

    WINDOWS ONLY: The context contains OS-compatible paths, but if you are
    using bash in Windows, you may want to convert them to bash-compatible
    paths with the "-p" option.

------------------------------------------------------------------------------
You can see more examples of commands in your bash history (up arrow key).
------------------------------------------------------------------------------

Windows cmd and PowerShell banner

Hello!

You can play with the runner now.

Currently, PowerShell is not fully supported. Some of commands below may
work only in cmd.

exit_job
    Exit current action job with success.

load_job
    Load environment variables that are available inside job steps, for
    example variables starting with the "GITHUB_" prefix. If you are
    connecting over HTTP the environment is already loaded, you can
    skip this command.

\\.\pipe\log
    A named pipe that redirects everything from it to the log on GitHub Action.
    For example, the following command will print your history to log:

        doskey /history > \\.\pipe\log

%GH_ARTIFACT%
    An environment variable set by "load_job" script containing a path.
    Content of this directory will be published as a workflow artifact.
    For example, you can compress and send current directory to the artifact:

        tar -czf %GH_ARTIFACT%\workspace.tgz .

    Artifact will be available only after successful finish of workflow run,
    so you have to call "exit_job" when you're done.

ghctx
    Command outputs GitHub Actions context value. For example, show runner OS:

        ghctx runner.os

------------------------------------------------------------------------------

Setup SSH authentication

This is needed only if you want to use certificate authentication in SSH. You can skip this, if you want to use SSH password authentication, RDP or HTTP.

You have a few options here, depending on your authentication preferences:

  1. If you want to use your existing SSH public key (*.pub), e.g. from your ~/.ssh/ directory, copy its content to the CLIENT_KEY secret.

  2. If you want to use a new SSH key that was automatically generated, you can go keys branch that was created by the Generate New Keys workflow. Open ZIP file using a password from the PASSWORD secret. You will have there a new private key that you can later use to connect over the SSH.

  3. If you want to generate your own SSH key pair (e.g. using instructions from Generating a new SSH key), you have to copy newly generated public key to the CLIENT_KEY secret.

  4. You can combine above methods multiple times. The CLIENT_KEY secret accepts multiple public keys, one key per line.

Footnotes

  1. VNC server on macos-11 is broken. 2

actions-playground's People

Contributors

doki-nordic avatar

Watchers

James Cloos avatar  avatar

Forkers

kildom

actions-playground's Issues

Fix `load_job` documentation

load_job description should be fixed since environment is loaded automatically now in bash over HTTP and SSH.

[prestudy] Drop SSH support

HTTP connection is able to do the same as SSH (to confirm) and it is easier to use and configure.

Since SSH support takes a lot of code and effort, maybe remove it?

Show banner in HTTP connection

Use .bashrc to show banner. Script should detect if it is the first bash process after the ttyd process.

For consistency, this may also work for SSH if possible. This may resolve problem of needing to scroll up on some OSes (to confirm).

On Windows, the banner may also start in the notepad (or separate cmd window) for RDP connection.

Allow alternative tunneling method

. ZeroTier pinggy.io zrok.io localhost.run
account yes optional yes no
limit - 1h per tunnel - -
local software yes (service) no yes (except HTTP) no
HTTP yes yes yes yes
SSH yes yes require local sw no
Other protocols yes probably yes require local sw no

https://pinggy.io/

  • HTTP: ssh -p 443 -R0:localhost:80 a.pinggy.io
  • SSH: ssh -p 443 -R0:localhost:22 [email protected]

https://zrok.io/

  • zrok enable
  • HTTP: zrok share public localhost:80
  • SSH:
    • host: zrok share private --backend-mode tcpTunnel localhost:22
    • client: zrok access private 5adagwfl888k

https://localhost.run/

Use python venv

Currently, python modules are installed with pip globally, that affects user environment, so it is not the same as clean worker run.
Create virtual environment in temp directory.

A new problem to solve: avoid propagating virtual environment variables to the shells (ssh, http)

Fix case when there is no "CLIENT_KEY" secret

Remove:

    keys = inputs.contexts['secrets']['CLIENT_KEY']
    keys += '\n' + (inputs.keys_dir / 'client_key.pub').read_text()

Replace with:

    if 'CLIENT_KEY' in inputs.contexts['secrets']:
        keys = inputs.contexts['secrets']['CLIENT_KEY'] + '\n'
    else:
        keys = ''
    keys += (inputs.keys_dir / 'client_key.pub').read_text()

Test Windows platform

Test all functionalities in Windows. Something may be broken by the latest changes.

Show connection info in the log

Show commands and links:

  • http link (with user name if works in modern browsers)
  • vnc link and connection information (only macOS)
  • rdp link and connection information (only Windows)
  • ssh link and connection information
  • sftp link and connection information

Put it in the README.md file on the keys branch. Add link to it from main README.md (on top and in the description)

Some information:

========================= HTTP =========================
Link: http://[email protected]/
      http://192.168.194.252/
User: runner
Password: ***from PASSWORD secret***

========================= SSH =========================
Link: ssh://[email protected]
Address: 192.168.194.252
User: runner
Password: ***from PASSWORD secret***

========================= SFTP =========================
Link: sftp://[email protected]/
Address: 192.168.194.252
User: runner
Password: ***from PASSWORD secret***

...
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.