Skip to content
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

Refactor tool to support external settings #9

Merged
merged 10 commits into from Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions .dockerignore
@@ -1,8 +1,15 @@
.git
.github
__pycache__
.*project
.pytest_cache
.vscode
docs/
/.settings/
/tests
bin
Dockerfile
docs/
include
lib
lib64
LICENSE.txt
Makefile
README.md
README.md
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Expand Up @@ -2,6 +2,8 @@ name: Release new Docker image

on:
push:
branches:
- 'main'
tags:
- 'v*.*.*'
pull_request:
Expand Down Expand Up @@ -54,8 +56,6 @@ jobs:
- name: Test image
run: |
docker run --rm -v "${PWD}":/github/workspace ${{ env.IMAGE_NAME }}:${{ env.TEST_TAG }} check black ${{ env.TEST_PATHS }}
docker run --rm -v "${PWD}":/github/workspace ${{ env.IMAGE_NAME }}:${{ env.TEST_TAG }} check flake8 ${{ env.TEST_PATHS }}
docker run --rm -v "${PWD}":/github/workspace ${{ env.IMAGE_NAME }}:${{ env.TEST_TAG }} check isort ${{ env.TEST_PATHS }}

- name: Login to DockerHub
uses: docker/login-action@v1
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/tests.yml
@@ -0,0 +1,27 @@
name: Test codebase

on: push

jobs:

tests:
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: Install requirements
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r tests/requirements.txt

- name: Run tests
run: |
python -m pytest tests/
8 changes: 7 additions & 1 deletion .gitignore
@@ -1,3 +1,9 @@
__pycache__
.*project
.pytest_cache
.vscode
/.settings/
.*project
bin
include
lib
lib64
21 changes: 16 additions & 5 deletions Dockerfile
@@ -1,15 +1,26 @@
FROM python:3.10-slim
FROM python:3.10-slim as base
FROM base as builder

RUN pip install -U pip wheel \
&& mkdir /app /wheelhouse

COPY requirements.txt /app/
COPY src /app/src

RUN cd /app/ && pip wheel -r requirements.txt --wheel-dir=/wheelhouse

FROM base

LABEL maintainer="Plone Community <dev@plone.org>" \
org.label-schema.name="code-quality" \
org.label-schema.description="Plone code quality tool" \
org.label-schema.vendor="Plone Foundation" \
org.label-schema.docker.cmd="docker run -rm -v "${PWD}":/github/workspace plone/code-quality check black src"
ericof marked this conversation as resolved.
Show resolved Hide resolved

COPY requirements.txt pyproject.toml docker-entrypoint.py ./

RUN pip install -U pip && pip install -r requirements.txt

WORKDIR /github/workspace

ENTRYPOINT [ "/docker-entrypoint.py" ]

COPY docker-entrypoint.py /
COPY --from=builder /wheelhouse /wheelhouse
RUN pip install --force-reinstall --no-index --no-deps /wheelhouse/*
36 changes: 32 additions & 4 deletions Makefile
@@ -1,8 +1,11 @@
IMAGE_NAME=plone/code-quality
DOCKERFILE=Dockerfile
CODEBASE=docker-entrypoint.py
LINT=docker run --rm -v "${PWD}":/github/workspace "${IMAGE_NAME}:latest" check
FORMAT=docker run --rm -v "${PWD}":/github/workspace "${IMAGE_NAME}:latest" format
ifndef LOG_LEVEL
LOG_LEVEL=INFO
endif
CODEBASE=docker-entrypoint.py src/setup.py src/plone_code_analysis tests/fixtures/packages/ok tests/package tests/conftest.py
LINT=docker run -e LOG_LEVEL="${LOG_LEVEL}" --rm -v "${PWD}":/github/workspace "${IMAGE_NAME}:latest" check
FORMAT=docker run -e LOG_LEVEL="${LOG_LEVEL}" --rm -v "${PWD}":/github/workspace "${IMAGE_NAME}:latest" format
CURRENT_USER=$$(whoami)

# Add the following 'help' target to your Makefile
Expand All @@ -11,6 +14,26 @@ CURRENT_USER=$$(whoami)
help: ## This help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

bin/pip:
@echo "$(GREEN)==> Setup Virtual Env$(RESET)"
python3 -m venv .
bin/pip install -r requirements.txt

bin/pytest:
bin/pip install -r tests/requirements.txt

.PHONY: clean
clean: ## remove virtual environment
rm -fr bin include lib lib64

.PHONY: setup
setup: bin/pytest ## Create virtualenv and run pip install

.PHONY: test
test: bin/pytest ## Create virtualenv and run pip install
@echo "$(GREEN)==> Run tests $(RESET)"
bin/python -m pytest tests

.PHONY: build-image
build-image: ## Build Docker Image
@echo "Building $(IMAGE_NAME):latest"
Expand All @@ -23,8 +46,13 @@ lint: build-image ## Lint code with existing image
$(LINT) flake8 "${CODEBASE}"
$(LINT) isort "${CODEBASE}"

.PHONY: lint-all
lint-all: build-image ## Lint code with existing image using configurations from pyproject.toml
@echo "Linting ${CODEBASE} $(IMAGE_NAME):latest"
$(LINT)

.PHONY: format
format: build-image ## Format code with existing image
@echo "Formatting ${CODEBASE} $(IMAGE_NAME):latest"
$(FORMAT) "${CODEBASE}"
$(FORMAT)
sudo chown -R ${CURRENT_USER}: *