Skip to content

fix(backend): ensure existing tests all pass (#689) #654

fix(backend): ensure existing tests all pass (#689)

fix(backend): ensure existing tests all pass (#689) #654

name: Build and Deploy
on:
# Push includes PR merge
push:
branches:
- main
- staging
- dev
paths:
# Workflow is triggered only if src changes
- src/**
# Allow manual trigger
workflow_dispatch:
jobs:
backend-build:
uses: hotosm/gh-workflows/.github/workflows/[email protected]
with:
context: ./src/backend
build_target: service
image_name: ghcr.io/${{ github.repository }}/backend
dockerfile: Dockerfile
scan_image: false
secrets: inherit
extra-vars:
runs-on: ubuntu-latest
environment:
name: ${{ github.ref_name == 'dev' && 'develop' || github.ref_name }}
outputs:
BASE_URL: ${{ steps.vars_and_secrets_to_env.outputs.BASE_URL }}
COG_URL: ${{ steps.vars_and_secrets_to_env.outputs.COG_URL }}
SITE_NAME: ${{ steps.vars_and_secrets_to_env.outputs.SITE_NAME }}
steps:
- name: Vars to Env File
env:
VARS_CONTEXT: ${{ toJson(vars) }}
run: |
# Parse JSON with multiline strings
to_envs() { jq -r "to_entries[] | \"\(.key)=\(.value)\""; }
# Create .env file from VARS_CONTEXT
if [ "${VARS_CONTEXT}" != "null" ]; then
echo "${VARS_CONTEXT}" | to_envs > .env
fi
- name: Extract relevant vars
id: vars_and_secrets_to_env
run: |
BASE_URL=$(grep '^BASE_URL=' .env | cut -d '=' -f2-)
echo $BASE_URL
echo "BASE_URL=${BASE_URL}" >> "$GITHUB_OUTPUT"
COG_URL=$(grep '^COG_URL=' .env | cut -d '=' -f2-)
echo "COG_URL=${COG_URL}" >> "$GITHUB_OUTPUT"
echo $COG_URL
SITE_NAME=$(grep '^SITE_NAME=' .env | cut -d '=' -f2-)
echo "SITE_NAME=${SITE_NAME}" >> "$GITHUB_OUTPUT"
echo $SITE_NAME
frontend-build:
uses: hotosm/gh-workflows/.github/workflows/[email protected]
needs:
- extra-vars
with:
context: ./src/frontend
build_target: prod
image_name: ghcr.io/${{ github.repository }}/frontend
dockerfile: Dockerfile
extra_build_args: |
BASE_URL=${{ needs.extra-vars.outputs.BASE_URL }}
COG_URL=${{ needs.extra-vars.outputs.COG_URL }}
SITE_NAME=${{ needs.extra-vars.outputs.SITE_NAME }}
scan_image: false
secrets: inherit
deploy_to_vm:
name: Deploy to VM
needs:
- frontend-build
- backend-build
uses: hotosm/gh-workflows/.github/workflows/[email protected]
with:
environment: ${{ github.ref_name == 'dev' && 'develop' || github.ref_name }}
# Note we set build="false", as we already built in the step above
command: start prod ${{ github.ref_name }} "false"
example_env_file_path: .env.example
secrets: inherit