Skip to content

Commit

Permalink
Feat: Test Homebrew Formula in macos.yaml
Browse files Browse the repository at this point in the history
Also added better command-line parsing to runformula.sh
  • Loading branch information
dgreatwood committed Nov 18, 2024
1 parent a5b92ac commit 8d536ab
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 12 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ on:
push:
branches:
- master
- brewFormula
pull_request:
branches:
- master
- brewFormula

defaults:
run:
Expand Down Expand Up @@ -92,6 +94,12 @@ jobs:
# Use the following to run just a single test (e.g. http_server_test)
# run: build/tests/run_http_server_test

- name: Test Homebrew Formula
run: |
homebrew/runformula.sh -y --HEAD
if brew list pistache &>/dev/null; then brew remove pistache; fi
homebrew/runformula.sh -y
- name: Coverage
if: ${{ !contains(matrix.os, 'macos') }} # Remove this if to do coverage test
run: |
Expand All @@ -115,4 +123,3 @@ jobs:
sha256sum --check codecov.SHA256SUM
chmod +x codecov
./codecov
80 changes: 70 additions & 10 deletions homebrew/runformula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,65 @@
# shasum -a 256 <filename.tar.gz>
# Note: brew formula audit prefers tarball to zip file.

if [ $# -gt 0 ]; then
if [ $# -gt 1 ] || [ "$1" != "--HEAD" ]; then
echo "Usage: $(basename "$0") [-h] [--help] [--HEAD]"
echo " With --HEAD, tests with head of pistache master"
echo " Otherwise, tests with pistache release"
exit 0
# For option parsing, see:
# https://stackoverflow.com/questions/402377/using-getopts-to-process-long-and-short-command-line-options
# (The answer that begins "The Bash builtin getopts function can be...")
# And:
# https://linuxsimply.com/bash-scripting-tutorial/functions/script-argument/bash-getopts/
# MAKE SURE below that you set optspec to correctly reflect short options

do_error=false
do_yes=false
do_usage=false
use_head=false
optspec=":hy-:"
while getopts "$optspec" optchar; do
case "${optchar}" in
-)
case "${OPTARG}" in
HEAD)
use_head=true
;;
help)
do_usage=true
;;
*)
echo "Error: Unknown option --${OPTARG}" >&2
do_error=true
break
;;
esac;;
h)
do_usage=true
;;
y)
do_yes=true
;;
*)
echo "Error: Non-option argument: '-${OPTARG}'" >&2
do_error=true
break
;;
esac
done

if [ "$do_error" = true ]; then do_usage=true; fi

if [ "$do_usage" = true ]; then
echo "Usage: $(basename "$0") [-h] [--help] [-y] [--HEAD]"
echo " -h Prints usage message, then exits"
echo " --help Prints usage message, then exits"
echo " --HEAD Tests with head of pistache master"
echo " (otherwise, tests with pistache release)"
echo " -y Answer yes to questions (i.e. do audit)"
if [ "$do_yes" = true ] || [ "$do_head" = true ]; then
echo "Error: Usage requested with other options"
do_error=true
fi
if [ "$do_error" = true ]; then
exit 1
fi
exit 0
fi

if ! type "brew" > /dev/null; then
Expand Down Expand Up @@ -65,7 +117,7 @@ if [ -f "$pist_form_file" ]; then

if cmp --silent -- "$MY_SCRIPT_DIR/pistache.rb" "$pist_form_file"; then
echo "$pist_form_file is already up to date, exiting"
if [ "$1" != "--HEAD" ]; then
if [ "$use_head" != true ]; then
if brew list pistache &>/dev/null; then
echo "If you like: brew remove pistache; brew install --build-from-source pistache"
else
Expand All @@ -92,15 +144,23 @@ else
fi

if brew list pistache &>/dev/null; then brew remove pistache; fi
if [[ "$1" == "--HEAD" ]]; then
if [ "$use_head" = true ]; then
brew install --HEAD pistache
else
brew install --build-from-source pistache
fi
brew test --verbose pistache

read -e -p 'brew audit? [y/N]> '
if [[ "$REPLY" == [Yy]* ]]; then
do_audit=$do_yes
if [ "$do_audit" != true ]; then
read -e -p 'brew audit? [y/N]> '
if [[ "$REPLY" == [Yy]* ]]; then
do_audit=true
fi
fi

if [ "$do_audit" = true ]; then
echo "Auditing brew formula..."
brew audit --strict --new --online pistache
else
echo "Skipping audit"
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.18.20241117
0.4.18.20241118

0 comments on commit 8d536ab

Please sign in to comment.