Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info

Note the double > without the double > the existing contents of authorized_keys will be over-written (nuked!) and that may not be desirable


Create the workflow file in .github/workflows

Code Block
languagebash
name: CI
on: [push, pull_request]
jobs:
  # test:
  #   ...
  deploy:
    name: "Deploy to staging"
    runs-on: ubuntu-latest
    if: github.event_name == 'push' && github.ref == 'refs/heads/master'
    # needs: test
    steps:
      - name: Configure SSH
        run: |
          mkdir -p ~/.ssh/
          echo "$SSH_KEY" > ~/.ssh/staging.key
          chmod 600 ~/.ssh/staging.key
          cat >>~/.ssh/config <<END
          Host staging
            HostName $SSH_HOST
            User $SSH_USER
            IdentityFile ~/.ssh/staging.key
            StrictHostKeyChecking no
          END
        env:
          SSH_USER: ${{ secrets.STAGING_SSH_USER }}
          SSH_KEY: ${{ secrets.STAGING_SSH_KEY }}
          SSH_HOST: ${{ secrets.STAGING_SSH_HOST }}
- name: Stop the server
        run: ssh staging 'sudo systemctl stop my-application'
- name: Check out the source
        run: ssh staging 'cd my-application && git fetch && git reset --hard origin/master'
- name: Start the server
        if: ${{ always() }}
        run: ssh staging 'sudo systemctl start my-application'
 

 

 



https://dev.to/s1hofmann/github-actions-ssh-deploy-setup-l7h

...