Skip to content

Instantly share code, notes, and snippets.

@danielmichaels
Created July 17, 2020 14:37
Show Gist options
  • Save danielmichaels/770102d058bf29c71f3830b78ba4d848 to your computer and use it in GitHub Desktop.
Save danielmichaels/770102d058bf29c71f3830b78ba4d848 to your computer and use it in GitHub Desktop.

Action Setup Workflow

What you need to do in order to setup a basic Github Actions

SSH

On the server (droplet) create a new ssh key

  • ssh-keygen -t rsa -b 4096 -C "github-actions"

copy the key into ~/.ssh/authorized_keys

  • cat ~/.ssh/id_rsa.pub >> .ssh/authorized_keys

Copy the private key into your clipboard we need this next

  • cat ~/.ssh/id_rsa

Secrets

After setting up the server's ssh, we need to login to the repo on github and head to the settings page.

Settings > Secrets > Add Secret

  • SSH_KEY: private key (id_rsa)
  • HOST: ip or domain name
  • USERNAME: user who will own the repository; I use deployer
  • PORT: defaults to 22, but better to be explicit even if you don't change it

Settings > Deploy Key > Add Deploy Key

Add the server's public key to this. I use the name of the server user; deployer

*.yml

All the secrets and setup are adjusted for ssh-action.

Example .yml file for a simple action which can ssh into our server

    - name: SSH Remote Commands
      uses: appleboy/ssh-action@v0.1.2
      env:
        REPO: ${{ github.repository }}
      with:
        script_stop: true
        host: ${{ secrets.HOST }}
        username: ${{ secrets.USERNAME }}
        port: ${{ secrets.PORT }}
        key: ${{ secrets.SSH_KEY }}
        envs: REPO
        script: |
          pwd
          git pull
          echo "git pull $REPO"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment