Skip to content

Update deploy.yml

Update deploy.yml #28

Workflow file for this run

# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
name: Deployment
on:
push:
branches:
- develop
- main
jobs:
build:
name: build the project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "20.x"
cache: "npm"
cache-dependency-path: |
client/package-lock.json
server/package-lock.json
- run: |
npm ci --force
npm run build
working-directory: "./client"
- run: |
npm ci
npm run compile
working-directory: "./server"
- name: Create environment file
run: |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
HOST=${{ secrets.PROD_NEO4J_HOST }}
USERNAME=${{ secrets.PROD_NEO4J_USERNAME }}
PASSWORD=${{ secrets.PROD_NEO4J_PASSWORD }}
else
HOST=${{ secrets.DEV_NEO4J_HOST }}
USERNAME=${{ secrets.DEV_NEO4J_USERNAME }}
PASSWORD=${{ secrets.DEV_NEO4J_PASSWORD }}
fi
echo "NEO4J_HOST=$HOST" >> .env
echo "NEO4J_USERNAME=$USERNAME" >> .env
echo "NEO4J_PASSWORD=$PASSWORD" >> .env
working-directory: "./server"
- name: Create directory structure for deployment
run: |
mkdir -p deploy/client
mkdir -p deploy/server
cp -r client/dist deploy/client/
cp -r server deploy/
working-directory: ${{ github.workspace }}
- name: Zip artifact for deployment
run: zip deploy.zip ./deploy -r
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: artifact
path: /home/runner/work/socinian-graph-dse/socinian-graph-dse/deploy.zip
deploy:
name: deploy to server
needs: [ build ]
runs-on: ubuntu-latest
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: artifact
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ github.ref == 'refs/heads/main' && secrets.PROD_SSH_KEY || secrets.DEV_SSH_KEY || '' }}
known_hosts: ${{ github.ref == 'refs/heads/main' && secrets.PROD_KNOWN_HOSTS || secrets.DEV_KNOWN_HOSTS || '' }}
- name: Set environment variables
run: |
SSH_HOST=${{ github.ref == 'refs/heads/main' && secrets.PROD_SSH_HOST || secrets.DEV_SSH_HOST || '' }}
SSH_USER=${{ github.ref == 'refs/heads/main' && secrets.PROD_SSH_USER || secrets.DEV_SSH_USER || '' }}
SSH_KEY=${{ github.ref == 'refs/heads/main' && secrets.PROD_SSH_KEY || secrets.DEV_SSH_KEY || '' }}
SSH_KEY=${{ github.ref == 'refs/heads/main' && secrets.PROD_SSH_KEY || secrets.DEV_SSH_KEY || '' }}
- name: ssh-scp-ssh-pipelines
uses: cross-the-world/[email protected]
with:
host: ${{ env.SSH_HOST }}
user: ${{ env.SSH_USER }}
key: ${{ env.SSH_KEY }}
first_ssh: |
cd ${{ secrets.SSH_PATH }}
pm2 delete --silent "GraphQL Dev" || :
rm -r * || :
scp: /home/runner/work/socinian-graph-dse/socinian-graph-dse/deploy.zip => ${{ secrets.SSH_PATH }}
last_ssh: |
cd ${{ secrets.SSH_PATH }}
mkdir temp_folder
unzip deploy.zip -d temp_folder
mv temp_folder/deploy/client ./
mv temp_folder/deploy/server ./
rm -r temp_folder
cd server
npm ci
pm2 start npm --name "GraphQL Dev" -- start
pm2 save