Skip to content

Commit

Permalink
Add Fork and Branch Detection Functions
Browse files Browse the repository at this point in the history
Added two new functions to the script which should point it to the correct fork and branch to clone from which will lead to a successful build.

And as always did some more scripts cleanup and added notes where needed.

Update linux-build.sh - remove --verbose from ls-remote of git

Update linux-build.sh - Correct Variable Mistakes

Update linux-build.sh - Shorten Readable Variables and add set to track script.

Update linux-builld.sh - added more verbose code for debugging

Update scripts-build.yaml - Adjust tmate to activate on failure and for 30minutes.

I might need to change my approach on how I do this.

Update linux-build.sh - Change how the DEFAULT_BRANCH filled.

Change Approach in linux-build.sh - Did a True, False if statement instead of the ! if statement. Easier to follow too.

Update linux-build.sh - Corrected logic errors and add more logging.
  • Loading branch information
odysseywestra committed Feb 15, 2024
1 parent 292fce8 commit 6ad53d0
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 80 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/script-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ jobs:
- name: "Clean MyPaint"
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
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
timeout-minutes: 30

176 changes: 98 additions & 78 deletions scripts/linux-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
# of pacman as default. This script will also be building from source instead of using
# pkgbuilds. I will add this back in later.

set -o pipefail

# ANSI control codes
RED='\033[0;31m'
GREEN='\033[0;32m'
Expand All @@ -41,40 +43,19 @@ SCRIPT=`basename "$0"`
SCRIPTDIR=`dirname "$0"`
cd "$SCRIPTDIR/.."

# Main repository location, as an absolute path.
# Main repository location and Working Directory, as an absolute path.
TOPDIR=`pwd`
WORKING_DIR=$(cd "$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.

# This script pulls down and maintains a clone of the mypaint project so I need
# to keep track of the root directory of the project. This will be using ubuntu
# 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_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_URL="$(git config --get remote.origin.url)"
SRC_USERNAME="$(echo $SRC_URL | awk -F[:/.] '{print $6}')"
SRC_PROJECT_NAME="$(echo $SRC_URL | awk -F[:/.] '{print $7}')"
SRC_SITE="$(git config --get remote.origin.url | sed -nE 's#(https://[^/]*)/.*#\1#p')"
SRC_UPSTREAM_URL="$SRC_SITE/$SRC_REMOTE_PROJECT_NAME/$SRC_REMOTE_PROJECT_NAME.git"
SRC_UPSTREAM_URL="$SRC_SITE/$SRC_PROJECT_NAME/$SRC_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
# 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"
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.

Expand Down Expand Up @@ -102,6 +83,27 @@ 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"



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

prepare_enviroment(){
Expand All @@ -127,63 +129,81 @@ install_dependencies() {
logok "Pixbuf query loaders cache updated"
}

# The use_correct_branch() fuction will check the upstream remote repository for the correct branch and
# if it exists it will use the same branch. If it does not exist it will use
# the main branch. This will most likely be called from the install_from_source()
# function.

use_correct_branch(){
# Set the branch name
SRC_BRANCH=$(git rev-parse --abbrev-ref HEAD)

loginfo "$SOURCEPKG is on branch $SRC_BRANCH"

# Check if the branch exists in the mypaint repository
git ls-remote --heads https://github.com/owner1/repo1.git $branch | grep -q refs/heads/$branch
if [ $? -eq 0 ]; then
branch=$branch
# This function will select the correct fork of the source package and pass it to $SOURCEPKG_URL.
use_correct_fork(){
if [ -z "$1" ]; then
logerror "No argument passed to use_correct_fork()"
exit 1
fi
SOURCEPKG="$1"
loginfo "Checking to see if $SRC_USERNAME has $SOURCEPKG in their Repositories"
SOURCEPKG_URL="$SRC_SITE/$SRC_USERNAME/$SOURCEPKG.git"
FORK_EXISTS=$(git ls-remote --quiet --exit-code $SOURCEPKG_URL > /dev/null && echo "true" || echo "false")

if $FORK_EXISTS; then
lognote "$SRC_USERNAME has a fork of $SOURCEPKG."
CORRECT_REPO="Fork"
else
branch="main"
lognote "$SRC_USERNAME does not have a fork of $SOURCEPKG."
CORRECT_REPO="Upstream"
SOURCEPKG_URL="$SRC_SITE/$SRC_PROJECT_NAME/$SOURCEPKG.git"
fi

# Checkout the branches
git clone --branch $branch1 https://github.com/owner1/repo1.git repo1
lognote "Using $CORRECT_REPO Repository: $SOURCEPKG_URL for $SOURCEPKG"
}

# This function will be used to install the dependencies from source. Need to
# make it modular so that it can be used for other enviroment or when we change
# build procces.
# This function will select the correct branch of the source package and pass it to $SOURCEPKG_BRANCH.
use_correct_branch(){
if [ -z "$1" ]; then
logerror "No argument passed to use_correct_branch()"
exit 1
fi
SOURCEPKG="$1"
loginfo "Checking to see if $SRC_BRANCH exists in $SOURCEPKG git repository"
BRANCH_EXISTS=$(git ls-remote --quiet --exit-code $SOURCEPKG_URL $SRC_BRANCH > /dev/null && echo "true" || echo "false")

if $BRANCH_EXISTS; then
lognote "$SRC_BRANCH exists in $SOURCEPKG git repository."
SOURCEPKG_BRANCH="$SRC_BRANCH"
else
lognote "No branch matching $SRC_BRANCH found for $SOURCEPKG."
SOURCEPKG_BRANCH="$DEFAULT_BRANCH"
fi

lognote "Using $SOURCEPKG_BRANCH branch for $SOURCEPKG"
}

# 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(){
SOURCEPKG="$1"
INSTALL="$2"
SOURCEPKG_URI="$SRC_SITE/$SRC_REMOTE_USRNAME/$SOURCEPKG"
loginfo "Cloning $SOURCEPKG Repository"
cd $TOPDIR
# Check to see if the user has forked the repository. If not use upstream.
if ! git clone --verbose $SOURCEPKG_URI; then
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.
loginfo "Building $SOURCEPKG"
./autogen.sh
./configure --prefix=/usr
make
if $INSTALL; then
loginfo "Installing $SOURCEPKG into Enviroment"
sudo make install
logok "Install finished"
fi
popd
# This should stay instead of deleting the source package.
# At least for testing.
loginfo "Removing $SOURCEPKG" Source from Environment
sudo rm -v -fr $SOURCEPKG
SOURCEPKG="$1"
INSTALL="$2"
cd $WORKING_DIR
use_correct_fork $SOURCEPKG
use_correct_branch $SOURCEPKG
loginfo "Cloning the correct $SOURCEPKG Repository"
if ! git clone --depth 1 --branch $SOURCEPKG_BRANCH $SOURCEPKG_URL; then
logerror "Failed to clone $SOURCEPKG"
exit 1
fi
pushd "$SOURCEPKG"
# TODO: Make this bit of script into it's own function.
loginfo "Building $SOURCEPKG"
./autogen.sh
./configure --prefix=/usr
make
if $INSTALL; then
loginfo "Installing $SOURCEPKG into Enviroment"
sudo make install
logok "Install finished"
else
loginfo "Skipping install of $SOURCEPKG"
fi
popd
# This should stay instead of deleting the source package.
# At least for testing.
loginfo "Removing $SOURCEPKG Source from Environment"
sudo rm -v -fr $SOURCEPKG
}

build_for_testing() {
Expand Down

0 comments on commit 6ad53d0

Please sign in to comment.