Skip to content

Commit

Permalink
Merge pull request #490 from Moo-Ack-Productions/set-test-output-stat…
Browse files Browse the repository at this point in the history
…us-code

Improve release automation with automated test running
  • Loading branch information
TheDuckCow committed Nov 10, 2023
2 parents bdc10fa + e915aa5 commit 7bcad1d
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 7 deletions.
106 changes: 106 additions & 0 deletions push_latest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/bin/bash
source venv/bin/activate

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

# -----------------------------------------------------------------------------
# Validate and build the release.
# -----------------------------------------------------------------------------

# Affirm on the master branch
BRANCH=$(git rev-parse --abbrev-ref HEAD)

if [ "$BRANCH" != "master" ]; then
echo -e "${RED}Not on master branch, run:${NC}"
echo "git checkout master"
exit
fi

# TODO(TheDuckCow): Perform check when we have an automated way to set prod env.
# if [[ `git status --porcelain` ]]; then
# echo "There are uncommited changes, ending"
# exit
# fi

git pull --quiet
echo ""
echo "Current status (should be empty!)"
git status

echo "Running tests"
python run_tests.py -a
if [ $? -eq 0 ]; then
echo "Tests passed, moving on"
else
echo "Tests failed, exiting"
exit
fi

# -----------------------------------------------------------------------------
# Update the data mapping to the latest values
# -----------------------------------------------------------------------------

# Manual override: we must recheckout some files after test runs finished,
# due to some side effects of testing with local code references.
git checkout MCprep_addon/MCprep_resources/mcprep_data_update.json
git checkout test_files/test_data/jmc2obj_test_1_15_2.mtl
git checkout test_files/test_data/mineways_test_combined_1_15_2.mtl
git checkout test_files/test_data/mineways_test_separated_1_15_2.mtl

python mcprep_data_refresh.py -auto

git status

ANY_DIFF=$(git diff MCprep_addon/MCprep_resources/mcprep_data_update.json)
if [ -z "$ANY_DIFF" ]
then
echo ""
else
echo "Commit new updates to mapping file before release:"
echo "$ANY_DIFF"
exit
fi


# -----------------------------------------------------------------------------
# Validate and build the release.
# -----------------------------------------------------------------------------


echo "Building prod addon..."
bpy-addon-build # No --during-build dev to make it prod.
ls build/MCprep_addon.zip

echo ""
echo "Current live tags online:"
git tag -l

echo ""
# Extract the numbers between parentheses, replace comma and space with period
BASE_VER=$(grep "\"version\":" MCprep_addon/__init__.py | awk -F"[()]" '{print $2}' | tr ',' '.' | tr -d ' ')
NEW_TAG="${BASE_VER}"
echo -e "Current __init__ version: ${GREEN}${NEW_TAG}${NC}"
read -p -r "Continue (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
NEW_NAME="MCprep_addon_$NEW_TAG.zip"
mv build/MCprep_addon.zip "build/$NEW_NAME"
exit 0
# Make the tags
echo ""
echo "Generating tags and DRAFT release on github"
# use --generate-notes to auto generate release notes (edit for public changelog)
gh release create "$NEW_TAG" \
--draft \
--generate-notes \
-t "v${BASE_VER} | (Update)" \
"./build/$NEW_NAME"
echo ""
echo "Complete release by going to the link above, and updating these pages:"
echo "https://theduckcow.com/dev/blender/mcprep-download/"
echo "https://theduckcow.com/dev/blender/mcprep/releases/"
14 changes: 12 additions & 2 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import argparse
import os
import subprocess
import sys
import time


Expand Down Expand Up @@ -75,6 +76,7 @@ def main():

# Loop over all binaries and run tests.
t0 = time.time()
any_failures = False
for ind, binary in enumerate(blender_execs):
run_all = args.all_execs is True
run_specific = args.version is not None
Expand All @@ -94,14 +96,22 @@ def main():
cmd.extend(["-t", args.test_specific])
if args.version is not None:
cmd.extend(["-v", args.version])
output = subprocess.check_output(cmd)
# output = subprocess.check_output(cmd)
child = subprocess.Popen(cmd, stdout=subprocess.PIPE)
output = child.communicate()[0]
print(output.decode("utf-8"))

# Detect if there was at least 1+ failure/error, to pass to exit code.
if child.returncode != 0:
any_failures = True

t1 = time.time()

output_results()
round_s = round(t1 - t0)
print(f"tests took {round_s}s to run")
exit_code = 1 if any_failures else 0
print(f"tests took {round_s}s to run, ending with code {exit_code}")
sys.exit(exit_code)


def get_args():
Expand Down
12 changes: 7 additions & 5 deletions test_files/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,22 @@ def main():
fails = [res[0].id().split(".")[-1] for res in results.failures]
skipped = [res[0].id().split(".")[-1] for res in results.skipped]

errors = ";".join(errs + fails).replace(",", " ")
with open("test_results.csv", 'a') as csv:
errors = ";".join(errs + fails).replace(",", " ")
if errors == "":
errors = "No errors"
err_txt = "No errors" if errors == "" else errors
csv.write("{},{},{},{},{},{}\r\n".format(
str(bpy.app.version).replace(",", "."),
"all_tests" if not args.test_specific else args.test_specific,
results.testsRun - len(skipped),
len(skipped),
len(results.errors) + len(results.failures),
errors,
err_txt,
))
print("Wrote out test results.")
sys.exit()
if errors:
sys.exit(1)
else:
sys.exit(0)


if __name__ == '__main__':
Expand Down

0 comments on commit 7bcad1d

Please sign in to comment.