Skip to content

Commit 08f6d4c

Browse files
committed
fix: ci/cd
Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com>
1 parent f1eab8d commit 08f6d4c

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

.github/workflows/ci-cd.yml

+22-11
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ on:
44
push:
55
branches:
66
- main
7+
pull_request:
78

89
jobs:
9-
build:
10+
build-test:
1011
runs-on: ubuntu-latest
1112

1213
steps:
@@ -24,6 +25,18 @@ jobs:
2425
- name: Run build
2526
run: npm run build
2627

28+
- name: Run tests
29+
run: npm test
30+
31+
deploy:
32+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
33+
needs: build-test
34+
runs-on: ubuntu-latest
35+
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v2
39+
2740
- name: Docker login
2841
env:
2942
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
@@ -36,20 +49,18 @@ jobs:
3649
- name: Push Docker image
3750
run: docker push sahilyeole/portfolio:latest
3851

39-
deploy:
40-
needs: build
41-
runs-on: ubuntu-latest
52+
- name: Start ssh-agent
53+
uses: webfactory/ssh-agent@v0.5.4
54+
with:
55+
ssh-private-key: ${{ secrets.SSH_KEY }}
56+
ssh-passphrase: ${{ secrets.SSH_PASSPHRASE }}
4257

43-
steps:
4458
- name: Deploy to server via SSH
45-
uses: appleboy/ssh-action@master
46-
with:
47-
host: ${{ secrets.SSH_HOST }}
48-
username: ${{ secrets.SSH_USERNAME }}
49-
key: ${{ secrets.SSH_KEY }}
50-
script: |
59+
run: |
60+
ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} << 'EOF'
5161
docker pull sahilyeole/portfolio:latest
5262
docker stop portfolio-container || true
5363
docker rm portfolio-container || true
5464
docker run -d --name portfolio-container -p 80:3000 sahilyeole/portfolio:latest
65+
EOF
5566

0 commit comments

Comments
 (0)