Skip to content

Merge pull request #3 from sebenns/update-phone #38

Merge pull request #3 from sebenns/update-phone

Merge pull request #3 from sebenns/update-phone #38

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
env:
HOST: ${{ github.ref == 'refs/heads/main' && secrets.PROD_NEO4J_HOST || secrets.DEV_NEO4J_HOST || '' }}
USERNAME: ${{ github.ref == 'refs/heads/main' && secrets.PROD_NEO4J_USERNAME || secrets.DEV_NEO4J_USERNAME || '' }}
PASSWORD: ${{ github.ref == 'refs/heads/main' && secrets.PROD_NEO4J_PASSWORD || secrets.DEV_NEO4J_PASSWORD || '' }}
run: |
sed -i -e '$a\' .env
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 openSSH
run: |
sudo apt-get update
sudo apt-get install openssh-client -y
- name: SSH Key Action
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: ssh-scp-ssh-pipelines
env:
APP_NAME: ${{ github.ref == 'refs/heads/main' && '"GraphQL"' || '"GraphQL Dev"' }}
uses: cross-the-world/[email protected]
with:
host: ${{ github.ref == 'refs/heads/main' && secrets.PROD_SSH_HOST || secrets.DEV_SSH_HOST || '' }}
user: ${{ github.ref == 'refs/heads/main' && secrets.PROD_SSH_USER || secrets.DEV_SSH_USER || '' }}
key: ${{ github.ref == 'refs/heads/main' && secrets.PROD_SSH_KEY || secrets.DEV_SSH_KEY || '' }}
first_ssh: |
cd ${{ secrets.SSH_PATH }}
pm2 delete --silent $APP_NAME || :
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 $APP_NAME -- start
pm2 save