Skip to content

Merge pull request #18 from alik-r/dependabot/go_modules/backend/gola… #26

Merge pull request #18 from alik-r/dependabot/go_modules/backend/gola…

Merge pull request #18 from alik-r/dependabot/go_modules/backend/gola… #26

Workflow file for this run

name: Auto Deploy in VPS after Push in Production
on:
push:
branches:
- main
jobs:
server_checks:
name: CI checks for server code
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
ref: main
token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
- name: Set up Go environment
uses: actions/setup-go@v3
with:
go-version: '1.22'
- name: Run Go Tests
run: |
cd backend
go test ./...
- name: Format Go code (go fmt)
run: |
cd backend
go fmt ./...
- name: Vet Go code (go vet)
run: |
cd backend
go vet ./...
deploy:
name: Deploy project
permissions:
deployments: write
runs-on: ubuntu-latest
needs: server_checks
steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
ref: main
token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
- name: Create GitHub deployment
uses: chrnorm/deployment-action@v2
id: deployment
with:
token: '${{ github.token }}'
environment-url: ${{ vars.MY_APP }}
environment: production
- name: Set up SSH Key and Deploy my App on Server
uses: appleboy/ssh-action@master
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
with:
host: ${{ secrets.VPS_IP }}
username: ${{ secrets.VPS_USERNAME }}
password: ${{ secrets.VPS_PASSWORD }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: 22
script: |
git config --global url."https://${{ secrets.PERSONAL_GITHUB_TOKEN }}:@github.com".insteadOf "https://github.com"
cd /var/www/casino.alikamran.cc
git pull origin main
sudo docker compose down
sudo docker compose pull
sudo docker compose build --no-cache
sudo docker compose up -d
- name: Update deployment Status (success)
if: success()
uses: chrnorm/deployment-status@v2
with:
token: '${{ github.token }}'
environment-url: ${{ vars.MY_APP }}
state: 'success'
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
- name: Update deployment status (failure)
if: failure()
uses: chrnorm/deployment-status@v2
with:
token: '${{ github.token }}'
environment-url: ${{ vars.MY_APP }}
state: 'failure'
deployment-id: ${{ steps.deployment.outputs.deployment_id }}