From 14b5951930565ed8bdc57d9cfa01b33f38d67507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobi=20Sch=C3=A4fer?= Date: Sat, 1 Jun 2024 15:17:34 +0200 Subject: [PATCH] Add reusable workflow for setting up SSH agent --- .github/actions/ssh/action.yml | 26 +++++++++++++++++++++ .github/workflows/stage.yml | 42 ++++++++++------------------------ 2 files changed, 38 insertions(+), 30 deletions(-) create mode 100644 .github/actions/ssh/action.yml diff --git a/.github/actions/ssh/action.yml b/.github/actions/ssh/action.yml new file mode 100644 index 00000000..ea2e93c1 --- /dev/null +++ b/.github/actions/ssh/action.yml @@ -0,0 +1,26 @@ +name: Set up SSH agent + +inputs: + config: + required: true + type: string + known-hosts: + required: true + type: string + +runs: + using: composite + + steps: + - name: Debug + run: | + echo ${{ inputs.config }} + echo ${{ inputs.known-hosts }} + + - 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 diff --git a/.github/workflows/stage.yml b/.github/workflows/stage.yml index af3e3b17..9d9c276e 100644 --- a/.github/workflows/stage.yml +++ b/.github/workflows/stage.yml @@ -1,7 +1,10 @@ name: Deploy (Staging) on: - workflow_dispatch + workflow_dispatch: {} + push: + branches: + - helma-🐜 env: SSH_AUTH_SOCK: /tmp/ssh-agent.sock @@ -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