Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
550 changes: 0 additions & 550 deletions .pylintrc

This file was deleted.

18 changes: 14 additions & 4 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,33 @@ USER root
ARG TARGETARCH=amd64
ARG GO_VERSION=1.24.3

ENV PATH="/usr/local/go/bin:$PATH"

# The Go project uses "arm64" instead of "aarch64" in filenames
RUN dnf install -y tar gzip gpgme gpgme-devel pkgconfig jq && \
RUN dnf install -y tar gzip git make gpgme gpgme-devel pkgconfig jq && \
ARCH=$(case "${TARGETARCH:-amd64}" in aarch64) echo "arm64" ;; amd64) echo "amd64" ;; *) echo "${TARGETARCH:-amd64}" ;; esac) && \
curl -Ls "https://go.dev/dl/go${GO_VERSION}.linux-${ARCH}.tar.gz" | tar -C /usr/local -xz && \
python -m pip install --no-cache-dir uv && \
dnf clean all && rm -rf /var/cache/dnf /tmp/*

ENV PATH="/usr/local/go/bin:$PATH"
FROM base AS unittests

WORKDIR /src
COPY . .
RUN uv sync --locked --extra dev
ENV PATH="/src/.venv/bin:$PATH"
CMD ["make", "unittests"]

FROM base AS runtime

WORKDIR /src
COPY . .
RUN python -m pip install .

WORKDIR /working
RUN rm -rf /src
RUN chown default .
RUN chown 1001:0 .
RUN chmod 0777 .

USER default
USER 1001
ENTRYPOINT [ "/opt/app-root/bin/rebasebot" ]
85 changes: 70 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,80 @@
PYTHON=python3
IS_CI := false
ifeq ($(VIRTUAL_ENV),/opt/app-root)
IS_CI := true
endif

.PHONY: deps
deps:
$(PYTHON) -m pip install --upgrade pip
$(PYTHON) -m pip install --upgrade -r requirements-hacking.txt
SRC_DIRS = rebasebot tests
RUFF_ARGS =
ifeq ($(IS_CI),true)
# CI checkouts under /go may be read-only, so avoid .ruff_cache writes there.
RUFF_ARGS += --no-cache
endif

CONTAINER_ENGINE ?= podman
CONTAINERFILE ?= Containerfile
CONTAINER_BUILD_ARGS ?=
CONTAINER_RUN_ARGS ?=
CONTAINERFILE_UNITTEST_IMAGE ?= rebasebot-unittests:latest
CI_BUILD_ROOT_CONTAINERFILE ?= hack/ci-build-root.Containerfile
CI_SRC_CONTAINERFILE ?= hack/ci-src.Containerfile
CI_BUILD_ROOT_IMAGE ?= rebasebot-ci-root:latest
CI_SRC_IMAGE ?= rebasebot-ci-src:latest
CI_REPO_PATH ?= /go/src/github.com/openshift-eng/rebasebot

.PHONY: unittests
unittests:
unittests: ## Run unit & integration tests
hack/tests.sh

.PHONY: container-unittests
container-unittests: ## Run unit tests in a local image that mimics Prow build_root/src
$(CONTAINER_ENGINE) build $(CONTAINER_BUILD_ARGS) -f $(CI_BUILD_ROOT_CONTAINERFILE) -t $(CI_BUILD_ROOT_IMAGE) .
$(CONTAINER_ENGINE) build $(CONTAINER_BUILD_ARGS) -f $(CI_SRC_CONTAINERFILE) --build-arg BUILD_ROOT_IMAGE=$(CI_BUILD_ROOT_IMAGE) --build-arg REPO_PATH=$(CI_REPO_PATH) -t $(CI_SRC_IMAGE) .
$(CONTAINER_ENGINE) run --rm $(CONTAINER_RUN_ARGS) $(CI_SRC_IMAGE)

.PHONY: containerfile-unittests
containerfile-unittests: ## Run unit tests inside the repo Containerfile test stage
$(CONTAINER_ENGINE) build $(CONTAINER_BUILD_ARGS) -f $(CONTAINERFILE) --target unittests -t $(CONTAINERFILE_UNITTEST_IMAGE) .
$(CONTAINER_ENGINE) run --rm $(CONTAINER_RUN_ARGS) $(CONTAINERFILE_UNITTEST_IMAGE)

.PHONY: lint
lint:
$(PYTHON) -m flake8 --max-line-length=120 rebasebot tests
$(PYTHON) -m pylint rebasebot tests
$(PYTHON) -m mypy rebasebot tests --no-strict-optional --ignore-missing-imports
lint: ## Run lint and format in check mode
ruff check $(RUFF_ARGS) $(SRC_DIRS)
ruff format $(RUFF_ARGS) --check $(SRC_DIRS)

.PHONY: venv
venv:
$(PYTHON) -m venv env
.PHONY: lint-fix
lint-fix: ## Fix fixable lint issues and format code
ruff format $(RUFF_ARGS) $(SRC_DIRS)
ruff check $(RUFF_ARGS) --fix $(SRC_DIRS)

install:
.PHONY: install
install: ## Install into your user python environment.
# On macOS with Homebrew Python, you may get "externally-managed-environment" error.
# Use `pipx install .` instead, or install within a virtual environment (`make venv`).
$(PYTHON) -m pip install --user .
python -m pip install --user .

.PHONY: build
build: ## Create build tarball
uv build

.PHONY: help
help: ## Display this help screen
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

.PHONY: clean
clean:
rm -r dist/ build/ .pytest_cache/ .mypy_cache rebasebot.egg-info .coverage

.venv: ## Create venv
ifeq ($(IS_CI),false)
uv venv
endif

# Install dependencies into venv
.PHONY: deps
deps: .venv
ifeq ($(IS_CI),false)
uv sync --locked --extra dev
else
# In CI we already are inside a venv, and the source checkout under /go may be read-only.
uv sync --active --locked --extra dev --no-install-project
endif
19 changes: 19 additions & 0 deletions hack/ci-build-root.Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM registry.access.redhat.com/ubi9/python-312

USER root

ENV GO_VERSION=1.24.3
ENV PATH="/usr/local/go/bin:$PATH"

RUN dnf install -y tar gzip git make && \
curl -Ls https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz | \
tar -C /usr/local -zxvf - go/ && \
python -m pip install uv

# Prow expects to be able to check out a repo under /go.
RUN mkdir -p /go && \
chown 1001:1001 /go && \
chmod 755 /go

WORKDIR /go
USER 1001:1001
20 changes: 20 additions & 0 deletions hack/ci-src.Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ARG BUILD_ROOT_IMAGE=rebasebot-ci-root:latest
FROM ${BUILD_ROOT_IMAGE}

USER root

ARG REPO_PATH=/go/src/github.com/openshift-eng/rebasebot
ARG ARTIFACT_DIR=/tmp/artifacts

# Mimic ci-operator's src image layout and keep the checkout non-writable for the test user.
COPY . ${REPO_PATH}
RUN chmod -R a+rX ${REPO_PATH} && \
mkdir -p ${ARTIFACT_DIR} && \
chown 1001:1001 ${ARTIFACT_DIR}

WORKDIR ${REPO_PATH}
ENV OPENSHIFT_CI=true
ENV ARTIFACT_DIR=${ARTIFACT_DIR}

USER 1001:1001
CMD ["bash", "-lc", "make deps && make unittests"]
19 changes: 0 additions & 19 deletions hack/configure-hooks.sh

This file was deleted.

39 changes: 0 additions & 39 deletions hack/lint

This file was deleted.

3 changes: 2 additions & 1 deletion hack/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ if [ "$OPENSHIFT_CI" == "true" ] && [ -n "$ARTIFACT_DIR" ] && [ -d "$ARTIFACT_DI
# point gopath to /tmp since go mod and go tidy is using during tests
export GOPATH=/tmp/temp_gopath

PYTEST_ARGS="${PYTEST_ARGS} --cov-report=term --cov-report=html:${ARTIFACT_DIR}/cov-report --junitxml=${ARTIFACT_DIR}/junit_rebasebot_tests.xml"
# Disable pytest's cache plugin because CI checkouts under /go may be read-only.
PYTEST_ARGS="${PYTEST_ARGS} -p no:cacheprovider --cov-report=term --cov-report=html:${ARTIFACT_DIR}/cov-report --junitxml=${ARTIFACT_DIR}/junit_rebasebot_tests.xml"
fi

set -x
Expand Down
6 changes: 6 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def main():
print("Hello from rebasebot!")


if __name__ == "__main__":
main()
75 changes: 71 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,73 @@
[build-system]
requires = [
"setuptools>=42",
"wheel"
]
requires = ["setuptools==82.0.1", "wheel==0.46.3"]
build-backend = "setuptools.build_meta"

[project]
name = "rebasebot"
version = "0.0.1"
description = "A tool to sync downstream repositories with their upstream"
readme = "README.md"
requires-python = ">=3.11"

dependencies = [
"github3-py==4.0.1",
"gitpython==3.1.46",
]

[project.optional-dependencies]
dev = [
"pytest==9.0.3",
"pytest-cov==7.1.0",
"ruff==0.15.10",
]

[project.scripts]
rebasebot = "rebasebot.cli:main"

[tool.setuptools.packages.find]
where = ["."]

[tool.setuptools.package-data]
rebasebot = ["builtin-hooks/**"]

[tool.ruff]
line-length = 120

[tool.ruff.lint]
ignore = [
"PLR0912", # too many branches
"PLR0913", # too many arguments
"PLR0915", # too many statements
"PLR0911", # too many return statements
# Enabling these rules would require significant refactoring
]

select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes - undefined names, unused imports
"I", # isort - import sorting
"B", # flake8-bugbear - common bugs and design problems
"C4", # flake8-comprehensions - better list/set/dict comprehensions
"UP", # pyupgrade - upgrade syntax for newer Python versions
"PL", # pylint - static analysis rules
#"D", # pydocstyle - docstring conventions
#"N", # pep8-naming - naming conventions
#"RET", # flake8-return - return statement patterns
#"SIM", # flake8-simplify - code simplification
#"PTH", # flake8-use-pathlib - prefer pathlib over os.path
# TODO Enable the currently disabled rules
]

[tool.ruff.lint.per-file-ignores]
"tests/**/*.py" = ["PLR2004", "D"] # allow magic values, disable docstring checks in tests

[tool.ruff.lint.pep8-naming]
ignore-names = ["i", "j", "k", "ex", "Run", "_"] # allow common single-letter variable names

[tool.ruff.format]
quote-style = "double"
indent-style = "space"

[tool.ruff.lint.isort]
known-first-party = ["rebasebot"] # treat rebasebot as first-party for import sorting
Loading