Create LICENSE #15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PGIS Toolkit Frontend | |
on: | |
push: | |
branches: | |
- '*' | |
workflow_dispatch: | |
jobs: | |
build: | |
name: Build Static Files | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clone repository | |
uses: actions/checkout@v2 | |
- name: Use Node.js 12.22.12 | |
uses: actions/setup-node@v1 | |
with: | |
node-version: 12.22.12 | |
- name: Cache node_modules | |
uses: actions/cache@v2 | |
with: | |
path: node_modules | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
- name: Write Environment Variables | |
id: write_env | |
run: | | |
set -e | |
case "${{ github.ref }}" in | |
refs/heads/staging) | |
cat > .env <<EOF | |
#STAGING MODE | |
TITLE=USAFIRI | |
BASE_URL=https://pgis.naxa.com.np/api | |
USERS_URL=https://pgis.naxa.com.np/api | |
ASSETS_URL=https://pgis.naxa.com.np | |
API_URL=https://pgis.naxa.com.np/api/v1 | |
DASHBOARD_API_URL=https://pgis.naxa.com.np/api/v2 | |
LOGIN_API_URL=https://pgis.naxa.com.np/api | |
BIPAD_API_URL=https://bipadportal.gov.np/api/v1 | |
TOKEN=${{ secrets.ENV_SECRET }} | |
EOF | |
;; | |
refs/heads/master) | |
cat > .env <<EOF | |
#PROD MODE | |
TITLE=USAFIRI | |
BASE_URL=https:///app.usafiri.io/api | |
USERS_URL=https:///app.usafiri.io/api | |
ASSETS_URL=https:///app.usafiri.io | |
API_URL=https:///app.usafiri.io/api/v1 | |
DASHBOARD_API_URL=https:///app.usafiri.io/api/v2 | |
LOGIN_API_URL=https:///app.usafiri.io/api | |
BIPAD_API_URL=https://bipadportal.gov.np/api/v1 | |
TOKEN=${{ secrets.ENV_SECRET }} | |
EOF | |
;; | |
esac | |
- name: Install dependencies | |
run: npm install --force | |
- name: Generate build | |
run: | | |
npm run build | |
- name: Upload Dist as Artifacts | |
uses: actions/upload-artifact@v3 | |
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/staging' }} | |
with: | |
name: Pgis-${{ github.ref_name }} | |
path: dist | |
retention-days: 2 | |
deploy: | |
name: Deploy static files | |
needs: | |
- build | |
if: ${{ github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/master' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clone repository | |
uses: actions/checkout@v2 | |
- name: Get Artifacts | |
uses: actions/download-artifact@v1 | |
with: | |
path: dist | |
name: Pgis-${{ github.ref_name }} | |
- name: Get VM SSH host and user | |
id: get_vm_conf | |
run: | | |
case "${{ github.ref }}" in | |
refs/heads/staging) | |
export SERVER_HOST=159.89.164.123 | |
export SERVER_USERNAME=devops | |
export PROJECT_PATH=/srv/Projects/pgis-toolkit_frontend_staging/dist | |
;; | |
refs/heads/master) | |
export SERVER_HOST=13.39.95.193 | |
export SERVER_USERNAME=ubuntu | |
export PROJECT_PATH=/home/ubuntu/Projects/pgis-toolkit_frontend_prod_landing/dist | |
;; | |
esac | |
echo "SERVER_HOST=${SERVER_HOST}" >> $GITHUB_OUTPUT | |
echo "SERVER_USERNAME=${SERVER_USERNAME}" >> $GITHUB_OUTPUT | |
echo "PROJECT_PATH=${PROJECT_PATH}" >> $GITHUB_OUTPUT | |
- name: Configure SSH key | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
chmod 400 ~/.ssh/id_rsa | |
ssh-keyscan ${{ steps.get_vm_conf.outputs.SERVER_HOST }} >> ~/.ssh/known_hosts | |
- name: copy static files | |
run: | | |
scp -r ./dist/* ${{ steps.get_vm_conf.outputs.SERVER_USERNAME }}@${{ steps.get_vm_conf.outputs.SERVER_HOST }}:${{ steps.get_vm_conf.outputs.PROJECT_PATH }} | |
echo "Build Pass" |