Github Actions - dev ops

General Notes

1. Check Marketplace for latest versions of marketplace actions
        

Get Access to your project's base directory

# Adding the checkout action gives you access via the $GITHUB_WORKSPACE variable as shown by example below.
# There are exceptions to this rule. I think particularly when using another action that exists inside a self contained container

steps:
    - name: Checkout the repo
      uses: actions/checkout@v2

    - name: Get version number as $TAG
      run: echo "TAG=$(cat $GITHUB_WORKSPACE/version.py | grep -oP '[0-9]\.[0-9]\.[0-9]')" >> $GITHUB_ENV
        

Checkout Repository

- name: Checkout
  uses: actions/checkout@v2.3.4
        

Run Multiple Commands

     - run: |
        echo "An initial message"
        pip install -r requirements.txt
        

Set an environment variable

- name: Get version number as $TAG
  run: echo "TAG=$(cat $GITHUB_WORKSPACE/version.py | grep -oP '[0-9]\.[0-9]\.[0-9]')" >> $GITHUB_ENV

# Access TAG variable with:
${{ env.TAG }}
        

Self-hosted Runner Pros/Cons

Pros

Score Pro
  • 1 Allows (I think) for SSH from the runner with the same key as used on the machine.
  • 2 Allows (I think) to be used with IP specific firewall in place.

Cons

Score Con
  • 2 If I have to use another computer (like for example I'm on my laptop), I have to add that laptop to the pool of runners if I want my action to run
  • 1 Could lead to more complexity. Another service running on my personal machine.

Self-hosted Runner Troubleshooting

https://docs.github.com/en/actions/hosting-your-own-runners/monitoring-and-troubleshooting-self-hosted-runners
        

Run SSH Commands on Remote Server

# This operates on your remote server so any scripts should have absolute paths to their location,
# as they exist on the server

- name: executing remote ssh commands using ssh key
  uses: appleboy/ssh-action@master
  with:
    host: $
    username: $
    key: $
    passphrase: $
    port: $
    script: ~/script_in_home_dir.sh