Last active
December 20, 2023 21:47
-
-
Save nickboldt/5b674f75934e7bba5a38486e17a18cfa to your computer and use it in GitHub Desktop.
wrapper for brew as replacement for borked rhpkg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# requires | |
# dnf install -y brewkoji python3-koji-containerbuild-cli \ | |
# openldap-clients python3-rpkg python3-kobo python3-bugzilla \ | |
# gcc openssl-devel bzip2-devel sqlite-devel | |
# brew container-build rhdh-1.0-rhel-9-containers-candidate | |
# git+https://pkgs.devel.redhat.com/git/containers/rhdh-operator#5459112551259a7f5a194227e7b3537be38afdf0 \ | |
# --git-branch rhdh-1.0-rhel-9 | |
gitbranch=$(git rev-parse --abbrev-ref HEAD || true) # echo $gitbranch | |
if [[ $gitbranch != "rhdh-"*"-rhel-"* ]] && [[ $gitbranch != "devspaces-"*"-rhel-"* ]]; then | |
gitbranch="rhdh-1-rhel-9" | |
fi | |
target=${gitbranch}-containers-candidate | |
repo="$(git remote -v | grep origin | head -1 | sed -r -e "s#.+/containers/(.+) \(fetch.+#\1#")" | |
sha="$(git rev-parse HEAD)" | |
scratchFlag="" | |
usage () { | |
echo " | |
Usage: | |
$0 [options] | |
Options: | |
-b branch Default branch: $gitbranch (current repo) | |
-r repo Default repo: $repo (current repo) | |
-t SHA Default SHA: $sha (current head commit) | |
-n Default: do a normal (non-scratch) build | |
-s, --scratch Optional: do a scratch build | |
-h, --help This help | |
Example | |
$0 -r $repo -t $sha -b $gitbranch --scratch | |
" | |
} | |
while [[ "$#" -gt 0 ]]; do | |
case $1 in | |
'-b'|'--gitbranch') gitbranch="$2"; target="${gitbranch}-containers-candidate"; shift 1;; | |
'-r') repo="$2"; shift 1;; | |
'-t') sha="$2"; shift 1;; | |
'-s'|'--scratch') scratchFlag="--scratch"; shift 0;; | |
'-n') scratchFlag=""; shift 0;; | |
'-h'| '--help') usage; exit 0;; | |
esac | |
shift 1 | |
done | |
if [[ $scratchFlag != "" ]]; then gitbranch=$(git rev-parse --abbrev-ref HEAD); fi | |
CMD="brew container-build ${target} git+https://pkgs.devel.redhat.com/git/containers/${repo}#${sha} --git-branch ${gitbranch} --nowait ${scratchFlag}" | |
git pull && git push && tmpfile=$(mktemp) && \ | |
$CMD 2>"${tmpfile}.err" | tee 2>&1 "${tmpfile}" && \ | |
if [[ $(grep -c -E "brew: error: " "${tmpfile}.err") -gt 0 ]]; then | |
echo "[ERROR] Could not run brew container-build! | |
=============================== | |
$CMD | |
=============================== | |
" | |
grep -E -v '^[[:space:]]*$|DeprecationWarning' "${tmpfile}.err" | |
echo " | |
=============================== | |
" | |
exit 4 | |
fi | |
taskID=$(cat "${tmpfile}" | grep "Created task:" | sed -e "s#Created task: *##") && brew watch-logs $taskID | tee 2>&1 "${tmpfile}" | |
taskID=${taskID// /} | |
google-chrome https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=$taskID | |
echo "Task completed: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=$taskID" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment