Skip to content

Commit

Permalink
Add reusable workflow for setting up SSH agent
Browse files Browse the repository at this point in the history
  • Loading branch information
p3k committed Jun 1, 2024
1 parent 048cdc3 commit c0172c5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 30 deletions.
29 changes: 29 additions & 0 deletions .github/actions/ssh/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Set up SSH agent
description: Set up the SSH agent

inputs:
config:
description: The SSH configuration
required: true
known-hosts:
description: The list of known hosts
required: true

runs:
using: composite

steps:
- name: Debug
shell: sh
run: |
echo ${{ inputs.config }}
echo ${{ inputs.known-hosts }}
- name: Set up SSH agent
shell: sh
run: |
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add - <<< '${{ secrets.SSH_PRIVATE_KEY }}'
mkdir -p ~/.ssh
echo '${{ inputs.config }}' > ~/.ssh/config
echo '${{ inputs.known-hosts }}' > ~/.ssh/known_hosts
42 changes: 12 additions & 30 deletions .github/workflows/stage.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: Deploy (Staging)

on:
workflow_dispatch
workflow_dispatch: {}
push:
branches:
- helma-🐜

env:
SSH_AUTH_SOCK: /tmp/ssh-agent.sock
Expand All @@ -17,34 +20,13 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3

- name: Build with Gradle
run: ./gradlew installDist

- name: Set up SSH agent
run: |
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add - <<< "${{ secrets.SSH_PRIVATE_KEY }}"
mkdir -p ~/.ssh
echo '${{ vars.SSH_CONFIG }}' > ~/.ssh/config
echo '${{ vars.KNOWN_HOSTS }}' > ~/.ssh/known_hosts
- name: Publish to staging server
run: |
rsync build/install/helma/ antville.dev:/ \
--verbose --archive --delete --compress \
--filter 'protect /lib/ext' \
--filter '+ /launcher.jar' \
--filter '+ /lib' \
--filter '- /*' \
uses: ./.github/actions/ssh
with:
config: ${{ vars.SSH_CONFIG }}
known-hosts: ${{ vars.SSH_KNOWN_HOSTS }}
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Restart Helma
run: ssh antville.dev restart
- name: Test
run: ssh antville.dev ping

0 comments on commit c0172c5

Please sign in to comment.