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

fix(ci): cleanup before package building, not after #23619

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
27 changes: 27 additions & 0 deletions clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,37 @@
set -e -u

TERMUX_SCRIPTDIR=$(cd "$(realpath "$(dirname "$0")")"; pwd)
CLEANUP_MESSAGE="Cleaning up build artifacts."

# Store pid of current process in a file for docker__run_docker_exec_trap
. "$TERMUX_SCRIPTDIR/scripts/utils/docker/docker.sh"; docker__create_docker_exec_pid_file

# Get variable CGCT_DIR
. "$TERMUX_SCRIPTDIR/scripts/properties.sh"

while (($# >= 1)); do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
while (($# >= 1)); do
while (( $# )); do

Numbers other than 0 are truthy.

case "$1" in
-m)
if [ $# -ge 2 ]; then
shift 1
if [ -z "$1" ]; then
echo "./clean.sh: Argument to '-m' should not be empty."
exit 1
fi
CLEANUP_MESSAGE="$1"
else
echo "./clean.sh: option '-m' requires an argument"
exit 1
fi
;;
-*)
echo "./clean.sh: illegal option '$1'"
exit 1
;;
esac
shift 1
done

# Checking if script is running on Android with 2 different methods.
# Needed for safety to prevent execution of potentially dangerous
# operations such as 'rm -rf /data/*' on Android device.
Expand All @@ -30,6 +54,9 @@ test -f "$HOME/.termuxrc" && . "$HOME/.termuxrc"
: "${TMPDIR:=/tmp}"
export TMPDIR


echo "INFO: $CLEANUP_MESSAGE"

# Lock file. Same as used in build-package.sh.
TERMUX_BUILD_LOCK_FILE="${TMPDIR}/.termux-build.lck"
if [ ! -e "$TERMUX_BUILD_LOCK_FILE" ]; then
Expand Down
8 changes: 4 additions & 4 deletions scripts/updates/utils/termux_pkg_upgrade_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,19 @@ termux_pkg_upgrade_version() {
fi
done < "${TERMUX_SCRIPTDIR}/scripts/big-pkgs.list"

if [[ "${big_package}" == "true" ]]; then
"${TERMUX_SCRIPTDIR}/scripts/run-docker.sh" ./clean.sh
if [[ "${big_package}" == "true" || "${force_cleanup}" == "true" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If -C causes termux_step_cleanup_packages() to run, which uses the same $TERMUX_CLEANUP_BUILT_PACKAGES_THRESHOLD as ${force_cleanup} does, but clean.sh deletes way more things than termux_step_cleanup_packages() does, and now this changes it so that ${force_cleanup} is checked before ./build-package.sh is run in this file (instead of after), then is -C with build-package.sh in this file still necessary? since, if everything possible was already cleaned with clean.sh right before build-package.sh is run on a single package, then termux_step_cleanup_packages() in this file will now always return without doing anything?

if ! "${TERMUX_SCRIPTDIR}/scripts/run-docker.sh" ./build-package.sh -C -a "${TERMUX_ARCH}" -i "${TERMUX_PKG_NAME}"; then

(-C would still be necessary with build-package.sh in packages.yml though, because packages.yml does not use clean.sh)

"${TERMUX_SCRIPTDIR}/scripts/run-docker.sh" ./clean.sh -m "Running clean.sh to recover disk space"
fi

if ! "${TERMUX_SCRIPTDIR}/scripts/run-docker.sh" ./build-package.sh -C -a "${TERMUX_ARCH}" -i "${TERMUX_PKG_NAME}"; then
if [[ "${big_package}" == "true" ]]; then
"${TERMUX_SCRIPTDIR}/scripts/run-docker.sh" ./clean.sh
"${TERMUX_SCRIPTDIR}/scripts/run-docker.sh" ./clean.sh -m "Running clean.sh to recover disk space"
fi
git checkout -- "${TERMUX_PKG_BUILDER_DIR}"
termux_error_exit "ERROR: failed to build."
fi

if [[ "${big_package}" == "true" ]] || [[ "${force_cleanup}" == "true" ]]; then
if [[ "${big_package}" == "true" ]]; then
"${TERMUX_SCRIPTDIR}/scripts/run-docker.sh" ./clean.sh
fi

Expand Down