diff --git a/.github/actions/ssh/action.yml b/.github/actions/ssh/action.yml new file mode 100644 index 00000000..928871b3 --- /dev/null +++ b/.github/actions/ssh/action.yml @@ -0,0 +1,34 @@ +name: Set up SSH agent +description: Set up the SSH agent +author: Tobi Schäfer + +inputs: + config: + description: The SSH configuration + required: true + key: + description: The private SSH key + required: true + known-hosts: + description: The list of known hosts + required: true + +runs: + using: composite + + steps: + - name: Set up SSH agent + shell: bash + env: + CONFIG: ${{ inputs.config }} + KEY: ${{ inputs.key }} + KNOWN_HOSTS: ${{ inputs.known-hosts }} + SOCKET: /tmp/ssh-agent.sock + run: | + mkdir -p ~/.ssh + echo "${CONFIG}" > ~/.ssh/config + echo "${KNOWN_HOSTS}" > ~/.ssh/known_hosts + + echo "SSH_AUTH_SOCK=${SOCKET}" >> $GITHUB_ENV + ssh-agent -a ${SOCKET} > /dev/null + ssh-add - <<< "${KEY}" diff --git a/.github/workflows/stage.yml b/.github/workflows/stage.yml index af3e3b17..2dd4d28d 100644 --- a/.github/workflows/stage.yml +++ b/.github/workflows/stage.yml @@ -1,10 +1,10 @@ name: Deploy (Staging) on: - workflow_dispatch - -env: - SSH_AUTH_SOCK: /tmp/ssh-agent.sock + workflow_dispatch: {} + push: + branches: + - helma-🐜 jobs: stage: @@ -17,34 +17,14 @@ 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 + uses: ./.github/actions/ssh + with: + config: ${{ vars.SSH_CONFIG }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + known-hosts: ${{ vars.SSH_KNOWN_HOSTS }} - - name: Publish to staging server + - name: Test run: | - rsync build/install/helma/ antville.dev:/ \ - --verbose --archive --delete --compress \ - --filter 'protect /lib/ext' \ - --filter '+ /launcher.jar' \ - --filter '+ /lib' \ - --filter '- /*' \ - - - name: Restart Helma - run: ssh antville.dev restart + echo $SSH_AUTH_SOCK + ssh antville.dev ping