Created
August 2, 2023 03:58
-
-
Save zellwk/c621f73a3c75ac964f56f0c811d7ec80 to your computer and use it in GitHub Desktop.
Github Actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See https://zellwk.com/blog/github-actions-deploy/ an explanation of this code | |
name: deploy | |
on: | |
push: | |
branches: | |
- main | |
- master | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/setup-node@v1 | |
- run: npm install | |
- run: npm run build | |
- name: Install SSH Key | |
uses: shimataro/ssh-key-action@v2 | |
with: | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
known_hosts: unnecessary | |
- name: Adding Known Hosts | |
run: ssh-keyscan -p ${{ secrets.SSH_PORT }} -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts | |
- name: Deploy with rsync | |
run: rsync -avz -e "ssh -p ${{ secrets.SSH_PORT }}" ./dist/ ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/var/www/students.asyncjs.today/dist/ | |
- name: Restart Server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USER }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
port: ${{ secrets.SSH_PORT }} | |
script: | | |
cd /PATH_TO_FOLDER | |
git fetch origin master | |
git reset --hard FETCH_HEAD | |
git clean -d -f --exclude secrets | |
npm install --production | |
npm run restart |
@Tholkappiar, I am getting the same error, where you able to solve it?
note:runs-on not a architect platform,that's a name of your hosted runner name
I don’t understand you, what do you mean?
Hi @zellwk Thanks for sharing this. Your blog post https://zellwk.com/blog/github-actions-deploy/ was very helpful and it helped me setup the workflow the way I wanted it. I had to tweak my configuration a little bit to get it working but it was worth it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is mine which i used :
And got this :
Run ssh-keyscan -H *** >> ~/.ssh/known_hosts ssh-keyscan -H *** >> ~/.ssh/known_hosts shell: /usr/bin/bash -e {0} Error: Process completed with exit code 1.
Any idea Bro ?