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 8c58165
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ssh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Set up SSH agent

on:
workflow_call:
inputs:
config:
required: true
type: string
known-hosts:
required: true
type: string
secrets:
SSH_PRIVATE_KEY:
required: true

env:
SSH_AUTH_SOCK: /tmp/ssh-agent.sock

jobs:
ssh-agent:
runs-on: ubuntu-latest

steps:
- name: Set up SSH agent
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
28 changes: 15 additions & 13 deletions .github/workflows/stage.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
name: Deploy (Staging)

on:
workflow_dispatch

env:
SSH_AUTH_SOCK: /tmp/ssh-agent.sock
workflow_dispatch: {}
push:
branches:
- helma-🐜

jobs:
ssh:
uses: ./.github/workflows/ssh.yml
with:
config: ${{ vars.SSH_CONFIG }}
known-hosts: ${{ vars.SSH_KNOWN_HOSTS }}
secrets: inherit

stage:
needs: ssh
runs-on: ubuntu-latest

environment:
Expand All @@ -29,17 +37,11 @@ jobs:
- 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
# The rsync command applies the same filters as the one in tools/extras/deploy.sh
run: |
rsync build/install/helma/ antville.dev:/ \
ssh antville.dev ping
echo rsync ./build/install/helma/ antville.dev:./ \
--verbose --archive --delete --compress \
--filter 'protect /lib/ext' \
--filter '+ /launcher.jar' \
Expand Down

0 comments on commit 8c58165

Please sign in to comment.