Skip to content

Commit

Permalink
Merge pull request #63 from ff137/lint-and-test-workflow
Browse files Browse the repository at this point in the history
👷 Create lint and test workflow
  • Loading branch information
WadeBarnes authored Mar 14, 2024
2 parents bce1dff + 1b8c2b2 commit 4fe2bf1
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 65 deletions.
12 changes: 9 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# For details on how this file works refer to:
# - https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
# For details on how this file works refer to:
# - https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
version: 2
updates:
# Maintain dependencies for GitHub Actions
Expand All @@ -11,4 +11,10 @@ updates:
interval: weekly
groups:
all-actions:
patterns: [ "*" ]
patterns: ["*"]

# Maintain pip dependencies
- package-ecosystem: pip
directory: /
schedule:
interval: daily
72 changes: 72 additions & 0 deletions .github/workflows/lint-and-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Lint and test

on:
# Manual dispatch option:
workflow_dispatch:
# Trigger the workflow only for pull requests for the main branch
pull_request:
branches:
- main

jobs:
style:
name: Python linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install \
isort~=5.13.2 \
black~=24.2.0
- name: Check import style with isort
run: |
isort . --check --profile black --diff
- name: Check code style with Black
run: |
black . --check --diff
test:
name: Integration Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: "indy-tails-server" # Specify a path to clone the main repo into a specific directory

# Clone von-network repository
- name: Checkout von-network repository
uses: actions/checkout@v4
with:
repository: "bcgov/von-network"
path: "von-network" # Clone into a separate directory

# Build and start von-network
- name: Build and start von-network
run: |
cd von-network
chmod +x manage
./manage build
./manage start
- name: Build and run tests
run: |
cd indy-tails-server/docker
chmod +x ./manage
./manage build
./manage test
- name: Stop von-network
run: |
cd von-network
./manage stop
- name: Stop indy-tails-server
run: |
cd indy-tails-server/docker
./manage stop
24 changes: 20 additions & 4 deletions docker/Dockerfile.test
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
FROM bcgovimages/von-image:next-1
FROM ubuntu:20.04

# Note: libindy is a dependency for tests, and it's easiest to install on ubuntu images
# using debian from python base images doesn't allow following steps to work, so build from ubuntu:20

# Install ca-certificates and add the Sovrin repository key
RUN apt-get update && apt-get install -y ca-certificates gnupg software-properties-common && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys CE7709D068DB5E88 && \
add-apt-repository "deb https://repo.sovrin.org/sdk/deb bionic stable" && \
apt-get update && \
apt-get install -y libindy

# Install Python 3.9 and python3-pip
RUN apt-get install -y python3.9 python3.9-venv python3.9-dev python3-pip

ADD requirements.txt .
ADD requirements.dev.txt .

RUN pip3 install --upgrade pip
RUN pip3 install --no-cache-dir -r requirements.txt -r requirements.dev.txt
# Upgrade pip using Python 3.9 to ensure compatibility
RUN python3.9 -m pip install --upgrade pip

# Use Python 3.9's pip to install dependencies from requirements files
RUN python3.9 -m pip install --no-cache-dir -r requirements.txt -r requirements.dev.txt

ADD test ./

ENTRYPOINT ["python", "integration.py"]
ENTRYPOINT ["python3.9", "integration.py"]
11 changes: 7 additions & 4 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
rich
pynacl
aiofiles
rich~=13.7.0
pynacl~=1.5.0
aiofiles~=23.2.1

python3_indy
python3_indy~=1.16.0.post286

isort~=5.13.2
black~=24.2.0
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
aiohttp==3.8.6
base58
base58~=2.1.1

# temporary to fix transitive dependency issues
multidict<5.0.0
Expand All @@ -8,4 +8,4 @@ yarl==1.6.0
# indy_vdr
# Error loading library: indy_vdr specified version because it occurs when installing as pip3 install indy-vdr.

indy_vdr==0.4.0.dev16
indy_vdr==0.4.0.dev16
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import os
import runpy
from setuptools import setup, find_packages

from setuptools import find_packages, setup

PACKAGE_NAME = "tails_server"
version_meta = runpy.run_path("./{}/version.py".format(PACKAGE_NAME))
Expand Down Expand Up @@ -39,4 +40,4 @@ def parse_requirements(filename):
"Operating System :: OS Independent",
],
scripts=["bin/tails-server"],
)
)
1 change: 0 additions & 1 deletion tails_server/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import argparse


PARSER = argparse.ArgumentParser(description="Runs the server.")


Expand Down
2 changes: 0 additions & 2 deletions tails_server/ledger.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import logging
from tempfile import NamedTemporaryFile
import base64

from binascii import Error as BinAsciiError
import indy_vdr

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion tails_server/logging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from os import path
import logging
from logging.config import fileConfig
from os import path

DEFAULT_LOGGING_CONFIG_PATH = path.join(
path.dirname(path.abspath(__file__)), "config", "default_logging_config.ini"
Expand Down
21 changes: 7 additions & 14 deletions tails_server/web.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import logging
import hashlib
import base58
import logging
import os

from os.path import isfile, join
from tempfile import NamedTemporaryFile

import base58
from aiohttp import web

from .config.defaults import DEFAULT_WEB_HOST, DEFAULT_WEB_PORT, CHUNK_SIZE
from .ledger import (
get_rev_reg_def,
BadGenesisError,
BadRevocationRegistryIdError,
)
from .config.defaults import CHUNK_SIZE, DEFAULT_WEB_HOST, DEFAULT_WEB_PORT
from .ledger import BadGenesisError, BadRevocationRegistryIdError, get_rev_reg_def

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -56,6 +51,7 @@ async def get_file(request):

await response.write_eof()


@routes.get("/hash/{tails_hash}")
async def get_file_by_hash(request):
tails_hash = request.match_info["tails_hash"]
Expand Down Expand Up @@ -170,7 +166,6 @@ async def put_file(request):
return web.Response(text=tails_hash)



@routes.put("/hash/{tails_hash}")
async def put_file_by_hash(request):
storage_path = request.app["settings"]["storage_path"]
Expand Down Expand Up @@ -213,7 +208,7 @@ async def put_file_by_hash(request):
# Basic validation of tails file:
# Tails file must start with "00 02"
tmp_file.seek(0)
if tmp_file.read(2) != b'\x00\x02':
if tmp_file.read(2) != b"\x00\x02":
raise web.HTTPBadRequest(text='Tails file must start with "00 02".')

# Since each tail is 128 bytes, tails file size must be a multiple of 128
Expand All @@ -224,9 +219,7 @@ async def put_file_by_hash(request):

# File integrity is good so write file to permanent location.
tmp_file.seek(0)
with open(
os.path.join(storage_path, tails_hash), "xb"
) as tails_file:
with open(os.path.join(storage_path, tails_hash), "xb") as tails_file:
while True:
chunk = tmp_file.read(CHUNK_SIZE)
if not chunk:
Expand Down
Loading

0 comments on commit 4fe2bf1

Please sign in to comment.