Skip to content

try 163

try 163 #187

Workflow file for this run

name: Build and deploy on server
on:
push
env:
DIRECTORY: "${{ vars.DIRECTORY }}/${{ github.event.repository.name }}"
jobs:
checkout-code:
environment: Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "latest"
- name: Create .env file
run: |
echo "${{ secrets.ENVS }}" > .env
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: source-code
path: .
setup-ssh:
environment: Test
runs-on: ubuntu-latest
needs: checkout-code
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: source-code
path: .
- name: Set up SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Add server to known hosts
run: |
mkdir -p ~/.ssh
echo "${{ secrets.KNOWN_HOSTS }}" > ~/.ssh/known_hosts
deploy-on-server:
environment: Test
runs-on: ubuntu-latest
needs: setup-ssh
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: source-code
path: .
- name: Deploy on Server
env:
SERVER_USER: ${{ secrets.SERVER_USER }}
SERVER_HOST: ${{ secrets.SERVER_HOST }}
DIRECTORY: ${{ env.DIRECTORY }}
run: |
echo $DIRECTORY
ssh -t $SERVER_USER@$SERVER_HOST << EOF
rm -rf $DIRECTORY && mkdir -p $DIRECTORY
EOF
scp -r * $SERVER_USER@$SERVER_HOST:$DIRECTORY
scp .env $SERVER_USER@$SERVER_HOST:$DIRECTORY/.env
ssh -t $SERVER_USER@$SERVER_HOST << EOF
echo "Starting deployment process..."
cd $DIRECTORY
sh deploy.sh
echo "Deployment successful, cleaning up directory..."
rm -rf $DIRECTORY
EOF