From daa1c267e88ba58cc1894ee4c998c8d39734524a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Valyi?= Date: Fri, 5 Jul 2024 05:21:35 +0000 Subject: [PATCH] add CI and image push --- .github/workflows/ci.yml | 45 +++++++++++++++++++++++++ test_run.py | 71 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 test_run.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..38bfd2e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,45 @@ +name: Build + +on: + push: + push: + branches: + - master + pull_request: + schedule: + - cron: "0 4 * * 0" + +jobs: + build-boleto-cnab-api: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to ghcr.io + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build image + uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile + cache-from: type=registry,ref=ghcr.io/build-boleto-cnab-api-latest + cache-to: type=local,dest=/tmp/.buildx-cache + load: true + - name: Install test pre-requisites + run: pip install pytest + - name: Test + run: pytest -v + - name: Push image + uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=inline + push: true + if: ${{ github.repository_owner == 'akretion' && github.ref == 'refs/heads/master' }} diff --git a/test_run.py b/test_run.py new file mode 100644 index 0000000..df6b57b --- /dev/null +++ b/test_run.py @@ -0,0 +1,71 @@ +import json +import tempfile +from pathlib import Path +import os +import subprocess +import requests +import time + + +def test_run(): + cmd = ["docker", "build", "-t", "akretion/boleto_cnab_api", "."] + result = subprocess.run( + cmd, check=False, capture_output=True, text=True, cwd=Path(__file__).parent + ) + assert result.returncode == 0, result.stderr + "\n" + result.stdout + + cmd = [ + "docker", + "run", + "-d", + "-p", + "9292:9292", + "--name=boleto_cnab_api", + "akretion/boleto_cnab_api", + ] + result = subprocess.run(cmd, check=False, capture_output=True, text=True) + assert result.returncode == 0, result.stderr + "\n" + result.stdout + time.sleep(5) + remessa_values = [ + { + "valor": 5.0, + "cedente": "Kivanio Barbosa", + "documento_cedente": "12345678912", + "sacado": "Claudio Pozzebom", + "sacado_documento": "12345678900", + "agencia": "0810", + "conta_corrente": "53678", + "convenio": 12387, + "nosso_numero": "12345678", + "bank": "itau", + }, + { + "valor": 10.00, + "cedente": "PREFEITURA MUNICIPAL DE VILHENA", + "documento_cedente": "04092706000181", + "sacado": "João Paulo Barbosa", + "sacado_documento": "77777777777", + "agencia": "1825", + "conta_corrente": "0000528", + "convenio": "245274", + "nosso_numero": "000000000000001", + "bank": "caixa", + }, + ] + content = json.dumps(remessa_values) + with open(tempfile.mktemp(), "w") as f: + file_name = f.name + f.write(content) + files = {"data": open(file_name, "rb")} + result = requests.post( + "http://localhost:9292/api/boleto/multi", + data={ + "type": "pdf", + }, + files=files, + ) + assert str(result.status_code)[0] == "2" + + cmd = ["docker", "rm", "-f", "boleto_cnab_api"] + result = subprocess.run(cmd, check=False, capture_output=True, text=True) + assert result.returncode == 0, result.stderr + "\n" + result.stdout