Skip to content

feat: support nox and update readme #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 26, 2024
32 changes: 13 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,26 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install dependencies
run: |
pip install -r requirements-dev.txt
pip install -e .
- run: pip install -r requirements-dev.txt

- name: Run pre-commit
run: |
pre-commit run --all-files
pre-commit try-repo .
nox -s lint
nox -s test-hook

- name: Build wheel
run: python3 -m pip wheel --no-deps -w dist .
run: nox -s build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add wheel build verification

Verify that the wheel was successfully built before uploading.

-        run: nox -s build
+        run: |
+          nox -s build
+          if [ ! -f dist/*.whl ]; then
+            echo "::error::Wheel file not found in dist directory"
+            exit 1
+          fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
run: nox -s build
run: |
nox -s build
if [ ! -f dist/*.whl ]; then
echo "::error::Wheel file not found in dist directory"
exit 1
fi

- name: Upload wheel as artifact
uses: actions/upload-artifact@v4
with:
name: commit-check_wheel
path: ${{ github.workspace }}/dist/*.whl
- name: Run commit-check
run: |
python3 -m pip install dist/*.whl
commit-check -h
commit-check --message --branch --author-email
run: nox -s commit-check

- name: Collect Coverage
run: |
coverage run --source commit_check -m pytest
coverage report && coverage xml
run: nox -s coverage

- uses: codecov/codecov-action@v5.0.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand All @@ -69,6 +61,7 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.py }}
- run: pip install -r requirements-dev.txt

- name: Download wheel artifact
uses: actions/download-artifact@v4
Expand All @@ -79,20 +72,21 @@ jobs:
- name: Install test
# using a wildcard as filename on Windows requires a bash shell
shell: bash
run: python3 -m pip install dist/*.whl
run: nox -s install-wheel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Verify successful wheel installation

Add a verification step to ensure the wheel was installed correctly.

-        run: nox -s install-wheel
+        run: |
+          nox -s install-wheel
+          # Verify installation
+          python -c "import commit_check; print(commit_check.__version__)" || (echo "::error::Wheel installation verification failed" && exit 1)

Committable suggestion skipped: line range outside the PR's diff.


docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }} # get current branch name
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- run: python -m pip install . -r docs/requirements.txt
- run: pip install -r requirements-dev.txt

- name: Build docs
working-directory: docs
run: sphinx-build -E -W -b html . _build/html
run: nox -s docs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add documentation build verification

Verify that the documentation was built successfully before uploading.

-          run: nox -s docs
+          run: |
+            nox -s docs
+            if [ ! -d docs/_build/html ] || [ -z "$(ls -A docs/_build/html)" ]; then
+              echo "::error::Documentation not built successfully in docs/_build/html"
+              exit 1
+            fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
run: nox -s docs
run: |
nox -s docs
if [ ! -d docs/_build/html ] || [ -z "$(ls -A docs/_build/html)" ]; then
echo "::error::Documentation not built successfully in docs/_build/html"
exit 1
fi


- name: Save built docs as artifact
uses: actions/upload-artifact@v4
Expand Down
59 changes: 42 additions & 17 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ Commit Check
Overview
--------

**Commit Check** is a free, powerful tool that enforces commit metadata standards, including commit message, branch naming, committer name/email, and commit signoff. Fully customizable with error messages and suggested commands, it ensures compliance across teams.
**Commit Check** is a free, powerful tool that enforces commit metadata standards, including commit message, branch naming, committer name/email, commit signoff and more.

As an alternative to GitHub Enterprise `Metadata restrictions <https://docs.github.com/en/enterprise-server@3.11/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/available-rules-for-rulesets#metadata-restrictions>`_ and Bitbucket's paid puglin `Yet Another Commit Checker <https://marketplace.atlassian.com/apps/1211854/yet-another-commit-checker?tab=overview&hosting=datacenter>`_, Commit Check stands out by integrating DevOps principles and Infrastructure as Code (IaC).
Fully customizable with error messages and suggested commands, it ensures compliance across teams.

As an alternative to GitHub Enterprise `Metadata restrictions <https://docs.github.com/en/enterprise-server@3.11/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/available-rules-for-rulesets#metadata-restrictions>`_ and Bitbucket's paid plugin `Yet Another Commit Checker <https://marketplace.atlassian.com/apps/1211854/yet-another-commit-checker?tab=overview&hosting=datacenter>`_, Commit Check stands out by integrating DevOps principles and Infrastructure as Code (IaC).
Comment on lines +33 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Add pyproject.toml examples as requested in issue #181

The documentation currently only shows YAML-based configuration via .commit-check.yml. Since issue #181 specifically requests pyproject.toml examples and is part of the v0.9.x milestone, please add a section demonstrating pyproject.toml configuration options.

  • Add a new section under "Configuration" showing how to configure commit-check in pyproject.toml
  • Include common usage examples similar to those shown in .commit-check.yml

Note: This verification confirms that:

  1. The current documentation only covers YAML configuration
  2. Issue Add Examples #181 explicitly requests pyproject.toml examples
  3. This feature is planned for the v0.9.x milestone
  4. The examples are indeed missing from the documentation
🔗 Analysis chain

Add pyproject.toml configuration examples as mentioned in issue #181

While the overview changes improve clarity, the PR objectives mention adding examples for pyproject.toml configuration (issue #181). Consider adding a section demonstrating how to configure commit-check within pyproject.toml.

Would you like me to help draft the pyproject.toml configuration examples section?


The previous search was too specific. Let's broaden our search to understand:

  1. What configuration examples currently exist
  2. Verify if issue Add Examples #181 exists and its content
    This will help us validate if pyproject.toml examples are indeed missing and required.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if pyproject.toml examples exist anywhere in the documentation
rg -i "pyproject.toml" 

Length of output: 22


Script:

#!/bin/bash
# Let's check if there are any existing configuration examples in the documentation
fd -e rst -e md | xargs rg -i "configuration|config" -A 5 -B 5

# Also check if issue #181 exists and its content
gh issue view 181

Length of output: 2987


Configuration
-------------
Expand Down Expand Up @@ -70,7 +72,7 @@ Running as pre-commit hook
- repo: https://github.com/commit-check/commit-check
rev: the tag or revision
hooks: # support hooks
- id: check-message # requires hook prepare-commit-msg
- id: check-message # requires prepare-commit-msg hook
- id: check-branch
- id: check-author-name
- id: check-author-email
Expand All @@ -80,25 +82,25 @@ Running as pre-commit hook
Running as CLI
~~~~~~~~~~~~~~

Global Installation
Install globally

.. code-block:: bash

sudo pip3 install -U commit-check

User Installation
Install locally

.. code-block:: bash

pip install -U commit-check

Install from Git Repo
Install from source code

.. code-block:: bash

pip install git+https://github.com/commit-check/commit-check.git@main

Then, run ``commit-check`` from the command line. For more information, see the `docs <https://commit-check.github.io/commit-check/cli_args.html>`_.
Then, run ``commit-check --help`` from the command line. For more information, see the `docs <https://commit-check.github.io/commit-check/cli_args.html>`_.

Running as Git Hooks
~~~~~~~~~~~~~~~~~~~~
Expand All @@ -118,8 +120,8 @@ Save the script file as ``pre-push`` and make it executable:

Now, ``git push`` will trigger this hook automatically.

Example
-------
Examples
--------

Check Commit Message Failed

Expand Down Expand Up @@ -155,24 +157,47 @@ Check Branch Naming Failed

Commit rejected by Commit-Check.

(c).-.(c) (c).-.(c) (c).-.(c) (c).-.(c) (c).-.(c)
/ ._. \ / ._. \ / ._. \ / ._. \ / ._. \
__\( C )/__ __\( H )/__ __\( E )/__ __\( C )/__ __\( K )/__
(c).-.(c) (c).-.(c) (c).-.(c) (c).-.(c) (c).-.(c)
/ ._. \ / ._. \ / ._. \ / ._. \ / ._. \
__\( C )/__ __\( H )/__ __\( E )/__ __\( C )/__ __\( K )/__
(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)
|| E || || R || || R || || O || || R ||
_.' '-' '._ _.' '-' '._ _.' '-' '._ _.' '-' '._ _.' '-' '._
|| E || || R || || R || || O || || R ||
_.' '-' '._ _.' '-' '._ _.' '-' '._ _.' '-' '._ _.' '-' '._
(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)
`-´ `-´ `-´ `-´ `-´ `-´ `-´ `-´ `-´ `-´
`-´ `-´ `-´ `-´ `-´ `-´ `-´ `-´ `-´ `-´

Commit rejected.

Type branch check failed => my-test-branch
Type branch check failed => patch-1
It doesn't match regex: ^(bugfix|feature|release|hotfix|task|chore)\/.+|(master)|(main)|(HEAD)|(PR-.+)

Branches must begin with these types: bugfix/ feature/ release/ hotfix/ task/ chore/
Suggest: run command `git checkout -b type/branch_name`


Check Commit Signature Failed

.. code-block:: text

Commit rejected by Commit-Check.

(c).-.(c) (c).-.(c) (c).-.(c) (c).-.(c) (c).-.(c)
/ ._. \ / ._. \ / ._. \ / ._. \ / ._. \
__\( C )/__ __\( H )/__ __\( E )/__ __\( C )/__ __\( K )/__
(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)
|| E || || R || || R || || O || || R ||
_.' '-' '._ _.' '-' '._ _.' '-' '._ _.' '-' '._ _.' '-' '._
(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)
`-´ `-´ `-´ `-´ `-´ `-´ `-´ `-´ `-´ `-´

Commit rejected.

Type commit_signoff check failed => c92ce259ff041c91859c7fb61afdbb391e769d0f
It doesn't match regex: Signed-off-by:.*[A-Za-z0-9]\s+<.+@.+>
Signed-off-by not found in latest commit
Suggest: run command `git commit -m "conventional commit message" --signoff`



Badging your repository
-----------------------

Expand Down
25 changes: 14 additions & 11 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import glob

nox.options.reuse_existing_virtualenvs = True
nox.options.reuse_venv = True
nox.options.sessions = ["lint"]

REQUIREMENTS = {
Expand Down Expand Up @@ -42,30 +41,34 @@ def build(session):

@nox.session(name="install-wheel", requires=["build"])
def install_wheel(session):
session.run("python3", "-m", "pip", "wheel", "--no-deps", "-w", "dist", ".")
whl_file = glob.glob("dist/*.whl")
session.install(str(whl_file[0]))


# @nox.session(name="commit-check", requires=["install-wheel"])
@nox.session(name="commit-check", requires=["install-wheel"])
@nox.session(name="commit-check")
def commit_check(session):
session.run(
"commit-check",
"--message",
"--branch",
"--author-email",
)
session.install(".")
session.run("commit-check", "--message", "--branch", "--author-email")


@nox.session(requires=["install-wheel"])
@nox.session()
def coverage(session):
session.install(".")
session.run("coverage", "run", "--source", "commit_check", "-m", "pytest")
session.run("coverage", "report")
session.run("coverage", "xml")


@nox.session()
def docs(session):
session.install("-e", ".")
session.install(".")
session.install("-r", REQUIREMENTS["docs"])
session.run("sphinx-build", "-E", "-W", "-b", "html", "docs", "_build/html")


@nox.session(name="docs-live")
def docs_live(session):
session.install(".")
session.install("-r", REQUIREMENTS["docs"], "sphinx-autobuild")
session.run("sphinx-autobuild", "-b", "html", "docs", "_build/html")
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
coverage
nox
git+https://github.com/wntrblm/nox.git@main
pre-commit
pytest
pytest-mock
Loading