From f185cc9d95b82ceff7e18a28e8e028d31eb4fee4 Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Wed, 10 Sep 2025 12:32:15 -0300 Subject: [PATCH 01/24] =?UTF-8?q?Configura=C3=A7=C3=A3o=20inicial=20do=20C?= =?UTF-8?q?I=20com=20GitHub=20Actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Primeiras configurações do CI-CD --- .github/workflows/python-app.yml | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..1168bd9 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,39 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest From fcbd2845263393d205b117d285499551295b2217 Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Thu, 11 Sep 2025 15:35:23 -0300 Subject: [PATCH 02/24] Delete teste_cicd01.py --- teste_cicd01.py | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 teste_cicd01.py diff --git a/teste_cicd01.py b/teste_cicd01.py deleted file mode 100644 index 9d69c28..0000000 --- a/teste_cicd01.py +++ /dev/null @@ -1,8 +0,0 @@ -from main import read_root - -def test_passando(): - assert True - -def test_read_root (): - responses = read_root() - assert responses == {"hello": "world"} \ No newline at end of file From 9b9c81927be63169895db801049c950e47372d93 Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Sun, 14 Sep 2025 11:05:36 -0300 Subject: [PATCH 03/24] Tentando usar o Actions repliquei o trabalho, pois o github actions estava falhando --- .github/workflows/python-app.yml | 2 +- .idea/devops-puc.iml | 2 +- .idea/misc.xml | 5 +++-- main.py | 9 +++++++++ test_01.py | 10 ++++++++++ 5 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 main.py create mode 100644 test_01.py diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 1168bd9..2f3e79b 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -3,7 +3,7 @@ name: Python application -on: +on:s push: branches: [ "main" ] pull_request: diff --git a/.idea/devops-puc.iml b/.idea/devops-puc.iml index d6ebd48..10ba783 100644 --- a/.idea/devops-puc.iml +++ b/.idea/devops-puc.iml @@ -3,7 +3,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 6f29fee..8be8c38 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,7 @@ - - + + + \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..a577f6f --- /dev/null +++ b/main.py @@ -0,0 +1,9 @@ +def test_passando(): + assert True + +def test_read_root(): + response = read_root() + assert response == {"hello": "world"} + +def read_root(): + return {"hello": "world"} \ No newline at end of file diff --git a/test_01.py b/test_01.py new file mode 100644 index 0000000..dad7929 --- /dev/null +++ b/test_01.py @@ -0,0 +1,10 @@ +# test_main.py + +from main import read_root + +def test_passando(): + assert True + +def test_read_root(): + response = read_root() + assert response == {"hello": "world"} \ No newline at end of file From 06fd4fda17d20d62942b0b2d98ce90f14f91449e Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Sun, 14 Sep 2025 11:12:02 -0300 Subject: [PATCH 04/24] Update python-app.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Correção de sintaxe --- .github/workflows/python-app.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 2f3e79b..fb6c9ba 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -3,7 +3,7 @@ name: Python application -on:s +on: push: branches: [ "main" ] pull_request: @@ -14,26 +14,29 @@ permissions: jobs: build: - runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Set up Python 3.10 - uses: actions/setup-python@v3 + uses: actions/setup-python@v5 with: python-version: "3.10" + - name: Install dependencies run: | python -m pip install --upgrade pip pip install flake8 pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest run: | pytest From 3affb25e67bdbf75c74d2a3f85de9f102a56972b Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Sun, 14 Sep 2025 11:51:01 -0300 Subject: [PATCH 05/24] tentativa de configurar o actions --- .github/workflows/python-app.yml | 7 +------ main.py | 7 ------- test_01.py => tests/test_01.py | 2 -- 3 files changed, 1 insertion(+), 15 deletions(-) rename test_01.py => tests/test_01.py (90%) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index fb6c9ba..12c9d57 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -1,6 +1,3 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - name: Python application on: @@ -32,11 +29,9 @@ jobs: - name: Lint with flake8 run: | - # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | - pytest + pytest \ No newline at end of file diff --git a/main.py b/main.py index a577f6f..3dc9a50 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,2 @@ -def test_passando(): - assert True - -def test_read_root(): - response = read_root() - assert response == {"hello": "world"} - def read_root(): return {"hello": "world"} \ No newline at end of file diff --git a/test_01.py b/tests/test_01.py similarity index 90% rename from test_01.py rename to tests/test_01.py index dad7929..a6bfc89 100644 --- a/test_01.py +++ b/tests/test_01.py @@ -1,5 +1,3 @@ -# test_main.py - from main import read_root def test_passando(): From 5506ffbb62756374662c3e6d13b7b69c75e84247 Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Sun, 14 Sep 2025 12:37:09 -0300 Subject: [PATCH 06/24] fix: adiciona docstrings e corrige lint --- .github/workflows/python-app.yml | 35 +++++++++++--------------------- main.py | 10 ++++++++- tests/test_01.py | 8 +++++++- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 12c9d57..19d838f 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -1,37 +1,26 @@ -name: Python application +name: Pylint on: push: - branches: [ "main" ] + branches: [ "*" ] pull_request: - branches: [ "main" ] - -permissions: - contents: read - + branches: [ "*" ] jobs: build: runs-on: ubuntu-latest - + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10"] steps: - uses: actions/checkout@v4 - - - name: Set up Python 3.10 - uses: actions/setup-python@v5 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 with: - python-version: "3.10" - + python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - - name: Lint with flake8 - run: | - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - - name: Test with pytest + pip install pylint + - name: Analysing the code with pylint run: | - pytest \ No newline at end of file + pylint $(git ls-files '*.py') \ No newline at end of file diff --git a/main.py b/main.py index 3dc9a50..6118bb6 100644 --- a/main.py +++ b/main.py @@ -1,2 +1,10 @@ +"""Módulo principal do projeto devops-puc.""" + def read_root(): - return {"hello": "world"} \ No newline at end of file + """Retorna uma saudação simples.""" + return {"hello": "world"} + + +def outra_funcao(): + """Exemplo de função extra só pra teste.""" + return True diff --git a/tests/test_01.py b/tests/test_01.py index a6bfc89..cfca113 100644 --- a/tests/test_01.py +++ b/tests/test_01.py @@ -1,8 +1,14 @@ +"""Testes automatizados para o módulo main.""" + from main import read_root + def test_passando(): + """Teste que sempre passa.""" assert True +d def test_read_root(): + """Teste da função read_root().""" response = read_root() - assert response == {"hello": "world"} \ No newline at end of file + assert response == {"hello": "world"} From 1d765f2456a7e7d1916a449f979de5edda378f13 Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Sun, 14 Sep 2025 12:41:18 -0300 Subject: [PATCH 07/24] fix: adiciona docstrings e corrige lint --- tests/test_01.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_01.py b/tests/test_01.py index cfca113..30fe67b 100644 --- a/tests/test_01.py +++ b/tests/test_01.py @@ -6,7 +6,6 @@ def test_passando(): """Teste que sempre passa.""" assert True -d def test_read_root(): """Teste da função read_root().""" From 3ebdbf77f4f300e5b1690e55518cbfb1a18207d2 Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Mon, 15 Sep 2025 17:23:23 -0300 Subject: [PATCH 08/24] tentativa de configurar o actions --- .github/workflows/python-app.yml | 54 +++++++++++++++++++++----------- Dockerfile | 12 +++++++ main.py | 13 +++----- requirements.txt | 3 ++ 4 files changed, 55 insertions(+), 27 deletions(-) create mode 100644 Dockerfile create mode 100644 requirements.txt diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 19d838f..597d41c 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -1,26 +1,42 @@ -name: Pylint +name: Python + Docker on: push: - branches: [ "*" ] + branches: [ "main" ] pull_request: - branches: [ "*" ] + branches: [ "main" ] + jobs: - build: + test: runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.8", "3.9", "3.10"] + steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install pylint - - name: Analysing the code with pylint - run: | - pylint $(git ls-files '*.py') \ No newline at end of file + - uses: actions/checkout@v4 + + - name: Set up Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Run tests + run: pytest + + docker: + runs-on: ubuntu-latest + needs: test # só roda o Docker se os testes passarem + steps: + - uses: actions/checkout@v4 + + - name: Build Docker image + run: docker build -t testandodocker . + + - name: Run container + run: docker run -d -p 8000:80 --name test_container testandodocker + + - name: Check container logs + run: docker logs test_container diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c94b5e4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3 + +WORKDIR /usr/src/app + +COPY requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +EXPOSE 80 + +CMD [ "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80" ] diff --git a/main.py b/main.py index 6118bb6..3748535 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,7 @@ -"""Módulo principal do projeto devops-puc.""" +from fastapi import FastAPI -def read_root(): - """Retorna uma saudação simples.""" - return {"hello": "world"} +app = FastAPI() - -def outra_funcao(): - """Exemplo de função extra só pra teste.""" - return True +@app.get("/") +def home(): + return {"mensagem": "API funcionando no Docker!"} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..57a493a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +fastapi==0.111.1 +uvicorn[standard] + From 3a4584760e45c6188f618ed8b49fcf869bfdfc4d Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Mon, 22 Sep 2025 14:56:53 -0300 Subject: [PATCH 09/24] enviar mensagem para o Discord --- .github/workflows/python-app.yml | 11 +++++++++++ main.py | 4 ++++ tests/test_01.py | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 597d41c..71ce0fe 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -40,3 +40,14 @@ jobs: - name: Check container logs run: docker logs test_container + + + Discord: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Discord Webhook Action + uses: tsickert/discord-webhook@v7.0.0 + with: + webhook-url: ${{ secrets.DISCORD_WEBHOOK_ }} + filename: test.txt \ No newline at end of file diff --git a/main.py b/main.py index 3748535..debfe29 100644 --- a/main.py +++ b/main.py @@ -5,3 +5,7 @@ @app.get("/") def home(): return {"mensagem": "API funcionando no Docker!"} + + +def read_root(): + return {"mensagem": "API funcionando!"} diff --git a/tests/test_01.py b/tests/test_01.py index 30fe67b..689a058 100644 --- a/tests/test_01.py +++ b/tests/test_01.py @@ -11,3 +11,36 @@ def test_read_root(): """Teste da função read_root().""" response = read_root() assert response == {"hello": "world"} + +# tests/test_app.py + +from fastapi.testclient import TestClient +from main import app + +client = TestClient(app) + +def test_root_message(): + response = client.get("/") + assert response.status_code == 200 + assert response.json() == {"mensagem": "API funcionando no Docker!"} + +def test_soma_positiva(): + response = client.get("/soma/2/3") + assert response.status_code == 200 + assert "resultado" in response.json() + assert response.json() == {"resultado": 5} + +def test_soma_zero(): + response = client.get("/soma/0/5") + assert response.status_code == 200 + assert response.json()["resultado"] == 5 + +def test_soma_negativa(): + response = client.get("/soma/-2/-3") + assert response.status_code == 200 + assert response.json()["resultado"] == -5 + +def test_soma_valores_mistos(): + response = client.get("/soma/-2/3") + assert response.status_code == 200 + assert response.json()["resultado"] == 1 From 569cb1ab3f1923a69c43f59ac1f9aad6f0759520 Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Mon, 22 Sep 2025 16:04:38 -0300 Subject: [PATCH 10/24] enviar mensagem para o Discord --- .github/workflows/Discord.yml | 18 ++++++++++++++++++ .github/workflows/python-app.yml | 9 --------- 2 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/Discord.yml diff --git a/.github/workflows/Discord.yml b/.github/workflows/Discord.yml new file mode 100644 index 0000000..ade583e --- /dev/null +++ b/.github/workflows/Discord.yml @@ -0,0 +1,18 @@ +name: Discord Alerts + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + discord: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Enviar alerta para o Discord + uses: tsickert/discord-webhook@v7.0.0 + with: + webhook-url: ${{ secrets.DISCORD_WEBHOOK }} + content: " Novo commit ou PR criado no repositório!" diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 71ce0fe..fa21828 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -42,12 +42,3 @@ jobs: run: docker logs test_container - Discord: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Discord Webhook Action - uses: tsickert/discord-webhook@v7.0.0 - with: - webhook-url: ${{ secrets.DISCORD_WEBHOOK_ }} - filename: test.txt \ No newline at end of file From 0eabb0ff0ae5312cdb5827d0fec30bc09c0d02af Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Thu, 11 Sep 2025 11:38:08 -0300 Subject: [PATCH 11/24] Ajustando CI-CD # Conflicts: # .idea/.gitignore # .idea/devops-puc.iml # .idea/misc.xml --- .idea/.gitignore | 2 -- .idea/devops-puc.iml | 9 +++++---- .idea/inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/misc.xml | 2 +- .idea/modules.xml | 8 -------- test_primeiro.py | 8 ++++++++ 6 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/modules.xml create mode 100644 test_primeiro.py diff --git a/.idea/.gitignore b/.idea/.gitignore index a0ccf77..26d3352 100644 --- a/.idea/.gitignore +++ b/.idea/.gitignore @@ -1,5 +1,3 @@ # Default ignored files /shelf/ /workspace.xml -# Environment-dependent path to Maven home directory -/mavenHomeManager.xml diff --git a/.idea/devops-puc.iml b/.idea/devops-puc.iml index 10ba783..1eb8ccd 100644 --- a/.idea/devops-puc.iml +++ b/.idea/devops-puc.iml @@ -1,8 +1,9 @@ - - - - + + + + + diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 8be8c38..c262270 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,7 @@ - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 90f45fc..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/test_primeiro.py b/test_primeiro.py new file mode 100644 index 0000000..9d69c28 --- /dev/null +++ b/test_primeiro.py @@ -0,0 +1,8 @@ +from main import read_root + +def test_passando(): + assert True + +def test_read_root (): + responses = read_root() + assert responses == {"hello": "world"} \ No newline at end of file From 54dc0c9abda3c02c1be2348f8a8bf986910cf711 Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Thu, 11 Sep 2025 12:47:44 -0300 Subject: [PATCH 12/24] Ajustando CI-CD --- main.py | 12 ++++++------ test_primeiro.py | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index debfe29..c475da7 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,11 @@ -from fastapi import FastAPI -app = FastAPI() +def test_passando(): + assert True -@app.get("/") -def home(): - return {"mensagem": "API funcionando no Docker!"} +def test_read_root(): + response = read_root() + assert response == {"hello": "world"} def read_root(): - return {"mensagem": "API funcionando!"} + return {"hello": "world"} \ No newline at end of file diff --git a/test_primeiro.py b/test_primeiro.py index 9d69c28..a6bfc89 100644 --- a/test_primeiro.py +++ b/test_primeiro.py @@ -1,8 +1,8 @@ -from main import read_root +from main import read_root def test_passando(): assert True -def test_read_root (): - responses = read_root() - assert responses == {"hello": "world"} \ No newline at end of file +def test_read_root(): + response = read_root() + assert response == {"hello": "world"} \ No newline at end of file From ac956ba7e9c7c6a8c1f6154b549666a19b745446 Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Thu, 11 Sep 2025 15:30:05 -0300 Subject: [PATCH 13/24] Ajustando CI-CD 01 --- .idea/devops-puc.iml | 14 +++++++------- .idea/misc.xml | 2 +- main.py | 1 - test_primeiro.py | 8 -------- 4 files changed, 8 insertions(+), 17 deletions(-) delete mode 100644 test_primeiro.py diff --git a/.idea/devops-puc.iml b/.idea/devops-puc.iml index 1eb8ccd..aad402c 100644 --- a/.idea/devops-puc.iml +++ b/.idea/devops-puc.iml @@ -1,10 +1,10 @@ - - - - - - - + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c262270..18be27c 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/main.py b/main.py index c475da7..dd3f179 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,5 @@ def test_read_root(): response = read_root() assert response == {"hello": "world"} - def read_root(): return {"hello": "world"} \ No newline at end of file diff --git a/test_primeiro.py b/test_primeiro.py deleted file mode 100644 index a6bfc89..0000000 --- a/test_primeiro.py +++ /dev/null @@ -1,8 +0,0 @@ -from main import read_root - -def test_passando(): - assert True - -def test_read_root(): - response = read_root() - assert response == {"hello": "world"} \ No newline at end of file From 85423800bc326e7a21a268ebf4be797287e74bff Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Thu, 11 Sep 2025 16:18:09 -0300 Subject: [PATCH 14/24] Ajustando CI-CD 01 --- teste_cicd.py => test_main.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename teste_cicd.py => test_main.py (100%) diff --git a/teste_cicd.py b/test_main.py similarity index 100% rename from teste_cicd.py rename to test_main.py From f36b659c5b6eb2c75ad791b9347c50aecd345e01 Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Thu, 11 Sep 2025 16:55:32 -0300 Subject: [PATCH 15/24] Adicionando workflow para pytest --- .github/workflows/python-app.yml | 50 ++++++++++---------------------- 1 file changed, 15 insertions(+), 35 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index fa21828..afe1e58 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -1,44 +1,24 @@ -name: Python + Docker +name: Python application on: - push: - branches: [ "main" ] pull_request: branches: [ "main" ] jobs: - test: + build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - - name: Set up Python 3.10 - uses: actions/setup-python@v4 - with: - python-version: "3.10" - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - - name: Run tests - run: pytest - - docker: - runs-on: ubuntu-latest - needs: test # só roda o Docker se os testes passarem - steps: - - uses: actions/checkout@v4 - - - name: Build Docker image - run: docker build -t testandodocker . - - - name: Run container - run: docker run -d -p 8000:80 --name test_container testandodocker - - - name: Check container logs - run: docker logs test_container - - + - uses: actions/checkout@v4 + - name: Set up Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + pip install -r requirements.txt + - name: Test with pytest + run: | + pytest \ No newline at end of file From 466dd145d380206c8cb1317fc3cf28d286891cc8 Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Thu, 11 Sep 2025 17:10:02 -0300 Subject: [PATCH 16/24] =?UTF-8?q?Tentativa=20de=20corre=C3=A7=C3=A3o=20do?= =?UTF-8?q?=20Pytest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/python-app.yml | 3 ++- test_main.py | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index afe1e58..c24b085 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -18,7 +18,8 @@ jobs: run: | python -m pip install --upgrade pip pip install pytest - pip install -r requirements.txt + - name: Check file structure + run: ls -R - name: Test with pytest run: | pytest \ No newline at end of file diff --git a/test_main.py b/test_main.py index 9d69c28..4363150 100644 --- a/test_main.py +++ b/test_main.py @@ -1,8 +1,10 @@ -from main import read_root +# test_main.py + +from .main import read_root def test_passando(): assert True -def test_read_root (): - responses = read_root() - assert responses == {"hello": "world"} \ No newline at end of file +def test_read_root(): + response = read_root() + assert response == {"hello": "world"} \ No newline at end of file From 71a8bc095da4d76ddfdfd5c742757c1a09d446a5 Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Thu, 11 Sep 2025 17:54:59 -0300 Subject: [PATCH 17/24] Update python-app.yml ajustando o workflow --- .github/workflows/python-app.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index c24b085..fbe01d5 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -9,17 +9,22 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Set up Python 3.10 + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python uses: actions/setup-python@v4 with: python-version: "3.10" + - name: Install dependencies run: | python -m pip install --upgrade pip + pip install -r requirements.txt || true pip install pytest + - name: Check file structure run: ls -R - - name: Test with pytest - run: | - pytest \ No newline at end of file + + - name: Run tests with pytest + run: pytest --maxfail=1 --disable-warnings -q From 06f965786f6ab1bd8ed43b399664ffea858575db Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Thu, 11 Sep 2025 18:01:07 -0300 Subject: [PATCH 18/24] Create python-package.yml --- .github/workflows/python-package.yml | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/python-package.yml diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..e56abb6 --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,40 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python package + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest From 447a845fca0fedb22230a73f725927958fdfb845 Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Thu, 11 Sep 2025 18:05:59 -0300 Subject: [PATCH 19/24] Delete .github/workflows directory --- .github/workflows/python-app.yml | 30 --------------------- .github/workflows/python-package.yml | 40 ---------------------------- 2 files changed, 70 deletions(-) delete mode 100644 .github/workflows/python-app.yml delete mode 100644 .github/workflows/python-package.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml deleted file mode 100644 index fbe01d5..0000000 --- a/.github/workflows/python-app.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Python application - -on: - pull_request: - branches: [ "main" ] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.10" - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt || true - pip install pytest - - - name: Check file structure - run: ls -R - - - name: Run tests with pytest - run: pytest --maxfail=1 --disable-warnings -q diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml deleted file mode 100644 index e56abb6..0000000 --- a/.github/workflows/python-package.yml +++ /dev/null @@ -1,40 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - -name: Python package - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - build: - - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - python-version: ["3.9", "3.10", "3.11"] - - steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest - run: | - pytest From ed2b8a0e2ccaaa3310964ee75469491e36b059be Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Thu, 11 Sep 2025 17:31:50 -0300 Subject: [PATCH 20/24] Ajustando CI-CD 01 --- .idea/misc.xml | 2 +- test_main.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 18be27c..c262270 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/test_main.py b/test_main.py index 4363150..dad7929 100644 --- a/test_main.py +++ b/test_main.py @@ -1,6 +1,6 @@ # test_main.py -from .main import read_root +from main import read_root def test_passando(): assert True From 558d9cb5802d79144c4760d62eab19cb5bcf9ee7 Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Sat, 13 Sep 2025 13:36:50 -0300 Subject: [PATCH 21/24] Create pylint.yml testando pylint --- .github/workflows/pylint.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/pylint.yml diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml new file mode 100644 index 0000000..c73e032 --- /dev/null +++ b/.github/workflows/pylint.yml @@ -0,0 +1,23 @@ +name: Pylint + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10"] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pylint + - name: Analysing the code with pylint + run: | + pylint $(git ls-files '*.py') From 35e8d094cb32502a763e4b85b9d11cce7228a53b Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Sun, 14 Sep 2025 12:02:54 -0300 Subject: [PATCH 22/24] Update pylint.yml --- .github/workflows/pylint.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index c73e032..ef0a155 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -1,7 +1,10 @@ name: Pylint -on: [push] - +on: + push: + branches: [ "*" ] + pull_request: + branches: [ "*" ] jobs: build: runs-on: ubuntu-latest From 85476d84954100c68e70ee2b16ee1d84d374f162 Mon Sep 17 00:00:00 2001 From: Raulkubisds <147261111+Raulkubisds@users.noreply.github.com> Date: Sun, 14 Sep 2025 11:05:36 -0300 Subject: [PATCH 23/24] Tentando usar o Actions repliquei o trabalho, pois o github actions estava falhando --- .github/workflows/python-app.yml | 39 ++++++++++++++++++++++++++++++++ .idea/devops-puc.iml | 13 +++++------ .idea/misc.xml | 5 ++-- main.py | 1 - test_01.py | 10 ++++++++ 5 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/python-app.yml create mode 100644 test_01.py diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..2f3e79b --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,39 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on:s + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest diff --git a/.idea/devops-puc.iml b/.idea/devops-puc.iml index aad402c..d6ebd48 100644 --- a/.idea/devops-puc.iml +++ b/.idea/devops-puc.iml @@ -1,10 +1,9 @@ - - - - -