-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from akretion/ci
add CI and image push
- Loading branch information
Showing
2 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Build | ||
|
||
on: | ||
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' }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |