From bb32dff98b68a1dfb18e638dd9fffd8f4cd8c421 Mon Sep 17 00:00:00 2001 From: siddhant Date: Tue, 7 Jul 2026 17:39:41 +0530 Subject: [PATCH 1/4] ci setup --- .github/workflows/ci.yml | 43 ++++++++++++++++++++++++++++++++++++++++ requirements-dev.txt | 3 +++ scripts/setup-hooks.sh | 38 +++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 requirements-dev.txt create mode 100644 scripts/setup-hooks.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2f16c58 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,43 @@ +name: Continuous Integration + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: "pip" + + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements-dev.txt + + - name: Run Tests with Coverage + run: | + pytest tests/ -v --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=minichain | tee pytest-coverage.txt + + - name: Pytest coverage comment + if: github.event_name == 'pull_request' + uses: MishaKav/pytest-coverage-comment@main + with: + pytest-coverage-path: ./pytest-coverage.txt + junitxml-path: ./pytest.xml diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..1900428 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,3 @@ +pytest>=7.0.0 +pytest-asyncio>=0.21.0 +pytest-cov>=4.0.0 diff --git a/scripts/setup-hooks.sh b/scripts/setup-hooks.sh new file mode 100644 index 0000000..f8289aa --- /dev/null +++ b/scripts/setup-hooks.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +# Ensure we are in the root directory +cd "$(dirname "$0")/.." + +HOOK_FILE=".git/hooks/pre-commit" + +cat << 'EOF' > "$HOOK_FILE" +#!/bin/sh +echo "----------------------------------------" +echo "Running pytest locally before commit..." +echo "----------------------------------------" + +# Run pytest using the python environment available +python -m pytest tests/ -v + +# Capture the exit code of pytest +EXIT_CODE=$? + +if [ $EXIT_CODE -ne 0 ]; then + echo "" + echo "⚠️ WARNING: Tests failed!" + echo "The commit will proceed, but please fix the tests ASAP." + echo "----------------------------------------" +else + echo "" + echo "✅ Tests passed! Commit proceeding." + echo "----------------------------------------" +fi + +# Always exit 0 to ensure the commit is never blocked +exit 0 +EOF + +# Make the hook executable +chmod +x "$HOOK_FILE" + +echo "✅ Pre-commit hook successfully installed at $HOOK_FILE" From 7585ad37f08bbb9bf0cc5e9c80cafe11a2f1a275 Mon Sep 17 00:00:00 2001 From: siddhant Date: Tue, 7 Jul 2026 19:30:44 +0530 Subject: [PATCH 2/4] fix:hooks --- scripts/setup-hooks.sh | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 scripts/setup-hooks.sh diff --git a/scripts/setup-hooks.sh b/scripts/setup-hooks.sh deleted file mode 100644 index f8289aa..0000000 --- a/scripts/setup-hooks.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh - -# Ensure we are in the root directory -cd "$(dirname "$0")/.." - -HOOK_FILE=".git/hooks/pre-commit" - -cat << 'EOF' > "$HOOK_FILE" -#!/bin/sh -echo "----------------------------------------" -echo "Running pytest locally before commit..." -echo "----------------------------------------" - -# Run pytest using the python environment available -python -m pytest tests/ -v - -# Capture the exit code of pytest -EXIT_CODE=$? - -if [ $EXIT_CODE -ne 0 ]; then - echo "" - echo "⚠️ WARNING: Tests failed!" - echo "The commit will proceed, but please fix the tests ASAP." - echo "----------------------------------------" -else - echo "" - echo "✅ Tests passed! Commit proceeding." - echo "----------------------------------------" -fi - -# Always exit 0 to ensure the commit is never blocked -exit 0 -EOF - -# Make the hook executable -chmod +x "$HOOK_FILE" - -echo "✅ Pre-commit hook successfully installed at $HOOK_FILE" From 666fc5a5f83eb4261ca805622eb527a855c9b1d4 Mon Sep 17 00:00:00 2001 From: siddhant Date: Tue, 7 Jul 2026 19:52:57 +0530 Subject: [PATCH 3/4] add badge to readme --- .github/workflows/ci.yml | 19 +++++++++++++++++-- README.md | 3 ++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f16c58..81ee014 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,8 +36,23 @@ jobs: pytest tests/ -v --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=minichain | tee pytest-coverage.txt - name: Pytest coverage comment - if: github.event_name == 'pull_request' - uses: MishaKav/pytest-coverage-comment@main + if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' + id: coverageComment + uses: MishaKav/pytest-coverage-comment@v1 with: pytest-coverage-path: ./pytest-coverage.txt junitxml-path: ./pytest.xml + + - name: Update README with Coverage Html + if: github.ref == 'refs/heads/main' + run: | + sed -i '//,//c\\n\${{ steps.coverageComment.outputs.coverageHtml }}\n' ./README.md + + - name: Commit & Push changes to README + if: github.ref == 'refs/heads/main' + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git add README.md + git commit -m "docs: auto-update coverage badge in README" || echo "No changes to commit" + git push diff --git a/README.md b/README.md index 8e078a9..f39fa19 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ [![Static Badge](https://img.shields.io/badge/Stability_Nexus-MiniChain-228B22?style=for-the-badge&labelColor=FFC517)](https://stability.nexus/) - + + From 371da8847d9b732c1eb1efa471bad9c4a60c806a Mon Sep 17 00:00:00 2001 From: siddhant Date: Tue, 7 Jul 2026 22:42:57 +0530 Subject: [PATCH 4/4] fix badge workflow --- .github/workflows/ci.yml | 58 ------------------- .github/workflows/pr-checks.yml | 41 +++++++++++++ .github/workflows/update-badge.yml | 50 ++++++++++++++++ requirements-dev.txt => requirements-test.txt | 0 4 files changed, 91 insertions(+), 58 deletions(-) delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/pr-checks.yml create mode 100644 .github/workflows/update-badge.yml rename requirements-dev.txt => requirements-test.txt (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 81ee014..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: Continuous Integration - -on: - pull_request: - branches: - - main - push: - branches: - - main - -jobs: - test: - runs-on: ubuntu-latest - permissions: - contents: read - pull-requests: write - - steps: - - name: Checkout Code - uses: actions/checkout@v4 - - - name: Setup Python - uses: actions/setup-python@v5 - with: - python-version: "3.11" - cache: "pip" - - - name: Install Dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install -r requirements-dev.txt - - - name: Run Tests with Coverage - run: | - pytest tests/ -v --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=minichain | tee pytest-coverage.txt - - - name: Pytest coverage comment - if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' - id: coverageComment - uses: MishaKav/pytest-coverage-comment@v1 - with: - pytest-coverage-path: ./pytest-coverage.txt - junitxml-path: ./pytest.xml - - - name: Update README with Coverage Html - if: github.ref == 'refs/heads/main' - run: | - sed -i '//,//c\\n\${{ steps.coverageComment.outputs.coverageHtml }}\n' ./README.md - - - name: Commit & Push changes to README - if: github.ref == 'refs/heads/main' - run: | - git config --global user.name 'github-actions[bot]' - git config --global user.email 'github-actions[bot]@users.noreply.github.com' - git add README.md - git commit -m "docs: auto-update coverage badge in README" || echo "No changes to commit" - git push diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml new file mode 100644 index 0000000..6ab2f63 --- /dev/null +++ b/.github/workflows/pr-checks.yml @@ -0,0 +1,41 @@ +name: PR Tests & Coverage + +on: + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: "pip" + + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements-test.txt + + - name: Run Tests with Coverage + run: | + pytest tests/ -v --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=minichain | tee pytest-coverage.txt + + - name: Pytest coverage comment + uses: MishaKav/pytest-coverage-comment@v1 + with: + pytest-coverage-path: ./pytest-coverage.txt + junitxml-path: ./pytest.xml diff --git a/.github/workflows/update-badge.yml b/.github/workflows/update-badge.yml new file mode 100644 index 0000000..d032db6 --- /dev/null +++ b/.github/workflows/update-badge.yml @@ -0,0 +1,50 @@ +name: Update Coverage Badge +on: + push: + branches: [main] + +permissions: + contents: write + +jobs: + update-badge: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + fetch-depth: 0 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: "pip" + + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements-test.txt + + - name: Run tests + run: | + pytest tests/ -v --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=minichain | tee pytest-coverage.txt + + - name: Coverage comment + id: coverage + uses: MishaKav/pytest-coverage-comment@v1 + with: + pytest-coverage-path: ./pytest-coverage.txt + junitxml-path: ./pytest.xml + hide-comment: true + + - name: Update README + run: | + sed -i '//,//c\\n\${{ steps.coverage.outputs.coverageHtml }}\n' ./README.md + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: 'docs: update coverage badge' + file_pattern: README.md diff --git a/requirements-dev.txt b/requirements-test.txt similarity index 100% rename from requirements-dev.txt rename to requirements-test.txt