Skip to content

CD - Deploy to onto-ns.com #107

CD - Deploy to onto-ns.com

CD - Deploy to onto-ns.com #107

Workflow file for this run

name: CD - Deploy to onto-ns.com
on:
workflow_run:
workflows: ["CI - Tests"]
types: [completed]
branches: [main]
workflow_dispatch:
jobs:
check-service-changes:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
outputs:
service-changes: ${{ steps.check-changes.outputs.service-changes }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check changes
id: check-changes
run: |
git fetch --all --quiet
git diff --name-only origin/main -- | \
grep -qE "(pyproject.toml|entities_service/((models/|service/)(.+/)*)?[^/]*\.py)" \
&& SERVICE_CHANGES=true \
|| SERVICE_CHANGES=false
echo "Changed files:"
git diff --name-only origin/main --
echo "SERVICE_CHANGES=${SERVICE_CHANGES}"
echo "service-changes=${SERVICE_CHANGES}" >> $GITHUB_OUTPUT
deploy:
runs-on: ubuntu-latest
needs: check-service-changes
if: ${{ needs.check-service-changes.outputs.service-changes == 'true' }}
steps:
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install dependencies
run: sudo apt update && sudo apt install -y curl
- name: Deploy updated main
run: |
curl -o response.json --silent -m 30 http://api.onto-ns.com/deploy/?service=entities-service
cat << EOF | python
import json
import sys
from pathlib import Path
response = json.loads(Path('response.json').read_bytes())
if response["service"] != "entities-service":
sys.exit(
"ERROR: Did not deploy the correct service\n"
f" service: {response['service']}\n"
f" code: {response['returncode']}\n"
f" stderr: {response['stderr']}\n\n"
f" stdout: {response['stdout']}"
)
if response["returncode"] != 0:
sys.exit(
"ERROR: Non-zero return code\n"
f" code: {response['returncode']}\n"
f" stderr:\n{response['stderr']}\n\n"
f" stdout:\n{response['stdout']}"
)
if response["stderr"]:
print(
"WARNING: stderr is not empty\n"
f" stderr:\n{response['stderr']}\n\n"
)
print(
"SUCCESS!\n"
f" code: {response['returncode']}\n"
f" stdout:\n{response['stdout']}"
)
EOF