From a4f041469a270675e714f390cec6999d9b935bc3 Mon Sep 17 00:00:00 2001 From: checktheroads Date: Fri, 1 Jan 2021 14:23:15 -0700 Subject: [PATCH] github actions ci additions [skip ci] --- .github/workflows/backend.yml | 34 +++++++++++++++++++----- .github/workflows/frontend.yml | 26 ++++++++++++++++++ .tests/ga-backend-app.sh | 48 ++++++++++++++++++++++++++++++++++ hyperglass/cli/util.py | 26 +++++++----------- 4 files changed, 111 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/frontend.yml create mode 100755 .tests/ga-backend-app.sh diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index c4b407b..dd7b7ce 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -6,22 +6,42 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.6, 3.8] + node-version: [14.x] + redis-version: [5, 6] poetry-version: [1.1.4] + python-version: [3.6, 3.8] os: [ubuntu-20.04] runs-on: ${{ matrix.os }} + steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - name: Git Checkout + uses: actions/checkout@v2 + + - name: Install Python + uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Run image + + - name: Install Poetry uses: abatilo/actions-poetry@v2.0.0 with: poetry-version: ${{ matrix.poetry-version }} - - name: Install Dependencies + + - name: Install Node + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Start Redis + uses: supercharge/redis-github-action@1.1.0 + with: + redis-version: ${{ matrix.redis-version }} + + - name: Install Python Dependencies run: poetry install - - name: Flake8 + + - name: Run Flake8 run: poetry run flake8 hyperglass + - name: Run hyperglass - run: '.tests/app/setup.sh' + run: '.tests/ga-backend-app.sh' diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml new file mode 100644 index 0000000..15e93ba --- /dev/null +++ b/.github/workflows/frontend.yml @@ -0,0 +1,26 @@ +name: Frontend Testing +on: [push, pull_request] + +jobs: + frontend: + name: Type Check + strategy: + fail-fast: false + matrix: + node-version: [14.x] + os: [ubuntu-20.04] + runs-on: ${{ matrix.os }} + steps: + - name: Git Checkout + uses: actions/checkout@v2 + + - name: Install Node + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + + - name: Install Dependencies + run: yarn install + + - name: TypeScript Check + uses: icrawl/action-tsc@v1 diff --git a/.tests/ga-backend-app.sh b/.tests/ga-backend-app.sh new file mode 100755 index 0000000..bf2a6ea --- /dev/null +++ b/.tests/ga-backend-app.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +echo "[INFO] Starting setup..." +poetry run hyperglass setup -d +echo "[SUCCESS] Setup completed." +sleep 2 + +echo "[INFO] Setting listen_address..." +echo "listen_address: 127.0.0.1" >> $HOME/hyperglass/hyperglass.yaml + +echo "[INFO] Starting UI build." +poetry run hyperglass build-ui + +if [[ ! $? == 0 ]]; then + echo "[ERROR] Failed to start hyperglass." + exit 1 +else + echo "[SUCCESS] UI build completed." +fi + +echo "[INFO] Starting hyperglass..." +poetry run hyperglass start &> $HOME/hyperglass-ci.log & +sleep 180 + +if [[ ! $? == 0 ]]; then + echo "[ERROR] Failed to start hyperglass." + exit 1 +else + echo "[SUCCESS] Started hyperglass." +fi + +echo "[INFO] Running HTTP test..." + +STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8001) + +echo "[INFO] Status code: $STATUS" + +if [[ ! $? == 0 ]]; then + echo "[ERROR] HTTP test failed." + exit 1 +elif [[ ! "$STATUS" == "200" ]]; then + echo "[ERROR] HTTP test failed. Startup log:" + cat /var/log/hyperglassci.log + exit 1 +fi + +echo "[SUCCESS] Tests ran successfully." +exit 0 \ No newline at end of file diff --git a/hyperglass/cli/util.py b/hyperglass/cli/util.py index 5eca9ad..87268f2 100644 --- a/hyperglass/cli/util.py +++ b/hyperglass/cli/util.py @@ -383,19 +383,9 @@ def migrate_static_assets(app_path): callback(msg, a=a, b=b) -def install_systemd(app_path): - """Installs generated systemd file to system's systemd directory. +def install_systemd(app_path: Path) -> bool: + """Installs generated systemd file to system's systemd directory.""" - Arguments: - app_path {Path} -- hyperglass runtime path - - Raises: - ClickException: Raised if the /etc/systemd/system does not exist - ClickException: Raised if the symlinked file does not exit - - Returns: - {bool} -- True if successful - """ service = app_path / "hyperglass.service" systemd = Path("/etc/systemd/system") installed = systemd / "hyperglass.service" @@ -403,12 +393,16 @@ def install_systemd(app_path): if not systemd.exists(): error("{e} does not exist. Unable to install systemd service.", e=systemd) - installed.symlink_to(service) + try: + installed.symlink_to(service) + if not installed.exists(): + warning("Unable to symlink {s} to {d}", s=service, d=installed) + else: + success("Symlinked {s} to {d}", s=service, d=installed) - if not installed.exists(): - error("Unable to symlink {s} to {d}", s=service, d=installed) + except PermissionError: + warning("Permission denied to {f}. Systemd service not installed.", f=installed) - success("Symlinked {s} to {d}", s=service, d=installed) return True