Skip to content

Commit

Permalink
Add Package Selection Options and Code Cleanup
Browse files Browse the repository at this point in the history
Add the ability to add Package Management and select it via the GitHub Actions script.

Update linux-script.sh - Fix Syntax Error

Update linux-build.sh - Syntax Corrected and add LogNotes.

Update linux-build.sh - fix lognotes and add package selections as a function

Update linux-build.sh - Clean up deadspace

Update linux-build.sh - add error code for unneeded arguments and fix tab spacing
  • Loading branch information
odysseywestra committed Feb 18, 2024
1 parent dd6fe2d commit 770b0d6
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 120 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/script-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ jobs:
linux:
name: Linux
runs-on: ubuntu-22.04
env:
PKG_MANAGER: apt-get
USE_SUDO: true
steps:
- name: "Checkout Repository"
uses: actions/checkout@v4
Expand Down
290 changes: 170 additions & 120 deletions scripts/linux-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ SRC_BRANCH=$(git rev-parse --abbrev-ref HEAD)
DEFAULT_BRANCH=$(git remote show origin | grep 'HEAD branch' | awk '{print $3}')

# These are just here to make the output of the script more readable in the logs.

loginfo() {
echo -ne "${CYAN}"
echo -ne "${CYAN}INFO: "
echo -n "$@"
echo -e "${NC}"
}

logok() {
echo -ne "${GREEN}"
echo -ne "${GREEN}SUCCESS: "
echo -n "$@"
echo -e "${NC}"
}
Expand All @@ -83,30 +82,49 @@ lognote() {
echo -e "${NC}"
}

# TODO: These variables below should be called from the GitHub actions
# environment. Then change this to an if statement incase those environment
# variables are not set.

# Need to make the script for package management flexible so that it can be used
# on other systems. Need to make running sudo optional as well.

PKG_MANAGER="apt-get"
UPDATE_CMD="sudo $PKG_MANAGER update"
UPGRADE_CMD="sudo $PKG_MANAGER upgrade"
INSTALL_CMD="sudo $PKG_MANAGER install -y"
REMOVE_CMD="sudo $PKG_MANAGER remove -y"

# Set a package dependency list incase other OS's are used.

DEP_LIST="g++ gettext intltool gir1.2-gtk-3.0 libgtk-3-dev libjson-c-dev \
liblcms2-dev libpng-dev python3-dev python-gi-dev python3-gi-cairo \
python3-nose python3-numpy python3-setuptools swig git"


if [ $USE_SUDO == "true" ]; then
APPEND_SUDO="sudo"
lognote "Using sudo."
else
APPEND_SUDO=""
lognote "Not using sudo."
$USE_SUDO="false"
fi

select_pkg_manager(){
if [ $PKG_MANAGER == "apt-get" ]; then
lognote "Using apt-get package manager."

UPDATE_CMD="$APPEND_SUDO apt-get update"
UPGRADE_CMD="$APPEND_SUDO apt-get upgrade"
INSTALL_CMD="$APPEND_SUDO apt-get install -y"
REMOVE_CMD="$APPEND_SUDO apt-get remove -y"
DEP_LIST="g++ gettext intltool gir1.2-gtk-3.0 libgtk-3-dev libjson-c-dev \
liblcms2-dev libpng-dev python3-dev python-gi-dev python3-gi-cairo \
python3-nose python3-numpy python3-setuptools swig git"
elif [ $PKG_MANAGER == "pacman" ]; then
lognote "Using msys2 pacman package manager."
UPDATE_CMD="$APPEND_SUDO pacman -Sy"
UPGRADE_CMD="$APPEND_SUDO pacman -Su"
INSTALL_CMD="$APPEND_SUDO pacman -S --noconfirm"
REMOVE_CMD="$APPEND_SUDO pacman -R --noconfirm"
DEP_LIST="base-devel git mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake \
mingw-w64-x86_64-gtk3 mingw-w64-x86_64-json-glib mingw-w64-x86_64-lcms2 \
mingw-w64-x86_64-python3 mingw-w64-x86_64-python3-numpy mingw-w64-x86_64-python3-gobject \
mingw-w64-x86_64-python3-cairo mingw-w64-x86_64-python3-setuptools mingw-w64-x86_64-swig"
else
logerror "No package manager found."
exit 1
fi
}

