Skip to content

Commit 9a9ddc1

Browse files
committed
Multinode workflow: use github user's ssh key
1 parent 0b02c4c commit 9a9ddc1

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

.github/workflows/stackhpc-multinode.yml

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,52 @@ name: Multinode
4646
description: How long to break execution for (minutes) (note that instances are cleaned up after 12h)
4747
type: number
4848
default: 60
49+
use_my_ssh_key:
50+
description: authorise my github ssh keys on Ansible control host
51+
default: 'true'
52+
type: boolean
4953
ssh_key:
50-
description: SSH public key to authorise on Ansible control host
54+
description: SSH public key to authorise on Ansible control host (if different from github ssh keys)
5155
type: string
5256
terraform_kayobe_multinode_version:
5357
description: terraform-kayobe-multinode version
5458
type: string
5559
default: main
5660
jobs:
61+
github_user_ssh_keys:
62+
name: Retrieve actor github ssh keys
63+
runs-on: ubuntu-latest
64+
# Map a step output to a job output, this allows other jobs to be gated on the filter results
65+
outputs:
66+
ssh_keys: ${{ steps.compute_ssh_keys.outputs.ssh_keys }}
67+
steps:
68+
- name: Retrieve github user ssh keys or use provided ones
69+
id: compute_ssh_keys
70+
run: |
71+
# encode array using jq: https://jstrieb.github.io/posts/github-actions-multiline-outputs/
72+
if ${{ inputs.use_my_ssh_key }} && [ -z "${{ inputs.ssh_key }}" ]; then
73+
echo "Fetching ssh keys for ${{ github.actor }}"
74+
ssh_keys="$(gh api /users/${{ github.actor }}/keys --jq '[.[].key]' | jq --compact-output)"
75+
if [ -z "${ssh_keys}" ]; then
76+
echo "E: Unable to get '${{ github.actor }}' ssh keys (quotes added for clarity)"
77+
exit 1
78+
fi
79+
elif [ -n "${{ inputs.ssh_key }}" ]; then
80+
# single string to JSON array
81+
ssh_keys="$(jq --raw-input --compact-output '.|[.]' <<<"${{ inputs.ssh_key }}")"
82+
else
83+
ssh_keys=''
84+
fi
85+
echo "ssh_keys=${ssh_keys}" >> "$GITHUB_OUTPUT"
86+
env:
87+
GH_TOKEN: ${{ github.token }}
88+
- name: Show ssh_keys
89+
run: |
90+
echo "${{ steps.compute_ssh_keys.outputs.ssh_keys }}"
5791
multinode:
5892
name: Multinode
59-
uses: stackhpc/stackhpc-openstack-gh-workflows/.github/workflows/[email protected]
93+
needs: github_user_ssh_keys
94+
uses: stackhpc/stackhpc-openstack-gh-workflows/.github/workflows/multinode.yml@multi_ssh_keys
6095
with:
6196
multinode_name: ${{ inputs.multinode_name }}
6297
os_distribution: ${{ inputs.os_distribution }}
@@ -67,7 +102,7 @@ jobs:
67102
break_on: ${{ inputs.break_on }}
68103
# Workaround loss of number type using fromJSON: https://github.com/orgs/community/discussions/67182
69104
break_duration: ${{ fromJSON(inputs.break_duration) }}
70-
ssh_key: ${{ inputs.ssh_key }}
105+
ssh_keys: ${{ needs.github_user_ssh_keys.outputs.ssh_keys }}
71106
stackhpc_kayobe_config_version: ${{ github.ref_name }}
72107
# NOTE(upgrade): Reference the PREVIOUS and CURRENT releases here.
73108
stackhpc_kayobe_config_previous_version: ${{ inputs.upgrade == 'major' && 'stackhpc/2024.1' || 'stackhpc/2025.1' }}

0 commit comments

Comments
 (0)