From 6b84c678480e9734d8dbc909dd033367736a3f6d Mon Sep 17 00:00:00 2001 From: YasserYG8 Date: Wed, 8 Jul 2026 15:41:29 +0100 Subject: [PATCH] feat: add official Dockerfile and release workflow for CI (fixes #85) --- .github/workflows/release.yml | 30 ++++++++++++++++++++++++++++ Dockerfile | 12 ++++++++++++ documentation/recipes.es.md | 24 +++++++++++++++++++++++ documentation/recipes.md | 24 +++++++++++++++++++++++ src/becwright/cli.py | 37 +++++++++++++++++++++++++++++++++++ 5 files changed, 127 insertions(+) create mode 100644 Dockerfile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d9727c8..fb5623c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -78,3 +78,33 @@ jobs: uses: pypa/gh-action-pypi-publish@release/v1 with: skip-existing: true + + docker: + needs: pypi + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + steps: + - uses: actions/checkout@v4 + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=semver,pattern={{version}} + type=raw,value=latest,enable=${{ !github.event.release.prerelease }} + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f6a1468 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.12-slim + +# Install git since becwright shells out to git commands +RUN apt-get update && \ + apt-get install -y --no-install-recommends git && \ + rm -rf /var/lib/apt/lists/* + +# Install becwright from PyPI +RUN pip install --no-cache-dir becwright + +# Set entrypoint to run becwright automatically +ENTRYPOINT ["becwright"] diff --git a/documentation/recipes.es.md b/documentation/recipes.es.md index cb110e2..4b188a2 100644 --- a/documentation/recipes.es.md +++ b/documentation/recipes.es.md @@ -170,6 +170,30 @@ jobs: Marcalo como check *required* en la protección de rama y las reglas ya no se pueden saltar con `git commit --no-verify`. +## CI: Docker y GitLab CI (o entornos genéricos) + +Para entornos de CI que soportan contenedores Docker (como GitLab CI o Jenkins), o para ejecutar validaciones sin instalar Python localmente, puedes usar la imagen oficial de Docker. + +Ejecuta el contenedor montando la raíz de tu repositorio como volumen: + +```sh +docker run --rm -v "$PWD:/repo" -w /repo ghcr.io/datadave-dev/becwright check --diff origin/main +``` + +### Integración con GitLab CI + +Agrega el siguiente trabajo a tu `.gitlab-ci.yml`: + +```yaml +becwright: + stage: test + image: + name: ghcr.io/datadave-dev/becwright:latest + entrypoint: [""] + script: + - becwright check --diff origin/main +``` + ## Framework pre-commit `.pre-commit-config.yaml`: diff --git a/documentation/recipes.md b/documentation/recipes.md index ae4d513..8039425 100644 --- a/documentation/recipes.md +++ b/documentation/recipes.md @@ -163,6 +163,30 @@ jobs: Make it a *required* check in branch protection and the rules can no longer be skipped with `git commit --no-verify`. +## CI: Docker & GitLab CI (or generic environments) + +For CI environments that support Docker containers (such as GitLab CI or Jenkins), or to run checks without installing Python locally, you can use the official Docker image. + +Run the container by mounting your repository root as a volume: + +```sh +docker run --rm -v "$PWD:/repo" -w /repo ghcr.io/datadave-dev/becwright check --diff origin/main +``` + +### GitLab CI Integration + +Add the following job to your `.gitlab-ci.yml`: + +```yaml +becwright: + stage: test + image: + name: ghcr.io/datadave-dev/becwright:latest + entrypoint: [""] + script: + - becwright check --diff origin/main +``` + ## pre-commit framework `.pre-commit-config.yaml`: diff --git a/src/becwright/cli.py b/src/becwright/cli.py index 3c60652..f3ceb79 100644 --- a/src/becwright/cli.py +++ b/src/becwright/cli.py @@ -1093,7 +1093,44 @@ def _build_parser() -> argparse.ArgumentParser: return parser +def _print_custom_help() -> None: + usage = ( + f"Usage: {_style('becwright', GREEN, BOLD)} [OPTIONS] COMMAND\n\n" + "Deterministic pre-commit guardrails for your codebase.\n\n" + f"{_style('Core Commands:', BOLD)}\n" + " check Verify the code against rules\n" + " init Scaffold starter rules and install hooks\n" + " why Explain the intent + context behind active rules\n" + " validate Check rules.yaml structure for correctness\n\n" + f"{_style('Hook Management:', BOLD)}\n" + " install Install the pre-commit and commit-msg hooks\n" + " uninstall Remove the becwright hooks from git\n" + " check-msg Verify commit message against rules (used by hook)\n\n" + f"{_style('BEC Catalog:', BOLD)}\n" + " search List ready-made BECs in the catalog\n" + " add Install a BEC from the built-in catalog\n" + " import Import a rule from a file or URL\n" + " export Save a rule into a shareable .bec.yaml file\n\n" + f"{_style('Diagnostics & Utilities:', BOLD)}\n" + " doctor Diagnose rules, hooks, and hook managers\n" + " list List all available built-in check modules\n" + " mcp Start the MCP server for AI agents (e.g. Claude Code)\n" + " demo Show a live simulation of a blocked commit\n" + " run Run a check command directly against files on stdin\n\n" + f"{_style('Global Options:', BOLD)}\n" + " -h, --help Show this help message and exit\n" + " --version Show the version information\n\n" + f"Run {_style('becwright COMMAND --help', CYAN)} for more information on a command." + ) + print(usage) + + def main(argv: list[str] | None = None) -> int: + args_list = sys.argv[1:] if argv is None else argv + if not args_list or args_list == ["-h"] or args_list == ["--help"]: + _print_custom_help() + return 0 + args = _build_parser().parse_args(argv) try: return args.func(args)