# This function will be used to update the environment and upgrade the packages

prepare_enviroment(){
if [ -n "$1" ]; then
logerror "No arguments should be passed to prepare_enviroment()"
exit 1
fi
select_pkg_manager
loginfo "Updating Environment packages"
$UPDATE_CMD
loginfo "Upgradeing Packages"
Expand All @@ -115,17 +133,21 @@ prepare_enviroment(){
}

# This function will be used to install the dependencies for the project.

install_dependencies() {
if [ -n "$1" ]; then
logerror "No arguments should be passed to install_dependencies()"
exit 1
fi
select_pkg_manager
loginfo "Installing Dependencies"
if ! $INSTALL_CMD $DEP_LIST; then
logerror "Failed to install dependencies"
exit 1
fi
logok "Dependencies installed"

sudo ln -s /usr/lib/*/gdk-pixbuf-2.0/gdk-pixbuf-query-loaders /usr/local/bin/gdk-pixbuf-query-loaders
sudo gdk-pixbuf-query-loaders --update-cache
$APPEND_SUDO ln -s /usr/lib/*/gdk-pixbuf-2.0/gdk-pixbuf-query-loaders /usr/local/bin/gdk-pixbuf-query-loaders
$APPEND_SUDO gdk-pixbuf-query-loaders --update-cache
logok "Pixbuf query loaders cache updated"
}

Expand Down Expand Up @@ -176,6 +198,10 @@ use_correct_branch(){
# This function will be used to install the source package from the source. Needs
# use_correct_fork() and use_correct_branch() to work properly.
install_from_source(){
if [ -z "$1" ] || [ -z "$2" ]; then
logerror "No arguments passed to install_from_source()"
exit 1
fi
SOURCEPKG="$1"
INSTALL="$2"
cd $WORKING_DIR
Expand Down Expand Up @@ -207,115 +233,139 @@ install_from_source(){
}

build_for_testing() {
# This just build mypaint and if there are errors the build fails.
loginfo "Building MyPaint from source"
if ! python3 setup.py build; then
logerror "Build failed."
exit 1
fi
logok "Build finished."
if [ -n "$1" ]; then
logerror "No arguments should be passed to build_for_testing()"
exit 1
fi
# This just build mypaint and if there are errors the build fails.
loginfo "Building MyPaint from source"
if ! python3 setup.py build; then
logerror "Build failed."
exit 1
fi
logok "Build finished."
}

clean_local_repo() {
# This test the clean function in the setup.py file. So we have a clean
# repository to build with again.
loginfo "Cleaning local build"
if ! python3 setup.py clean --all; then
logerror "Fail to clean repository."
exit 1
fi
if ! rm -vf lib/*_wrap.c*; then
logerror "Fail to remove lib/*_wrap.c*"
exit 1
fi
logok "Clean finished."
if [ -n "$1" ]; then
logerror "No arguments should be passed to clean_local_repo()"
exit 1
fi
# This test the clean function in the setup.py file. So we have a clean
# repository to build with again.
loginfo "Cleaning local build"
if ! python3 setup.py clean --all; then
logerror "Fail to clean repository."
exit 1
fi
if ! rm -vf lib/*_wrap.c*; then
logerror "Fail to remove lib/*_wrap.c*"
exit 1
fi
logok "Clean finished."
}

install_test(){
# This will test the install and uninstall fuction in the setup.py file.
# This will probably go away, but it's here for now.
loginfo "Testing setup.py managed installation commands"
loginfo "Running managed_install"
if ! sudo python3 setup.py managed_install; then
logerror "Install failed."
exit 1
fi
logok "Install finished."

loginfo "Running managed_uninstall"
if ! sudo python3 setup.py managed_uninstall; then
logerror "Uninstall failed."
exit 1
fi
logok "Uninstall finished."
logok "Install-test finished finished."
if [ -n "$1" ]; then
logerror "No arguments should be passed to clean_local_repo()"
exit 1
fi
# This will test the install and uninstall fuction in the setup.py file.
# This will probably go away, but it's here for now.
loginfo "Testing setup.py managed installation commands"
loginfo "Running managed_install"
if ! sudo python3 setup.py managed_install; then
logerror "Install failed."
exit 1
fi
logok "Install finished."

loginfo "Running managed_uninstall"
if ! sudo python3 setup.py managed_uninstall; then
logerror "Uninstall failed."
exit 1
fi
logok "Uninstall finished."
logok "Install-test finished finished."
}

run_doctest() {
# This will make sure all the files in the lib directory are present and working.
loginfo "Running unit document tests."
if ! python3 setup.py nosetests --tests lib; then
logerror "Test failed."
exit 1
fi
logok "Unit document tests done."
if [ -n "$1" ]; then
logerror "No arguments should be passed to clean_local_repo()"
exit 1
fi
# This will make sure all the files in the lib directory are present and working.
loginfo "Running unit document tests."
if ! python3 setup.py nosetests --tests lib; then
logerror "Test failed."
exit 1
fi
logok "Unit document tests done."
}

run_tests() {
# This will run conformance test to make sure the brush engine is working.
# NOTE: Might need to run with xvfb too since it skiping certian tests.
loginfo "Running conformance tests."
if ! python3 setup.py test; then
logerror "Test failed."
exit 1
fi
logok "Tests done."
if [ -n "$1" ]; then
logerror "No arguments should be passed to clean_local_repo()"
exit 1
fi
# This will run conformance test to make sure the brush engine is working.
# NOTE: Might need to run with xvfb too since it skiping certian tests.
loginfo "Running conformance tests."
if ! python3 setup.py test; then
logerror "Test failed."
exit 1
fi
logok "Tests done."
}

run_demo() {
# This will run the demo and quit. Use xvfb-run if you are on a headless CI.
loginfo "Running demo"
if ! MYPAINT_DEBUG=1 python setup.py demo --args='--run-and-quit'; then
logerror "Demo failed."
exit 1
fi
logok "Demo done."
if [ -n "$1" ]; then
logerror "No arguments should be passed to clean_local_repo()"
exit 1
fi
# This will run the demo and quit. Use xvfb-run if you are on a headless CI.
loginfo "Running demo"
if ! MYPAINT_DEBUG=1 python setup.py demo --args='--run-and-quit'; then
logerror "Demo failed."
exit 1
fi
logok "Demo done."
}

case "$1" in
update-env)
prepare_enviroment
;;
install)
case $2 in
pkg-deps)
install_dependencies
;;
source-dep)
install_from_source $3 $4
;;
*)
logerror "Unknown install command: $2"
exit 2
;;
esac
;;
build)
build_for_testing
;;
clean)
clean_local_repo
;;
tests)
run_tests
run_doctest
install_test
;;
demo)
run_demo
;;
*)
grep '^#:' $0 | cut -d ':' -f 2-50
exit 2
;;
update-env)
prepare_enviroment
;;
install)
case $2 in
pkg-deps)
install_dependencies
;;
source-dep)
install_from_source $3 $4
;;
*)
logerror "Unknown install command: $2"
exit 2
;;
esac
;;
build)
build_for_testing
;;
clean)
clean_local_repo
;;
tests)
run_tests
run_doctest
install_test
;;
demo)
run_demo
;;
*)
grep '^#:' $0 | cut -d ':' -f 2-50
exit 2
;;
esac

0 comments on commit 770b0d6

Please sign in to comment.