mirror of https://github.com/searxng/searxng.git
[mod] move functions from utils/manage_static.sh to ./manage script
The functions: - static.build.commit - static.build.commit.drop - static.build.restore are imported into the ./manage script. To avoid name collisions some variables and fucntions has been renamed by adding the prefix *static_*. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
03d5d14d98
commit
25b6309cf2
9
Makefile
9
Makefile
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
.DEFAULT_GOAL=help
|
.DEFAULT_GOAL=help
|
||||||
export MTOOLS=./manage
|
export MTOOLS=./manage
|
||||||
export MSTATIC=./utils/manage_static.sh
|
|
||||||
|
|
||||||
include utils/makefile.include
|
include utils/makefile.include
|
||||||
|
|
||||||
|
@ -60,8 +59,8 @@ test.shell:
|
||||||
$(Q)shellcheck -x -s bash \
|
$(Q)shellcheck -x -s bash \
|
||||||
utils/brand.env \
|
utils/brand.env \
|
||||||
$(MTOOLS) \
|
$(MTOOLS) \
|
||||||
$(MSTATIC) \
|
|
||||||
utils/lib.sh \
|
utils/lib.sh \
|
||||||
|
utils/lib_static.sh \
|
||||||
utils/filtron.sh \
|
utils/filtron.sh \
|
||||||
utils/searx.sh \
|
utils/searx.sh \
|
||||||
utils/morty.sh \
|
utils/morty.sh \
|
||||||
|
@ -85,6 +84,7 @@ MANAGE += pyenv pyenv.install pyenv.uninstall
|
||||||
MANAGE += pypi.upload pypi.upload.test
|
MANAGE += pypi.upload pypi.upload.test
|
||||||
MANAGE += test.yamllint test.pylint test.pep8 test.unit test.coverage test.robot test.clean
|
MANAGE += test.yamllint test.pylint test.pep8 test.unit test.coverage test.robot test.clean
|
||||||
MANAGE += themes.all themes.oscar themes.simple pygments.less
|
MANAGE += themes.all themes.oscar themes.simple pygments.less
|
||||||
|
MANAGE += static.build.commit static.build.drop static.build.restore
|
||||||
|
|
||||||
PHONY += $(MANAGE)
|
PHONY += $(MANAGE)
|
||||||
|
|
||||||
|
@ -92,11 +92,6 @@ $(MANAGE):
|
||||||
$(Q)$(MTOOLS) $@
|
$(Q)$(MTOOLS) $@
|
||||||
|
|
||||||
|
|
||||||
MANAGE_STATIC += static.build.commit.drop static.build.commit static.git.restore.staged static.git.restore
|
|
||||||
|
|
||||||
$(MANAGE_STATIC):
|
|
||||||
$(Q)$(MSTATIC) $@
|
|
||||||
|
|
||||||
# deprecated
|
# deprecated
|
||||||
|
|
||||||
PHONY += docs docs-clean docs-live docker themes
|
PHONY += docs docs-clean docs-live docker themes
|
||||||
|
|
28
manage
28
manage
|
@ -9,6 +9,9 @@ source "$(dirname "${BASH_SOURCE[0]}")/utils/lib.sh"
|
||||||
source "${REPO_ROOT}/utils/brand.env"
|
source "${REPO_ROOT}/utils/brand.env"
|
||||||
source_dot_config
|
source_dot_config
|
||||||
|
|
||||||
|
# shellcheck source=utils/lib_static.sh
|
||||||
|
source "$(dirname "${BASH_SOURCE[0]}")/utils/lib_static.sh"
|
||||||
|
|
||||||
# config
|
# config
|
||||||
|
|
||||||
PYOBJECTS="searx"
|
PYOBJECTS="searx"
|
||||||
|
@ -42,53 +45,54 @@ PYLINT_OPTIONS="-m pylint -j 0 --rcfile .pylintrc"
|
||||||
|
|
||||||
help() {
|
help() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
buildenv
|
buildenv:
|
||||||
rebuild ./utils/brand.env
|
rebuild ./utils/brand.env
|
||||||
babel.compile
|
babel.compile:
|
||||||
pybabel compile ./searx/translations
|
pybabel compile ./searx/translations
|
||||||
data.*
|
data.:
|
||||||
all : update searx/languages.py and ./data/*
|
all : update searx/languages.py and ./data/*
|
||||||
languages : update searx/data/engines_languages.json & searx/languages.py
|
languages : update searx/data/engines_languages.json & searx/languages.py
|
||||||
useragents: update searx/data/useragents.json with the most recent versions of Firefox.
|
useragents: update searx/data/useragents.json with the most recent versions of Firefox.
|
||||||
docs.*
|
docs.:
|
||||||
html : build HTML documentation
|
html : build HTML documentation
|
||||||
live : autobuild HTML documentation while editing
|
live : autobuild HTML documentation while editing
|
||||||
gh-pages : deploy on gh-pages branch
|
gh-pages : deploy on gh-pages branch
|
||||||
prebuild : build reST include files (./${DOCS_BUILD}/includes)
|
prebuild : build reST include files (./${DOCS_BUILD}/includes)
|
||||||
clean : clean documentation build
|
clean : clean documentation build
|
||||||
docker
|
docker.:
|
||||||
build : build docker image
|
build : build docker image
|
||||||
push : build and push docker image
|
push : build and push docker image
|
||||||
gecko.driver
|
gecko.driver:
|
||||||
download & install geckodriver if not already installed (required for
|
download & install geckodriver if not already installed (required for
|
||||||
robot_tests)
|
robot_tests)
|
||||||
node.*
|
node.:
|
||||||
env : download & install npm dependencies locally
|
env : download & install npm dependencies locally
|
||||||
clean : drop npm installations
|
clean : drop npm installations
|
||||||
py.*
|
py.:
|
||||||
build : Build python packages at ./${PYDIST}
|
build : Build python packages at ./${PYDIST}
|
||||||
clean : delete virtualenv and intermediate py files
|
clean : delete virtualenv and intermediate py files
|
||||||
pyenv.* :
|
pyenv.:
|
||||||
install : developer install of searx into virtualenv
|
install : developer install of searx into virtualenv
|
||||||
uninstall : uninstall developer installation
|
uninstall : uninstall developer installation
|
||||||
cmd ... : run command ... in virtualenv
|
cmd ... : run command ... in virtualenv
|
||||||
OK : test if virtualenv is OK
|
OK : test if virtualenv is OK
|
||||||
pypi.upload:
|
pypi.upload:
|
||||||
Upload python packages to PyPi (to test use pypi.upload.test)
|
Upload python packages to PyPi (to test use pypi.upload.test)
|
||||||
test.* :
|
test.:
|
||||||
pylint : lint PYLINT_FILES, searx/engines, searx & tests
|
pylint : lint PYLINT_FILES, searx/engines, searx & tests
|
||||||
pep8 : pycodestyle (pep8) for all files except PYLINT_FILES
|
pep8 : pycodestyle (pep8) for all files except PYLINT_FILES
|
||||||
unit : run unit tests
|
unit : run unit tests
|
||||||
coverage : run unit tests with coverage
|
coverage : run unit tests with coverage
|
||||||
robot : run robot test
|
robot : run robot test
|
||||||
clean : clean intermediate test stuff
|
clean : clean intermediate test stuff
|
||||||
themes.* :
|
themes.:
|
||||||
all : build all themes
|
all : build all themes
|
||||||
oscar : build oscar theme
|
oscar : build oscar theme
|
||||||
simple : build simple theme
|
simple : build simple theme
|
||||||
pygments.* :
|
pygments.:
|
||||||
less : build LESS files for pygments
|
less : build LESS files for pygments
|
||||||
EOF
|
EOF
|
||||||
|
static_help
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,124 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
|
||||||
|
STATIC_BUILD_COMMIT="[build] /static"
|
||||||
|
STATIC_BUILT_PATHS=(
|
||||||
|
searx/static/themes/oscar/css
|
||||||
|
searx/static/themes/oscar/js
|
||||||
|
searx/static/themes/oscar/src/generated/pygments-logicodev.less
|
||||||
|
searx/static/themes/oscar/src/generated/pygments-pointhi.less
|
||||||
|
searx/static/themes/simple/css
|
||||||
|
searx/static/themes/simple/js
|
||||||
|
searx/static/themes/simple/src/generated/pygments.less
|
||||||
|
)
|
||||||
|
|
||||||
|
static_help(){
|
||||||
|
cat <<EOF
|
||||||
|
static.build.: ${STATIC_BUILD_COMMIT}
|
||||||
|
commit : build & commit /static folder
|
||||||
|
drop : drop last commit if it was previously done by static.build.commit
|
||||||
|
restore : git restore of the /static folder (after themes.all)
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
is.static.build.commit() {
|
||||||
|
|
||||||
|
local commit_sha="$1"
|
||||||
|
local commit_message
|
||||||
|
local commit_files
|
||||||
|
|
||||||
|
# check commit message
|
||||||
|
commit_message=$(git show -s --format=%s "${commit_sha}")
|
||||||
|
if [ "${commit_message}" != "${STATIC_BUILD_COMMIT}" ]; then
|
||||||
|
err_msg "expecting commit message: '${STATIC_BUILD_COMMIT}'"
|
||||||
|
err_msg "commit message of ${commit_sha} is: '${commit_message}'"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check all files of the commit belongs to $STATIC_BUILT_PATHS
|
||||||
|
commit_files=$(git diff-tree --no-commit-id --name-only -r "${commit_sha}")
|
||||||
|
for i in ${STATIC_BUILT_PATHS[*]}; do
|
||||||
|
# remove files of ${STATIC_BUILT_PATHS}
|
||||||
|
commit_files=$(echo "${commit_files}" | grep -v "^${i}")
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -n "${commit_files}" ]; then
|
||||||
|
err_msg "commit ${commit_sha} contains files not a part of ${STATIC_BUILD_COMMIT}"
|
||||||
|
echo "${commit_files}" | prefix_stdout " "
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
static.build.drop() {
|
||||||
|
# drop last commit if it was made by the static.build.commit command
|
||||||
|
|
||||||
|
local last_commit_id
|
||||||
|
local branch
|
||||||
|
|
||||||
|
build_msg STATIC "drop last commit if it was previously done by static.build.commit"
|
||||||
|
|
||||||
|
# get only last (option -n1) local commit not in remotes
|
||||||
|
branch="$(git branch --show-current)"
|
||||||
|
last_commit_id="$(git log -n1 "${branch}" --pretty=format:'%h'\
|
||||||
|
--not --exclude="${branch}" --branches --remotes)"
|
||||||
|
|
||||||
|
if [ -z "${last_commit_id}" ]; then
|
||||||
|
err_msg "there are no local commits"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! is.static.build.commit "${last_commit_id}"; then
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
build_msg STATIC "drop last commit ${last_commit_id}"
|
||||||
|
git reset --hard HEAD~1
|
||||||
|
}
|
||||||
|
|
||||||
|
static.build.commit() {
|
||||||
|
# call the "static.build.drop" command, then "themes.all" then commit the
|
||||||
|
# built files ($BUILT_PATHS).
|
||||||
|
|
||||||
|
build_msg STATIC "build & commit /static files"
|
||||||
|
|
||||||
|
# check for not commited files
|
||||||
|
if [ -n "$(git diff --name-only)" ]; then
|
||||||
|
err_msg "some files are not commited:"
|
||||||
|
git diff --name-only | prefix_stdout " "
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check for staged files
|
||||||
|
if [ -n "$(git diff --name-only --cached)" ]; then
|
||||||
|
err_msg "some files are staged:"
|
||||||
|
git diff --name-only --cached | prefix_stdout " "
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# drop existing commit from previos build
|
||||||
|
static.build.drop &>/dev/null
|
||||||
|
|
||||||
|
( set -e
|
||||||
|
# build the themes
|
||||||
|
themes.all
|
||||||
|
|
||||||
|
# add build files
|
||||||
|
for built_path in "${STATIC_BUILT_PATHS[@]}"; do
|
||||||
|
git add -v "${built_path}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# check for modified files that are not staged
|
||||||
|
if [ -n "$(git diff --name-only)" ]; then
|
||||||
|
die 42 "themes.all has created files that are not in STATIC_BUILT_PATHS"
|
||||||
|
fi
|
||||||
|
git commit -m "${STATIC_BUILD_COMMIT}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
static.build.restore() {
|
||||||
|
build_msg STATIC "git-restore of the built files (/static)"
|
||||||
|
git restore --staged "${STATIC_BUILT_PATHS[@]}"
|
||||||
|
git restore --worktree "${STATIC_BUILT_PATHS[@]}"
|
||||||
|
}
|
|
@ -1,133 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
BUILD_COMMIT_MESSAGE="[build] /static"
|
|
||||||
|
|
||||||
BUILT_PATHS=(
|
|
||||||
searx/static/themes/oscar/css
|
|
||||||
searx/static/themes/oscar/js
|
|
||||||
searx/static/themes/oscar/src/generated/pygments-logicodev.less
|
|
||||||
searx/static/themes/oscar/src/generated/pygments-pointhi.less
|
|
||||||
searx/static/themes/simple/css
|
|
||||||
searx/static/themes/simple/js
|
|
||||||
searx/static/themes/simple/src/generated/pygments.less
|
|
||||||
)
|
|
||||||
|
|
||||||
is.build.commit() {
|
|
||||||
local commit_sha="$1"
|
|
||||||
local commit_message
|
|
||||||
local commit_files
|
|
||||||
|
|
||||||
# check commit message
|
|
||||||
commit_message=$(git show -s --format=%s "${commit_sha}")
|
|
||||||
if [ "${commit_message}" != "${BUILD_COMMIT_MESSAGE}" ]; then
|
|
||||||
echo "Commit message of ${commit_sha} is '${commit_message}'"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# check all files of the commit belongs to $BUILT_PATHS
|
|
||||||
commit_files=$(git diff-tree --no-commit-id --name-only -r "${commit_sha}")
|
|
||||||
for i in ${BUILT_PATHS[*]}; do
|
|
||||||
# remove files of ${BUILT_PATHS}
|
|
||||||
commit_files=$(echo "${commit_files}" | grep -v "^${i}")
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -n "${commit_files}" ]; then
|
|
||||||
echo "Commit $1 contains files that were not build: ${commit_files}"
|
|
||||||
return 2
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static.build.commit.drop() {
|
|
||||||
local last_commit_id
|
|
||||||
local branch
|
|
||||||
|
|
||||||
# get only last (option -n1) local commit not in remotes
|
|
||||||
branch="$(git branch --show-current)"
|
|
||||||
last_commit_id="$(git log -n1 "${branch}" --pretty=format:'%h'\
|
|
||||||
--not --exclude="${branch}" --branches --remotes)"
|
|
||||||
|
|
||||||
if [ -z "${last_commit_id}" ]; then
|
|
||||||
echo "Empty branch"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! is.build.commit "${last_commit_id}"; then
|
|
||||||
return $?
|
|
||||||
fi
|
|
||||||
echo "Drop last commit ${last_commit_id}"
|
|
||||||
git reset --hard HEAD~1
|
|
||||||
}
|
|
||||||
|
|
||||||
static.build.commit() {
|
|
||||||
local staged_files
|
|
||||||
|
|
||||||
# check for not commited files
|
|
||||||
if [ -n "$(git diff --name-only)" ]; then
|
|
||||||
echo "Some files are not commited:"
|
|
||||||
echo "${NOT_COMMITED_FILES}"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
staged_files=$(git diff --name-only --cached)
|
|
||||||
|
|
||||||
# check for staged files
|
|
||||||
if [ -n "${staged_files}" ]; then
|
|
||||||
echo "Some files are staged:"
|
|
||||||
echo "${staged_files}"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# drop existing commit
|
|
||||||
if static.commit.drop; then
|
|
||||||
return $?
|
|
||||||
fi
|
|
||||||
|
|
||||||
(
|
|
||||||
set -e
|
|
||||||
# build the themes
|
|
||||||
make themes.all
|
|
||||||
|
|
||||||
# add build files
|
|
||||||
for built_path in "${BUILT_PATHS[@]}"; do
|
|
||||||
git add -v "${built_path}"
|
|
||||||
done
|
|
||||||
|
|
||||||
# check for modified files that are not staged
|
|
||||||
if [ -n "$(git diff --name-only)" ]; then
|
|
||||||
echo "make themes.all has created files that are not in BUILT_PATHS"
|
|
||||||
return 2
|
|
||||||
fi
|
|
||||||
git commit -m "${BUILD_COMMIT_MESSAGE}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
main() {
|
|
||||||
case $1 in
|
|
||||||
static.build.commit.drop)
|
|
||||||
# drop last commit if it was made by the "commit" command
|
|
||||||
static.build.commit.drop
|
|
||||||
;;
|
|
||||||
static.build.commit)
|
|
||||||
# call the "static.build.commit.drop" command,
|
|
||||||
# then "make themes.all"
|
|
||||||
# then commit the built files ($BUILT_PATHS).
|
|
||||||
static.build.commit
|
|
||||||
;;
|
|
||||||
static.git.restore.staged)
|
|
||||||
# after "git add ."
|
|
||||||
# remove the built files
|
|
||||||
# so only the source are commited
|
|
||||||
git restore --staged "${BUILT_PATHS[@]}"
|
|
||||||
;;
|
|
||||||
static.git.restore)
|
|
||||||
# "git restore" of the built files.
|
|
||||||
git restore --worktree --staged "${BUILT_PATHS[@]}"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
main "$@"
|
|
Loading…
Reference in New Issue