name: Deploy to production run-name: Deploying to production on: [push] jobs: deploy: runs-on: ubuntu-latest container: image: alpine steps: - name: Install packages run: | apk add --no-cache git openssh-client nodejs - name: Checkout code uses: actions/checkout@v3 - name: Setup SSH env: SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} HOST1: ${{ secrets.HOST1 }} USER: ${{ secrets.USER }} run: | mkdir -p ~/.ssh echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa ssh-keyscan -H $HOST1 >> ~/.ssh/known_hosts - name: Deploy to host env: HOST1: ${{ secrets.HOST1 }} USER: ${{ secrets.USER }} run: | echo "Deploying..." echo "Removing old files..." ssh $USER@$HOST1 'rm -rf /var/www/elia.network/html/*' echo "Copying new files..." scp -r . $USER@$HOST1:/var/www/elia.network/html echo "Deployment done!" ssh $USER@$HOST1 'rm -r /var/www/elia.network/html/.git*'