mirror of
https://github.com/ansible/awx.git
synced 2026-05-01 14:45:29 -02:30
Fix version worktree (#16431)
* git worktree friendly precomit install * worktrees don't have a .git directory. Before, docker-compose would trigger pre-commit install and fail. * make docker-compose work in git worktree * AWX tries to discover the version via info stored in .git/ dir. setuptools-scm is capable of finding the .git/ dir, starting from a worktree, but is unable because only the worktree is mapped into the container, not the .git/ dir itself. Thus, we have to detect and pass the version into the container from outside. That is why this change landed in the Makefile.
This commit is contained in:
@@ -103,6 +103,12 @@ When necessary, remove any AWX containers and images by running the following:
|
|||||||
|
|
||||||
### Pre commit hooks
|
### Pre commit hooks
|
||||||
|
|
||||||
|
Install the pre-commit hook before contributing:
|
||||||
|
|
||||||
|
```
|
||||||
|
make pre-commit
|
||||||
|
```
|
||||||
|
|
||||||
When you attempt to perform a `git commit` there will be a pre-commit hook that gets run before the commit is allowed to your local repository. For example, python's [black](https://pypi.org/project/black/) will be run to test the formatting of any python files.
|
When you attempt to perform a `git commit` there will be a pre-commit hook that gets run before the commit is allowed to your local repository. For example, python's [black](https://pypi.org/project/black/) will be run to test the formatting of any python files.
|
||||||
|
|
||||||
While you can use environment variables to skip the pre-commit hooks GitHub will run similar tests and prevent merging of PRs if the tests do not pass.
|
While you can use environment variables to skip the pre-commit hooks GitHub will run similar tests and prevent merging of PRs if the tests do not pass.
|
||||||
|
|||||||
19
Makefile
19
Makefile
@@ -10,6 +10,7 @@ KIND_BIN ?= $(shell which kind)
|
|||||||
CHROMIUM_BIN=/tmp/chrome-linux/chrome
|
CHROMIUM_BIN=/tmp/chrome-linux/chrome
|
||||||
GIT_REPO_NAME ?= $(shell basename `git rev-parse --show-toplevel`)
|
GIT_REPO_NAME ?= $(shell basename `git rev-parse --show-toplevel`)
|
||||||
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
|
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
|
||||||
|
GIT_IS_WORKTREE := $(shell test -f .git && echo yes)
|
||||||
MANAGEMENT_COMMAND ?= awx-manage
|
MANAGEMENT_COMMAND ?= awx-manage
|
||||||
VERSION ?= $(shell $(PYTHON) tools/scripts/scm_version.py 2> /dev/null)
|
VERSION ?= $(shell $(PYTHON) tools/scripts/scm_version.py 2> /dev/null)
|
||||||
|
|
||||||
@@ -112,6 +113,9 @@ AWX_USER ?= admin
|
|||||||
AWX_PASSWORD ?= $$(awk -F"'" '/^admin_password:/{print $$2}' tools/docker-compose/_sources/secrets/admin_password.yml 2>/dev/null || echo "admin")
|
AWX_PASSWORD ?= $$(awk -F"'" '/^admin_password:/{print $$2}' tools/docker-compose/_sources/secrets/admin_password.yml 2>/dev/null || echo "admin")
|
||||||
AWX_VERIFY_SSL ?= false
|
AWX_VERIFY_SSL ?= false
|
||||||
|
|
||||||
|
# For git worktree to find the referenced git dir
|
||||||
|
GIT_COMMON_DIR := $(shell git rev-parse --git-common-dir 2>/dev/null || echo .git)
|
||||||
|
|
||||||
.PHONY: awx-link clean clean-tmp clean-venv requirements requirements_dev \
|
.PHONY: awx-link clean clean-tmp clean-venv requirements requirements_dev \
|
||||||
update_requirements upgrade_requirements update_requirements_dev \
|
update_requirements upgrade_requirements update_requirements_dev \
|
||||||
docker_update_requirements docker_upgrade_requirements docker_update_requirements_dev \
|
docker_update_requirements docker_upgrade_requirements docker_update_requirements_dev \
|
||||||
@@ -119,7 +123,7 @@ AWX_VERIFY_SSL ?= false
|
|||||||
receiver test test_unit test_coverage coverage_html \
|
receiver test test_unit test_coverage coverage_html \
|
||||||
sdist \
|
sdist \
|
||||||
VERSION PYTHON_VERSION docker-compose-sources \
|
VERSION PYTHON_VERSION docker-compose-sources \
|
||||||
.git/hooks/pre-commit
|
pre-commit
|
||||||
|
|
||||||
clean-tmp:
|
clean-tmp:
|
||||||
rm -rf tmp/
|
rm -rf tmp/
|
||||||
@@ -348,11 +352,10 @@ black: reports
|
|||||||
@command -v black >/dev/null 2>&1 || { echo "could not find black on your PATH, you may need to \`pip install black\`, or set AWX_IGNORE_BLACK=1" && exit 1; }
|
@command -v black >/dev/null 2>&1 || { echo "could not find black on your PATH, you may need to \`pip install black\`, or set AWX_IGNORE_BLACK=1" && exit 1; }
|
||||||
@(set -o pipefail && $@ $(BLACK_ARGS) awx awxkit awx_collection | tee reports/$@.report)
|
@(set -o pipefail && $@ $(BLACK_ARGS) awx awxkit awx_collection | tee reports/$@.report)
|
||||||
|
|
||||||
.git/hooks/pre-commit:
|
$(GIT_COMMON_DIR)/hooks/pre-commit:
|
||||||
@echo "if [ -x pre-commit.sh ]; then" > .git/hooks/pre-commit
|
ln -sf ../../pre-commit.sh $(GIT_COMMON_DIR)/hooks/pre-commit
|
||||||
@echo " ./pre-commit.sh;" >> .git/hooks/pre-commit
|
|
||||||
@echo "fi" >> .git/hooks/pre-commit
|
pre-commit: $(GIT_COMMON_DIR)/hooks/pre-commit
|
||||||
@chmod +x .git/hooks/pre-commit
|
|
||||||
|
|
||||||
genschema: awx-link reports
|
genschema: awx-link reports
|
||||||
@if [ "$(VENV_BASE)" ]; then \
|
@if [ "$(VENV_BASE)" ]; then \
|
||||||
@@ -527,7 +530,7 @@ ifneq ($(ADMIN_PASSWORD),)
|
|||||||
EXTRA_SOURCES_ANSIBLE_OPTS := -e admin_password=$(ADMIN_PASSWORD) $(EXTRA_SOURCES_ANSIBLE_OPTS)
|
EXTRA_SOURCES_ANSIBLE_OPTS := -e admin_password=$(ADMIN_PASSWORD) $(EXTRA_SOURCES_ANSIBLE_OPTS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
docker-compose-sources: .git/hooks/pre-commit
|
docker-compose-sources:
|
||||||
@if [ $(MINIKUBE_CONTAINER_GROUP) = true ]; then\
|
@if [ $(MINIKUBE_CONTAINER_GROUP) = true ]; then\
|
||||||
$(ANSIBLE_PLAYBOOK) -i tools/docker-compose/inventory -e minikube_setup=$(MINIKUBE_SETUP) tools/docker-compose-minikube/deploy.yml; \
|
$(ANSIBLE_PLAYBOOK) -i tools/docker-compose/inventory -e minikube_setup=$(MINIKUBE_SETUP) tools/docker-compose-minikube/deploy.yml; \
|
||||||
fi;
|
fi;
|
||||||
@@ -559,7 +562,7 @@ docker-compose: awx/projects docker-compose-sources
|
|||||||
$(MAKE) docker-compose-up
|
$(MAKE) docker-compose-up
|
||||||
|
|
||||||
docker-compose-up:
|
docker-compose-up:
|
||||||
$(DOCKER_COMPOSE) -f tools/docker-compose/_sources/docker-compose.yml $(COMPOSE_OPTS) up $(COMPOSE_UP_OPTS) --remove-orphans
|
$(if $(GIT_IS_WORKTREE),SETUPTOOLS_SCM_PRETEND_VERSION="$(VERSION)") $(DOCKER_COMPOSE) -f tools/docker-compose/_sources/docker-compose.yml $(COMPOSE_OPTS) up $(COMPOSE_UP_OPTS) --remove-orphans
|
||||||
|
|
||||||
docker-compose-down:
|
docker-compose-down:
|
||||||
$(DOCKER_COMPOSE) -f tools/docker-compose/_sources/docker-compose.yml $(COMPOSE_OPTS) down --remove-orphans
|
$(DOCKER_COMPOSE) -f tools/docker-compose/_sources/docker-compose.yml $(COMPOSE_OPTS) down --remove-orphans
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ services:
|
|||||||
DJANGO_SUPERUSER_PASSWORD: {{ admin_password }}
|
DJANGO_SUPERUSER_PASSWORD: {{ admin_password }}
|
||||||
UWSGI_MOUNT_PATH: {{ ingress_path }}
|
UWSGI_MOUNT_PATH: {{ ingress_path }}
|
||||||
DJANGO_COLORS: "${DJANGO_COLORS:-}"
|
DJANGO_COLORS: "${DJANGO_COLORS:-}"
|
||||||
|
SETUPTOOLS_SCM_PRETEND_VERSION: "${SETUPTOOLS_SCM_PRETEND_VERSION:-}"
|
||||||
{% if loop.index == 1 %}
|
{% if loop.index == 1 %}
|
||||||
RUN_MIGRATIONS: 1
|
RUN_MIGRATIONS: 1
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user