Skip to content

Commit

Permalink
fixup rebase for build.sh
Browse files Browse the repository at this point in the history
fixing build.sh

fixing build.sh- adding ignore files

fixing build.sh- adding ignore files and upstream

working on incorporating upstream.sh into master

working results file for build-all
  • Loading branch information
dillera committed Jan 22, 2024
1 parent 3489445 commit 788f4ed
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ firmware/*
CMakeSettings.json

.cache/

build-results.txt
platformio.ini-E
platformio.iniwow

65 changes: 63 additions & 2 deletions build-platforms/build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,41 @@
# merging it with BASE.ini to create platformio-test.ini
# which the build.sh script will run a clean build against.

# search_file is the name of the completed firmware that proves we built that platform
# file_name is the resulting file that will hold the results of the build-all
SEARCH_FILE="firmware.bin"
FILE_NAME="build-results.txt"


# Clean up any old ini files as well.
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
if [ -f "$SCRIPT_DIR/test.ini" ] ; then
rm $SCRIPT_DIR/test.ini
fi


echo ' ---------------------------------------- '
echo ' | | '
echo ' | Starting build-all script..... | '
echo " | SCRIPT_DIR=$SCRIPT_DIR"
echo " | output will be saved in $FILE_NAME"
echo ' | in the root of this repo.'
echo ' | | '
echo ' ---------------------------------------'
echo ''
echo ''

printf "Below this begins each platform build in sequence...."
printf "\n\n\n"

# We will create a record of what is built
# but first, clean out the old one....
if [ -f "$FILE_NAME" ]; then
rm "$FILE_NAME"
printf 'Found an old results file, deleted it.\n\n'
fi


# reads an ini [section] given the name from file, writes to output file.
function get_section {
local target_name=$1
Expand All @@ -25,7 +55,13 @@ function get_section {
}' $in_file > $out_file
}


# Setup a results file so we can see how we did.
NOW=$(date +"%Y-%m-%d %H:%M:%S")
printf "Start Time: $NOW - ----- Starting Build the World for Fujinet\n\n\n" >> "$FILE_NAME"

# loop over every platformio-XXX.ini file, and use it to create a test platformio file

for piofile in $(ls -1 $SCRIPT_DIR/platformio-*.ini) ; do
echo "Testing $(basename $piofile)"

Expand All @@ -45,7 +81,32 @@ for piofile in $(ls -1 $SCRIPT_DIR/platformio-*.ini) ; do
rm $SCRIPT_DIR/part1.ini

pushd ${SCRIPT_DIR}/..
./build.sh -cb -i $SCRIPT_DIR/test.ini

# Breaking this up into 3 parts.
# 1. - call build for the platform
# 2. - echo a line in results file, find firmware.bin
# 3. - now call build but just to clean

./build.sh -b -i $SCRIPT_DIR/test.ini

# first determine if there is a firmware bin which means a good build
NOW=$(date +"%Y-%m-%d %H:%M:%S")

# Extract the substring after 'platformio-' and before '.ini'
extracted_string=$(echo "$piofile" | sed -e 's|.*platformio-\(.*\)\.ini|\1|')
printf "$NOW - Built $extracted_string\n" >> "$FILE_NAME"

FOUND=$(find . -name "$SEARCH_FILE" -print -quit)
if [ -n "$FOUND" ]; then
printf "File '$SEARCH_FILE' found" >> "$FILE_NAME"
else
printf "File '$SEARCH_FILE' not found - this platfrom has issues \n" >> "$FILE_NAME"
fi
echo "------------------------------------------------" >> "$FILE_NAME"

./build.sh -c -i $SCRIPT_DIR/test.ini

popd

done

done
21 changes: 21 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ ZIP_MODE=0
AUTOCLEAN=1
INI_FILE="${SCRIPT_DIR}/platformio.ini"

OS_TYPE=$(uname)
if [ "$OS_TYPE" = "Linux" ]; then
echo "Running on a Linux system. Wise choice."
elif [ "$OS_TYPE" = "Darwin" ]; then
echo "Running on a Macintosh system."
BINARY_PATH="/usr/local/opt/gnu-sed/libexec/gnubin/sed"
if [ -f "$BINARY_PATH" ]; then
echo "Proper sed Binary file found: $BINARY_PATH"
else
echo "gnu sed Binary file not found; please install via brew install gnu-sed and re-run"
exit 1
fi
else
echo "Running on an unidentified system."
fi


# This beast finds the directory the build.sh script is in, no matter where it's run from
# which should be the root of the project
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

function show_help {
echo "Usage: $(basename $0) [-a|-b|-c|-d|-e ENV|-f|-g|-i FILE|-m|-n|-t TARGET|-p TARGET|-u|-z|-h]"
echo " Most common options:"
Expand Down
72 changes: 72 additions & 0 deletions upstream.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash
# Usage: upstream.sh [target-branch-if-not-master-or-main]
#
# Fetch upstream changes, merge them in with ff-only to our main/master
# branch, then rebase our current work on top of that.
# Specify the "main" branch you want to rebase against as a parameter
# if it is NOT one of main/master.

UB_SPECIFIED="false"
if [ $# -eq 1 ] ; then
USER_BRANCH="$1"
UB_SPECIFIED="true"
fi

if [ -n "$(git status --short)" ] ; then
echo "Your working tree is not clean. Aborting"
echo "check these files:"
git status --short
echo "there should be no untracked or un-committed files to proceed!"
exit 1
fi

git remote | grep -s 'upstream' > /dev/null
if [ $? -ne 0 ] ; then
echo "No upstream remote found."
echo "Please use 'git remote add upstream <URL to remote git repo>' to use this"
exit 1
fi

# main or master branch name
if [ "$UB_SPECIFIED" == "true" ] ; then
BR_MATCH="(\b$USER_BRANCH\b|\bmaster\b|\bmain\b)"
else
BR_MATCH="(\bmaster\b|\bmain\b)"
fi
M_BRANCH=$(git branch -v --no-color | sed 's#^\*# #' | awk '{print $1}' | grep -E "$BR_MATCH" | head -1)

if [ -z "$M_BRANCH" ] ; then
echo "Could not find branch to merge against. Used patter: $BR_MATCH"
exit 1
fi

# jumps to master/main if needed, fetches, merges and pushes latest upstream/master changes to our
# repo, then rebases our branch on top of master/main

current_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$current_branch" != "${M_BRANCH}" ]; then
echo "Changing from branch ${current_branch} to ${M_BRANCH}"
git checkout ${M_BRANCH}
fi

echo "Fetching upstream changes"
git fetch upstream ${M_BRANCH}
echo "Merging changes (fast forward only)"
git merge upstream/${M_BRANCH} --ff-only
if [ $? -ne 0 ] ; then
echo "ERROR performing ff-only merge. Rebasing against upstream"
git rebase upstream/${M_BRANCH}
if [ $? -ne 0 ] ; then
echo "ERROR rebasing to upstream. Your changes conflict with upstream changes."
git rebase --abort
exit 1
fi
fi

if [ "$current_branch" != "${M_BRANCH}" ]; then
echo "Resetting back to previous branch ${current_branch}"
git checkout $current_branch
echo "Rebasing local changes with external. You may need to fix merge conflicts"
git rebase ${M_BRANCH}
fi

1 comment on commit 788f4ed

@dillera
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also committed updstream.sh into the repo so there is no reason for anyone not to run it!

Please sign in to comment.