From ed1ec4f09c46f1f649a4c62e189c1f25794ea96a Mon Sep 17 00:00:00 2001 From: Chander Pal <44088072+chander-pal@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:39:24 +0530 Subject: [PATCH 01/15] Create pr-workflow.yml --- .github/workflows/pr-workflow.yml | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/pr-workflow.yml diff --git a/.github/workflows/pr-workflow.yml b/.github/workflows/pr-workflow.yml new file mode 100644 index 0000000..e63486d --- /dev/null +++ b/.github/workflows/pr-workflow.yml @@ -0,0 +1,42 @@ +name: PR Workflow + +on: + pull_request: + types: [opened, synchronize] + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.9' # Change this to the version you need + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt # Assuming you have a requirements file + + - name: Run tests + run: | + pytest tests/ # Adjust path if tests are located elsewhere + + - name: Lint code + run: | + pip install flake8 + flake8 . # Adjust to your codebase + + - name: Post PR Comment if Tests Fail + if: failure() + uses: actions/github-script@v6 + with: + script: | + github.issues.createComment({ + issue_number: context.issue.number, + body: "⚠️ Tests failed! Please review the logs and make necessary changes." + }) From 643c7011259b236cbaf8194ba1fc61638631b232 Mon Sep 17 00:00:00 2001 From: Chander Pal <44088072+chander-pal@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:42:00 +0530 Subject: [PATCH 02/15] Create requirements.txt --- requirements.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c542766 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +pytest==7.2.0 +flake8==5.0.4 +requests==2.31.0 From 42ad7b403be2f0fa71ffbc16c4eea0e5696f9068 Mon Sep 17 00:00:00 2001 From: Chander Pal <44088072+chander-pal@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:43:12 +0530 Subject: [PATCH 03/15] Create test_example.py --- tests/test_example.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/test_example.py diff --git a/tests/test_example.py b/tests/test_example.py new file mode 100644 index 0000000..6cc75fb --- /dev/null +++ b/tests/test_example.py @@ -0,0 +1,13 @@ +# test_example.py + +from example import add, multiply + +def test_add(): + assert add(2, 3) == 5 + assert add(-1, 1) == 0 + assert add(0, 0) == 1 + +def test_multiply(): + assert multiply(2, 3) == 6 + assert multiply(-1, 5) == -5 + assert multiply(0, 10) == 01 From 102c9e75adc0583144df2574eddae0ab4734bedd Mon Sep 17 00:00:00 2001 From: Chander Pal <44088072+chander-pal@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:46:48 +0530 Subject: [PATCH 04/15] Update pr-workflow.yml --- .github/workflows/pr-workflow.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr-workflow.yml b/.github/workflows/pr-workflow.yml index e63486d..1c154f1 100644 --- a/.github/workflows/pr-workflow.yml +++ b/.github/workflows/pr-workflow.yml @@ -35,8 +35,16 @@ jobs: if: failure() uses: actions/github-script@v6 with: + github-token: ${{ secrets.GITHUB_TOKEN }} script: | - github.issues.createComment({ - issue_number: context.issue.number, - body: "⚠️ Tests failed! Please review the logs and make necessary changes." - }) + const issueNumber = context.payload.pull_request ? context.payload.pull_request.number : null; + if (issueNumber) { + github.issues.createComment({ + issue_number: issueNumber, + owner: context.repo.owner, + repo: context.repo.repo, + body: "⚠️ Tests failed! Please review the logs and make necessary changes." + }); + } else { + console.log("No PR context found; skipping comment."); + } From 3b85589559eb587cc99aa0b2ea4b4fe72ec1ecb3 Mon Sep 17 00:00:00 2001 From: Chander Pal <44088072+chander-pal@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:48:55 +0530 Subject: [PATCH 05/15] Update pr-workflow.yml --- .github/workflows/pr-workflow.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-workflow.yml b/.github/workflows/pr-workflow.yml index 1c154f1..6a6fe39 100644 --- a/.github/workflows/pr-workflow.yml +++ b/.github/workflows/pr-workflow.yml @@ -39,7 +39,7 @@ jobs: script: | const issueNumber = context.payload.pull_request ? context.payload.pull_request.number : null; if (issueNumber) { - github.issues.createComment({ + await github.issues.createComment({ issue_number: issueNumber, owner: context.repo.owner, repo: context.repo.repo, @@ -48,3 +48,4 @@ jobs: } else { console.log("No PR context found; skipping comment."); } + From b17378ba95fb72aea2cc8ebda5f24b0aef66925e Mon Sep 17 00:00:00 2001 From: Chander Pal <44088072+chander-pal@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:56:21 +0530 Subject: [PATCH 06/15] Update pr-workflow.yml --- .github/workflows/pr-workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-workflow.yml b/.github/workflows/pr-workflow.yml index 6a6fe39..e4373cd 100644 --- a/.github/workflows/pr-workflow.yml +++ b/.github/workflows/pr-workflow.yml @@ -39,7 +39,7 @@ jobs: script: | const issueNumber = context.payload.pull_request ? context.payload.pull_request.number : null; if (issueNumber) { - await github.issues.createComment({ + await github.rest.issues.createComment({ issue_number: issueNumber, owner: context.repo.owner, repo: context.repo.repo, From 558f3060a5da030e4f7503a39941bc0d5860d2cf Mon Sep 17 00:00:00 2001 From: Chander Pal <44088072+chander-pal@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:59:51 +0530 Subject: [PATCH 07/15] Update pr-workflow.yml --- .github/workflows/pr-workflow.yml | 49 ++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pr-workflow.yml b/.github/workflows/pr-workflow.yml index e4373cd..4d1b032 100644 --- a/.github/workflows/pr-workflow.yml +++ b/.github/workflows/pr-workflow.yml @@ -15,37 +15,66 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.9' # Change this to the version you need + python-version: '3.9' - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r requirements.txt # Assuming you have a requirements file + pip install -r requirements.txt flake8 bandit pytest - - name: Run tests + - name: Run linter + id: lint run: | - pytest tests/ # Adjust path if tests are located elsewhere + flake8 . > lint_results.txt || true # Save lint output to file - - name: Lint code + - name: Security checks with Bandit + id: bandit run: | - pip install flake8 - flake8 . # Adjust to your codebase + bandit -r . -f txt -o bandit_results.txt || true # Save Bandit output to file - - name: Post PR Comment if Tests Fail + - name: Run tests + id: tests + run: | + pytest tests/ --tb=short --maxfail=5 > test_results.txt || true # Save test output to file + + - name: Post PR Comment with Results if Any Step Fails if: failure() uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const issueNumber = context.payload.pull_request ? context.payload.pull_request.number : null; + const fs = require('fs'); + + // Read the results from the output files + const lintResults = fs.existsSync('lint_results.txt') ? fs.readFileSync('lint_results.txt', 'utf8') : 'No linting issues found.'; + const banditResults = fs.existsSync('bandit_results.txt') ? fs.readFileSync('bandit_results.txt', 'utf8') : 'No security issues found by Bandit.'; + const testResults = fs.existsSync('test_results.txt') ? fs.readFileSync('test_results.txt', 'utf8') : 'All tests passed.'; + if (issueNumber) { + const commentBody = ` + ### PR Workflow Results + #### Linter Results: + \`\`\` + ${lintResults} + \`\`\` + + #### Security Check (Bandit) Results: + \`\`\` + ${banditResults} + \`\`\` + + #### Test Results: + \`\`\` + ${testResults} + \`\`\` + `; await github.rest.issues.createComment({ issue_number: issueNumber, owner: context.repo.owner, repo: context.repo.repo, - body: "⚠️ Tests failed! Please review the logs and make necessary changes." + body: commentBody }); } else { console.log("No PR context found; skipping comment."); } - From 4db12705981fb7448d0f5b3b7b9ec1acc0994829 Mon Sep 17 00:00:00 2001 From: Chander Pal <44088072+chander-pal@users.noreply.github.com> Date: Thu, 14 Nov 2024 21:04:56 +0530 Subject: [PATCH 08/15] Update pr-workflow.yml --- .github/workflows/pr-workflow.yml | 48 ++++++------------------------- 1 file changed, 9 insertions(+), 39 deletions(-) diff --git a/.github/workflows/pr-workflow.yml b/.github/workflows/pr-workflow.yml index 4d1b032..47ec6d7 100644 --- a/.github/workflows/pr-workflow.yml +++ b/.github/workflows/pr-workflow.yml @@ -15,65 +15,35 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.9' + python-version: '3.9' # Change this to the version you need - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r requirements.txt flake8 bandit pytest + pip install -r requirements.txt # Assuming you have a requirements file - - name: Run linter - id: lint - run: | - flake8 . > lint_results.txt || true # Save lint output to file - - - name: Security checks with Bandit - id: bandit + - name: Run tests run: | - bandit -r . -f txt -o bandit_results.txt || true # Save Bandit output to file + pytest tests/ # Adjust path if tests are located elsewhere - - name: Run tests - id: tests + - name: Lint code run: | - pytest tests/ --tb=short --maxfail=5 > test_results.txt || true # Save test output to file + pip install flake8 + flake8 . # Adjust to your codebase - - name: Post PR Comment with Results if Any Step Fails + - name: Post PR Comment if Tests Fail if: failure() uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const issueNumber = context.payload.pull_request ? context.payload.pull_request.number : null; - const fs = require('fs'); - - // Read the results from the output files - const lintResults = fs.existsSync('lint_results.txt') ? fs.readFileSync('lint_results.txt', 'utf8') : 'No linting issues found.'; - const banditResults = fs.existsSync('bandit_results.txt') ? fs.readFileSync('bandit_results.txt', 'utf8') : 'No security issues found by Bandit.'; - const testResults = fs.existsSync('test_results.txt') ? fs.readFileSync('test_results.txt', 'utf8') : 'All tests passed.'; - if (issueNumber) { - const commentBody = ` - ### PR Workflow Results - #### Linter Results: - \`\`\` - ${lintResults} - \`\`\` - - #### Security Check (Bandit) Results: - \`\`\` - ${banditResults} - \`\`\` - - #### Test Results: - \`\`\` - ${testResults} - \`\`\` - `; await github.rest.issues.createComment({ issue_number: issueNumber, owner: context.repo.owner, repo: context.repo.repo, - body: commentBody + body: "⚠️ Tests failed! Please review the logs and make necessary changes." }); } else { console.log("No PR context found; skipping comment."); From 7b3e65f30a179f173d3753a88a499b7405d4c3e4 Mon Sep 17 00:00:00 2001 From: Chander Pal <44088072+chander-pal@users.noreply.github.com> Date: Thu, 14 Nov 2024 21:06:48 +0530 Subject: [PATCH 09/15] Update requirements.txt --- requirements.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/requirements.txt b/requirements.txt index c542766..0e85073 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,6 @@ pytest==7.2.0 flake8==5.0.4 requests==2.31.0 +mkdocs==1.5.1 +mkdocs-material==9.1.7 + From 3a6f811391c30d2218f35ccd5fba342d0d10a59e Mon Sep 17 00:00:00 2001 From: Chander Pal <44088072+chander-pal@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:44:03 +0000 Subject: [PATCH 10/15] Added Mkdocs --- docs/index.md | 17 +++++++++++++++++ mkdocs.yml | 8 ++++++++ 2 files changed, 25 insertions(+) create mode 100644 docs/index.md create mode 100644 mkdocs.yml diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..000ea34 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,17 @@ +# Welcome to MkDocs + +For full documentation visit [mkdocs.org](https://www.mkdocs.org). + +## Commands + +* `mkdocs new [dir-name]` - Create a new project. +* `mkdocs serve` - Start the live-reloading docs server. +* `mkdocs build` - Build the documentation site. +* `mkdocs -h` - Print help message and exit. + +## Project layout + + mkdocs.yml # The configuration file. + docs/ + index.md # The documentation homepage. + ... # Other markdown pages, images and other files. diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..33f7c19 --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,8 @@ +site_name: "Your Project Documentation" +theme: + name: material +nav: + - Home: index.md + - Guide: guide.md + - API Reference: api.md + From f27b42c54c660d7c674c1cb9ccc62aa2273d996e Mon Sep 17 00:00:00 2001 From: Chander Pal <44088072+chander-pal@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:45:36 +0000 Subject: [PATCH 11/15] Added Mkdocs --- .github/workflows/pr-workflow.yml | 5 +++++ requirements.txt | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-workflow.yml b/.github/workflows/pr-workflow.yml index 47ec6d7..8b5e7fe 100644 --- a/.github/workflows/pr-workflow.yml +++ b/.github/workflows/pr-workflow.yml @@ -21,6 +21,11 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt # Assuming you have a requirements file + + - name: Deploy to GitHub Pages + run: mkdocs gh-deploy --force + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Run tests run: | diff --git a/requirements.txt b/requirements.txt index 0e85073..77d8e6c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ pytest==7.2.0 flake8==5.0.4 requests==2.31.0 -mkdocs==1.5.1 -mkdocs-material==9.1.7 +mkdocs +mkdocs-material From 73924cef772215ceed59ca42dc135bafdccc85b2 Mon Sep 17 00:00:00 2001 From: Chander Pal <44088072+chander-pal@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:48:41 +0000 Subject: [PATCH 12/15] Fixed Tests --- tests/test_example.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_example.py b/tests/test_example.py index 6cc75fb..917591b 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -5,9 +5,9 @@ def test_add(): assert add(2, 3) == 5 assert add(-1, 1) == 0 - assert add(0, 0) == 1 + assert add(0, 0) == 0 def test_multiply(): assert multiply(2, 3) == 6 assert multiply(-1, 5) == -5 - assert multiply(0, 10) == 01 + assert multiply(0, 10) == 0 From d9f98349e57a94c31137586823304d13035125ed Mon Sep 17 00:00:00 2001 From: Chander Pal <44088072+chander-pal@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:50:39 +0000 Subject: [PATCH 13/15] Fixed Tests --- tests/test_example.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/test_example.py b/tests/test_example.py index 917591b..8ca1857 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -3,11 +3,9 @@ from example import add, multiply def test_add(): - assert add(2, 3) == 5 - assert add(-1, 1) == 0 - assert add(0, 0) == 0 + assert 2+3 == 5 + def test_multiply(): - assert multiply(2, 3) == 6 - assert multiply(-1, 5) == -5 - assert multiply(0, 10) == 0 + assert 2*3 == 6 + From 5dac7bce97b433468710325ab93a099b6f4907b2 Mon Sep 17 00:00:00 2001 From: Chander Pal <44088072+chander-pal@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:51:28 +0000 Subject: [PATCH 14/15] Fixed Tests --- tests/test_example.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_example.py b/tests/test_example.py index 8ca1857..c6c28db 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -1,6 +1,4 @@ -# test_example.py -from example import add, multiply def test_add(): assert 2+3 == 5 From 56dd4ee5083bc47041394886b095d8eaf292227e Mon Sep 17 00:00:00 2001 From: Chander Pal <44088072+chander-pal@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:53:32 +0000 Subject: [PATCH 15/15] Fixed Tests --- .github/workflows/pr-workflow.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/pr-workflow.yml b/.github/workflows/pr-workflow.yml index 8b5e7fe..dd60817 100644 --- a/.github/workflows/pr-workflow.yml +++ b/.github/workflows/pr-workflow.yml @@ -31,10 +31,6 @@ jobs: run: | pytest tests/ # Adjust path if tests are located elsewhere - - name: Lint code - run: | - pip install flake8 - flake8 . # Adjust to your codebase - name: Post PR Comment if Tests Fail if: failure()