-
-
Save KangOl/d47bf722f98050765496416982da7479 to your computer and use it in GitHub Desktop.
nus :: new upgrade script
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
#!/usr/bin/env bash | |
set -euo pipefail | |
if [[ -n "${DEBUG:-}" ]]; then | |
set -x | |
fi | |
: "${NUS_ODOO_REPO:=/Users/chs/devel/odoo/odoo/stable}" | |
: "${NUS_ENT_REPO:=/Users/chs/devel/odoo/enterprise}" | |
: "${NUS_THEMES_REPO:=/Users/chs/devel/odoo/themes}" | |
NUS_FETCH=0 | |
opt= | |
while getopts 'hfv:' opt; do | |
case "$opt" in | |
h) | |
cat <<EOU | |
# nus :: New Upgrade Script | |
nus [-v VERSION] MODULE [KIND] | |
Options: | |
-h Show this help message. | |
-v VERSION Server version of the script. | |
Can be set via the env variable \$NUS_VERSION. | |
When the search branch is different than the | |
version (mainly for master branch), use the | |
\`version:branch\` pattern. | |
Arguments: | |
MODULE Module the script target. | |
KIND The kind of upgrade script. | |
Will be used to name the created file. [default: pre] | |
Environment variable: | |
NUS_VERSION | |
NUS_ODOO_REPO | |
NUS_ENT_REPO | |
NUS_THEMES_REPO | |
EOU | |
exit 0 | |
;; | |
f) | |
NUS_FETCH=1 | |
;; | |
v) | |
NUS_VERSION="$OPTARG" | |
;; | |
*);; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
if [[ $# != 1 && $# != 2 ]]; then | |
$0 -h | |
exit 1 | |
fi | |
if [[ -z "${NUS_VERSION:-}" ]]; then | |
echo "😶 no version specified" | |
exit 1 | |
fi | |
NUS_BRANCH="${NUS_VERSION}" | |
NUS_VERSION=${NUS_VERSION%%:*} | |
NUS_BRANCH=${NUS_BRANCH##*:} | |
NUS_VERSION=${NUS_VERSION/-/\~} | |
NUS_BRANCH=${NUS_BRANCH/\~/-} | |
NUS_MODULE="$1" | |
NUS_KIND="${2:-pre}" | |
grepin () { | |
pushd "$1" >/dev/null | |
if [[ $NUS_FETCH -eq 1 ]]; then | |
git fetch -q | |
fi | |
blob=$(git ls-tree "origin/$NUS_BRANCH" -- {.,addons,{openerp,odoo}/addons}/"$NUS_MODULE"/__{terp,openerp,manifest}__.py 2>/dev/null | awk '{print $3}') | |
if [[ -n $blob ]]; then | |
git show "$blob" | python3 -c "import ast,sys;print(ast.literal_eval(sys.stdin.buffer.read().decode()).get('version','1.0'))" | |
fi | |
popd >/dev/null | |
} | |
module_version=$(grepin "$NUS_ODOO_REPO") | |
if [[ -z "$module_version" ]]; then | |
module_version=$(grepin "$NUS_ENT_REPO") | |
if [[ -z "$module_version" ]]; then | |
module_version=$(grepin "$NUS_THEMES_REPO") | |
if [[ -z "$module_version" ]]; then | |
echo "💥 module not found!" | |
exit 1 | |
fi | |
fi | |
fi | |
dir="${NUS_MODULE}/${NUS_VERSION}.${module_version}" | |
mkdir -p "$dir" | |
FILE="$dir/$NUS_KIND-migrate.py" | |
touch "$FILE" | |
git add --intent-to-add "$FILE" | |
set -x | |
${EDITOR:-vim} "$FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment