Skip to content

Commit

Permalink
Direct Paths in YAML & More readability Changes.
Browse files Browse the repository at this point in the history
Decided to do Direct Paths in the Github Actions workflow file so that the script can better keep track of itself and the directory it is in. This is copied over from the msys2-build.sh script.

I also made the script more readable since this will be calling functions that have settings  or options. So I want to make sure future contributors can read and follow it when it time to edit the script or improve it.

Update script-build.yaml - Missing Argument in Script Call.

Update linux-build.sh - Added ".git" to end of source argument.

Update linux-build.sh - Fix String Variable Error.
  • Loading branch information
odysseywestra committed Feb 14, 2024
1 parent 4ffd993 commit 292fce8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 52 deletions.
23 changes: 10 additions & 13 deletions .github/workflows/script-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,40 @@ jobs:
linux:
name: Linux
runs-on: ubuntu-22.04
defaults:
run:
working-directory: scripts/
steps:
- name: "Checkout Repository"
uses: actions/checkout@v4

- name: "Make Script Executable"
run: chmod +x linux-build.sh
run: chmod +x $GITHUB_WORKSPACE/scripts/linux-build.sh

- name: "Update Enviroment"
run: ./linux-build.sh update-env
run: bash $GITHUB_WORKSPACE/scripts/linux-build.sh update-env

- name: "Install Dependencies"
run: ./linux-build.sh install pkg-deps
run: bash $GITHUB_WORKSPACE/scripts/linux-build.sh install pkg-deps

- name: "Install libmypaint from Source"
run: ./linux-build.sh install source-dep libmypaint true
run: bash $GITHUB_WORKSPACE/scripts/linux-build.sh install source-dep libmypaint true

- name: "Install mypaint-brushes from Source"
run: ./linux-build.sh install source-dep mypaint-brushes true
run: bash $GITHUB_WORKSPACE/scripts/linux-build.sh install source-dep mypaint-brushes true

- name: "Build MyPaint"
run: ./linux-build.sh build
run: bash $GITHUB_WORKSPACE/scripts/linux-build.sh build

- name: "Test MyPaint"
run: xvfb-run --auto-servernum ./linux-build.sh tests
run: xvfb-run --auto-servernum bash $GITHUB_WORKSPACE/scripts/linux-build.sh tests

- name: Run demo with XVFB
run: xvfb-run --auto-servernum ./linux-build.sh demo
run: xvfb-run --auto-servernum bash $GITHUB_WORKSPACE/scripts/linux-build.sh demo

- name: "Clean MyPaint"
run: ./linux-build.sh clean
run: bash $GITHUB_WORKSPACE/scripts/linux-build.sh clean

# Activate a ssh interactive shell for me to run commands in the build.
# THIS IS TEMPORARY FOR ME TO TEST STUFF.
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
timeout-minutes: 5
timeout-minutes: 30

74 changes: 35 additions & 39 deletions scripts/linux-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

# This script will act similar to the windows/msys2-build.sh script. The
# main difference is that it will be using the apt-get package manager instead
# of pacman. This script will also be building from source instead of using
# pkgbuilds
# of pacman as default. This script will also be building from source instead of using
# pkgbuilds. I will add this back in later.

# ANSI control codes
RED='\033[0;31m'
Expand All @@ -36,6 +36,15 @@ CYAN='\033[0;36m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color

# Script name and location.
SCRIPT=`basename "$0"`
SCRIPTDIR=`dirname "$0"`
cd "$SCRIPTDIR/.."

# Main repository location, as an absolute path.
TOPDIR=`pwd`
cd "$TOPDIR"

# 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.
Expand All @@ -45,12 +54,11 @@ NC='\033[0m' # No Color
# image from github actions and the root directory will be /home/work/mypaint/.

# Gather revelant information of the project and where it was cloned.
SRC_REM_URL="$(git config --get remote.origin.url)"
SRC_REM_UNAME="$(echo $SRC_REM_URL | awk -F[:/.] '{print $6}')"
SRC_REM_PRJ="$(echo $SRC_REM_URL | awk -F[:/.] '{print $7}')"
SRC_ROOT_DIR="$(git rev-parse --show-toplevel)"
SRC_REMOTE_URL="$(git config --get remote.origin.url)"
SRC_REMOTE_USRNAME="$(echo $SRC_REMOTE_URL | awk -F[:/.] '{print $6}')"
SRC_REMOTE_PROJECT_NAME="$(echo $SRC_REMOTE_URL | awk -F[:/.] '{print $7}')"
SRC_SITE="$(git config --get remote.origin.url | sed -nE 's#(https://[^/]*)/.*#\1#p')"
SRC_UPSTR_URL="$SRC_SITE/$SRC_REM_PRJ/$SRC_REM_PRJ.git"
SRC_UPSTREAM_URL="$SRC_SITE/$SRC_REMOTE_PROJECT_NAME/$SRC_REMOTE_PROJECT_NAME.git"
SRC_BRANCH=$(git rev-parse --abbrev-ref HEAD)

# Need to make the script for package management flexible so that it can be used
Expand Down Expand Up @@ -82,33 +90,18 @@ logok() {
echo -e "${NC}"
}

logerr() {
logerror() {
echo -ne "${RED}ERROR: "
echo -n "$@"
echo -e "${NC}"
}

logwarn() {
echo -ne "${YELLOW}WARNING: "
lognote() {
echo -ne "${YELLOW}NOTICE: "
echo -n "$@"
echo -e "${NC}"
}

# This section makes sure that we start from the Project Source Path.
# By Default it should point to /home/runner/work/username/projectname.
# TODO: This should be set to a funtion as well. Its causing the script to get lost
# without it. It's either that or write the script in a way were We always
# start from the scripts source directory. In this case its /scripts but
# need to make sure can be moved and still be in the correct place
# when executed.

cd $SRC_ROOT_DIR
if [ $? -ne 0 ]; then
logerr "Could not change to $SRC_ROOT_DIR. Exiting."
exit 1
fi


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

prepare_enviroment(){
Expand All @@ -124,7 +117,7 @@ prepare_enviroment(){
install_dependencies() {
loginfo "Installing Dependencies"
if ! $INSTALL_CMD $DEP_LIST; then
logerr "Failed to install dependencies"
logerror "Failed to install dependencies"
exit 1
fi
logok "Dependencies installed"
Expand Down Expand Up @@ -164,13 +157,16 @@ use_correct_branch(){
install_from_source(){
SOURCEPKG="$1"
INSTALL="$2"
SOURCEPKG_URI="$SRC_SITE/$SRC_REM_UNAME/$SOURCEPKG"
SOURCEPKG_URI="$SRC_SITE/$SRC_REMOTE_USRNAME/$SOURCEPKG"
loginfo "Cloning $SOURCEPKG Repository"
cd $SRC_ROOT_DIR
cd $TOPDIR
# Check to see if the user has forked the repository. If not use upstream.
if ! git clone --verbose $SOURCEPKG_URI; then
logwarn "User has no fork of $SOURCEPKG. Using upstream source"
git clone --verbose $SRC_SITE/$SRC_REM_PRJ/$SOURCEPKG
lognote "User has no fork of $SOURCEPKG. Using upstream source"
if ! git clone --verbose $SRC_SITE/$SRC_REMOTE_PROJECT_NAME/$SOURCEPKG.git; then
logerror "Failed to clone $SOURCEPKG"
exit 1
fi
fi
pushd "$SOURCEPKG"
# TODO: Make this bit of code into it's own function.
Expand All @@ -194,7 +190,7 @@ 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
logerr "Build failed."
logerror "Build failed."
exit 1
fi
logok "Build finished."
Expand All @@ -205,11 +201,11 @@ clean_local_repo() {
# repository to build with again.
loginfo "Cleaning local build"
if ! python3 setup.py clean --all; then
logerr "Fail to clean repository."
logerror "Fail to clean repository."
exit 1
fi
if ! rm -vf lib/*_wrap.c*; then
logerr "Fail to remove lib/*_wrap.c*"
logerror "Fail to remove lib/*_wrap.c*"
exit 1
fi
logok "Clean finished."
Expand All @@ -221,14 +217,14 @@ install_test(){
loginfo "Testing setup.py managed installation commands"
loginfo "Running managed_install"
if ! sudo python3 setup.py managed_install; then
logerr "Install failed."
logerror "Install failed."
exit 1
fi
logok "Install finished."

loginfo "Running managed_uninstall"
if ! sudo python3 setup.py managed_uninstall; then
logerr "Uninstall failed."
logerror "Uninstall failed."
exit 1
fi
logok "Uninstall finished."
Expand All @@ -239,7 +235,7 @@ 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
logerr "Test failed."
logerror "Test failed."
exit 1
fi
logok "Unit document tests done."
Expand All @@ -250,7 +246,7 @@ run_tests() {
# NOTE: Might need to run with xvfb too since it skiping certian tests.
loginfo "Running conformance tests."
if ! python3 setup.py test; then
logerr "Test failed."
logerror "Test failed."
exit 1
fi
logok "Tests done."
Expand All @@ -260,7 +256,7 @@ 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
logerr "Demo failed."
logerror "Demo failed."
exit 1
fi
logok "Demo done."
Expand All @@ -279,7 +275,7 @@ case "$1" in
install_from_source $3 $4
;;
*)
logerr "Unknown install command: $2"
logerror "Unknown install command: $2"
exit 2
;;
esac
Expand Down

0 comments on commit 292fce8

Please sign in to comment.