Skip to content

Instantly share code, notes, and snippets.

@ixxie
Last active April 22, 2020 15:11
Show Gist options
  • Save ixxie/aa68ba0e1fd507fc7fda9d7a6b6aff64 to your computer and use it in GitHub Desktop.
Save ixxie/aa68ba0e1fd507fc7fda9d7a6b6aff64 to your computer and use it in GitHub Desktop.

Github Action works in its own repo but not from another repo

I'm having trouble with a remote call of a github action. The issue concerns an action I created called nixosify which is designed to install my Linux distro of choice on a remote machine. The action accepts four parameters:

  • target: ip of the machine to convert
  • tempkey: private key to grant access to the target
  • tempkey_pub: the temporary public key, used to add to the install medium
  • authkey_pub: a permanent public key to add to authorized keys on the target, post install

As you can see in this successful execution of a test workflow this all seems good and well. The test workflow uses a VPS provider's CLI to create an test instance, run the test, and kill it.

The trouble starts whenever I try to use the action in a workflow in a seperate repository. First I tried to use the action on this repo which is supposed to deploy a minecraft server. The workflow run attempts fail due to SSH Connection refused errors. This makes me suspect I am possibly passing the keys wrong; however, the calls of the action are practically identical except for the action being references elsewhere in the later case while being called locally in the former case.

To double check this is a reference issue, I clone the original repo and made the minimal modifications needed to make it work in the new context (see diff below), remembering to add all the needed secrets to both the repo and the VPS provider. Alas, the all-but-identical workflow fails in this new context, again with SSH Connection refused errors.

The diff:

diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index e216eb5..19704f1 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -1,7 +1,7 @@
 on: [push]
 
 env:
-  prefix: 'test-nixosifyB'
+  prefix: 'test-nixosify'
   HCLOUD_TOKEN: ${{ secrets.hcloud_token }}
 
 jobs:
@@ -34,7 +34,7 @@ jobs:
               --name ${name} \
               --type ${size} \
               --image ${image} \
-              --ssh-key nixosifyB
+              --ssh-key nixosify
             ip=$(hcloud server describe ${name} -o json | jq -r .public_net.ipv4.ip)
             host_info="${host_info}${name}\t${ip}\n"
           done
@@ -48,7 +48,7 @@ jobs:
           echo "$host_ip"
           echo "::set-output name=host_ip::$host_ip"
       - name: Test nixosify
-        uses: sparkletco/nixosify@273e5e6
+        uses: ./
         id: nixosify
         with:
           target: ${{ steps.get-host-ip.outputs.host_ip }}
# convert to nixos
name: 'Convert to NixOS'
description: 'Convert a Debian/Ubuntu machine to NixOS'
inputs:
target: # id of input
description: 'IP of target for conversion'
required: true
tempkey:
description: 'Temporary private key to access the machine to be converted'
required: true
tempkey_pub:
description: 'Temporary public key to access the machine to be converted'
required: true
authkey_pub:
description: 'Authorized SSH key to include in the NixOS machine'
required: true
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.target }}
- ${{ inputs.tempkey }}
- ${{ inputs.tempkey_pub }}
- ${{ inputs.authkey_pub }}
on: [push]
env:
prefix: 'test-nixosify'
HCLOUD_TOKEN: ${{ secrets.hcloud_token }}
jobs:
test-nixosify:
runs-on: ubuntu-latest
name: Test nixosify action
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install depedencies
env:
hcloud_binary: https://github.com/hetznercloud/cli/releases/download/v1.16.2/hcloud-linux-amd64.tar.gz
run: |
curl -L $hcloud_binary --output ./hcloud.tar.gz
tar -xf ./hcloud.tar.gz
sudo cp ./hcloud /usr/local/bin/hcloud
sudo apt-get install jq
- name: Create test servers
id: create-test-servers
env:
number: 1
size: 'cx11'
image: 'ubuntu-18.04'
run: |
host_info=""
for n in `seq ${number}`
do
name="${prefix}-${n}"
hcloud server create \
--name ${name} \
--type ${size} \
--image ${image} \
--ssh-key nixosify
ip=$(hcloud server describe ${name} -o json | jq -r .public_net.ipv4.ip)
host_info="${host_info}${name}\t${ip}\n"
done
echo "::set-output name=host_info::$host_info"
- name: Get host IP
id: get-host-ip
env:
host_info: ${{ steps.create-test-servers.outputs.host_info }}
run: |
host_ip=$(printf $host_info | awk '{print $2}')
echo "$host_ip"
echo "::set-output name=host_ip::$host_ip"
- name: Test nixosify
uses: ./
id: nixosify
with:
target: ${{ steps.get-host-ip.outputs.host_ip }}
tempkey: ${{ secrets.nixosify_key }}
tempkey_pub: ${{ secrets.nixosify_key_pub }}
authkey_pub: ${{ secrets.nixosify_key_pub }}
- name: Delete test servers
if: always()
run: |
hcloud server list -o noheader -o columns=name \
| awk -v pattern="$prefix" '$0 ~ pattern' \
| while read -r host;
do
hcloud server delete $host
done
on: [push]
env:
prefix: 'test-nixosifyB'
HCLOUD_TOKEN: ${{ secrets.hcloud_token }}
jobs:
test-nixosify:
runs-on: ubuntu-latest
name: Test nixosify action
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install depedencies
env:
hcloud_binary: https://github.com/hetznercloud/cli/releases/download/v1.16.2/hcloud-linux-amd64.tar.gz
run: |
curl -L $hcloud_binary --output ./hcloud.tar.gz
tar -xf ./hcloud.tar.gz
sudo cp ./hcloud /usr/local/bin/hcloud
sudo apt-get install jq
- name: Create test servers
id: create-test-servers
env:
number: 1
size: 'cx11'
image: 'ubuntu-18.04'
run: |
host_info=""
for n in `seq ${number}`
do
name="${prefix}-${n}"
hcloud server create \
--name ${name} \
--type ${size} \
--image ${image} \
--ssh-key nixosifyB
ip=$(hcloud server describe ${name} -o json | jq -r .public_net.ipv4.ip)
host_info="${host_info}${name}\t${ip}\n"
done
echo "::set-output name=host_info::$host_info"
- name: Get host IP
id: get-host-ip
env:
host_info: ${{ steps.create-test-servers.outputs.host_info }}
run: |
host_ip=$(printf $host_info | awk '{print $2}')
echo "$host_ip"
echo "::set-output name=host_ip::$host_ip"
- name: Test nixosify
uses: sparkletco/nixosify@273e5e6
id: nixosify
with:
target: ${{ steps.get-host-ip.outputs.host_ip }}
tempkey: ${{ secrets.nixosify_key }}
tempkey_pub: ${{ secrets.nixosify_key_pub }}
authkey_pub: ${{ secrets.nixosify_key_pub }}
- name: Delete test servers
if: always()
run: |
hcloud server list -o noheader -o columns=name \
| awk -v pattern="$prefix" '$0 ~ pattern' \
| while read -r host;
do
hcloud server delete $host
done
@AndrewMeadows
Copy link

Lol, I guess you should have just used one -v option. Then you would have only ended up with the "debug1" messages.

AFAICT everything succeeded. The SSH session returns exit status 0 at the very bottom. However, the whole session is cancelled for some reason. Dunno.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment