2021-06-23 10:48:31 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2021-06-24 13:15:34 +00:00
|
|
|
BUILD_COMMIT_MESSAGE="[build] /static"
|
2021-06-23 10:48:31 +00:00
|
|
|
|
|
|
|
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() {
|
2021-06-24 13:15:34 +00:00
|
|
|
local commit_sha="$1"
|
|
|
|
local commit_message
|
|
|
|
local commit_files
|
|
|
|
|
2021-06-23 10:48:31 +00:00
|
|
|
# check commit message
|
2021-06-24 13:15:34 +00:00
|
|
|
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}'"
|
2021-06-23 10:48:31 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check all files of the commit belongs to $BUILT_PATHS
|
2021-06-24 13:15:34 +00:00
|
|
|
commit_files=$(git diff-tree --no-commit-id --name-only -r "${commit_sha}")
|
2021-06-23 10:48:31 +00:00
|
|
|
for i in ${BUILT_PATHS[*]}; do
|
|
|
|
# remove files of ${BUILT_PATHS}
|
2021-06-24 13:15:34 +00:00
|
|
|
commit_files=$(echo "${commit_files}" | grep -v "^${i}")
|
2021-06-23 10:48:31 +00:00
|
|
|
done
|
2021-06-24 13:15:34 +00:00
|
|
|
|
|
|
|
if [ -n "${commit_files}" ]; then
|
|
|
|
echo "Commit $1 contains files that were not build: ${commit_files}"
|
2021-06-23 10:48:31 +00:00
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2021-06-25 16:34:40 +00:00
|
|
|
|
2021-06-23 10:48:31 +00:00
|
|
|
static.build.commit.drop() {
|
2021-06-24 13:15:34 +00:00
|
|
|
local last_commit_id
|
2021-06-25 16:34:40 +00:00
|
|
|
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)"
|
2021-06-23 10:48:31 +00:00
|
|
|
|
2021-06-24 13:15:34 +00:00
|
|
|
if [ -z "${last_commit_id}" ]; then
|
2021-06-23 10:48:31 +00:00
|
|
|
echo "Empty branch"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2021-06-24 13:15:34 +00:00
|
|
|
if ! is.build.commit "${last_commit_id}"; then
|
2021-06-23 10:48:31 +00:00
|
|
|
return $?
|
|
|
|
fi
|
2021-06-24 13:15:34 +00:00
|
|
|
echo "Drop last commit ${last_commit_id}"
|
2021-06-23 10:48:31 +00:00
|
|
|
git reset --hard HEAD~1
|
|
|
|
}
|
|
|
|
|
|
|
|
static.build.commit() {
|
2021-06-24 13:15:34 +00:00
|
|
|
local staged_files
|
|
|
|
|
2021-06-23 10:48:31 +00:00
|
|
|
# check for not commited files
|
2021-06-24 13:15:34 +00:00
|
|
|
if [ -n "$(git diff --name-only)" ]; then
|
2021-06-23 10:48:31 +00:00
|
|
|
echo "Some files are not commited:"
|
|
|
|
echo "${NOT_COMMITED_FILES}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2021-06-24 13:15:34 +00:00
|
|
|
staged_files=$(git diff --name-only --cached)
|
|
|
|
|
2021-06-23 10:48:31 +00:00
|
|
|
# check for staged files
|
2021-06-24 13:15:34 +00:00
|
|
|
if [ -n "${staged_files}" ]; then
|
2021-06-23 10:48:31 +00:00
|
|
|
echo "Some files are staged:"
|
2021-06-24 13:15:34 +00:00
|
|
|
echo "${staged_files}"
|
2021-06-23 10:48:31 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# drop existing commit
|
2021-06-24 13:15:34 +00:00
|
|
|
if static.commit.drop; then
|
2021-06-23 10:48:31 +00:00
|
|
|
return $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
# build the themes
|
|
|
|
make themes.all
|
|
|
|
|
|
|
|
# add build files
|
2021-06-24 13:15:34 +00:00
|
|
|
for built_path in "${BUILT_PATHS[@]}"; do
|
2021-06-23 10:48:31 +00:00
|
|
|
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
|
2021-06-24 13:15:34 +00:00
|
|
|
git commit -m "${BUILD_COMMIT_MESSAGE}"
|
2021-06-23 10:48:31 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2021-06-24 15:23:01 +00:00
|
|
|
git restore --staged "${BUILT_PATHS[@]}"
|
2021-06-23 10:48:31 +00:00
|
|
|
;;
|
|
|
|
static.git.restore)
|
|
|
|
# "git restore" of the built files.
|
2021-06-24 15:23:01 +00:00
|
|
|
git restore --worktree --staged "${BUILT_PATHS[@]}"
|
2021-06-23 10:48:31 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|