ソースを参照

Rewrite bump_version in python

tags/pure-v9.5.5
Guillaume Vincent 2年前
コミット
4070e3d11d
2個のファイルの変更72行の追加93行の削除
  1. +0
    -93
      bin/bump_version.bash
  2. +72
    -0
      bin/bump_version.py

+ 0
- 93
bin/bump_version.bash ファイルの表示

@@ -1,93 +0,0 @@
#!/usr/bin/env bash

RED='\033[0;31m'
GREEN='\033[0;32m'
NOCOLOR='\033[0m'

function echo_red {
echo -e "${RED}$1${NOCOLOR}"
}

function echo_green {
echo -e "${GREEN}$1${NOCOLOR}"
}

function check_current_directory_is_root {
if [ ! -f README.md ]; then
echo_red "You seems to be in the wrong directory"
echo_red "Execute this script from the root of lesspass with ./bin/${0##*/}"
exit 1
fi
}

function check_repository_is_clean {
git remote update
git add .
git status
git diff-index --quiet HEAD
if [ $? == 1 ]
then
echo_red "Git repository not clean. Aborting."
exit 1
fi
if [ $(git rev-parse HEAD) != $(git rev-parse @{u}) ]
then
echo_red "Git branch diverged. Aborting."
exit 1
fi
}

function check_branch_is_main {
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
if [ $BRANCH_NAME != "main" ]
then
echo_red "Current branch is not main. Aborting."
exit 1
fi
}

function check_usage {
is_invalid=false
package="${1}"
if [ "${package}" != "web-extension" ] && [ "${package}" != "site" ]
then
echo_red "Error: package is invalid. (web-extension or site)."
is_invalid=true
fi
bump_type="${2}"
if [ "${bump_type}" != "--major" ] && [ "${bump_type}" != "--minor" ] && [ "${bump_type}" != "--patch" ]
then
echo_red "Error: No bump type specified (--major, --minor or --patch)."
is_invalid=true
fi
if [ "$is_invalid" = true ]
then
echo_green "Example: ./bin/${0##*/} web-extension --patch"
echo_green "Example: ./bin/${0##*/} site --patch"
exit 1
fi
}

set +o errexit

package="${1:-}"
bump_type="${2:-}"
check_usage ${package} ${bump_type}
check_branch_is_main
check_current_directory_is_root
check_repository_is_clean

set -o errexit
set -o pipefail
set -o nounset

current_version=$( grep -m1 version packages/lesspass-${package}/package.json | cut -d '"' -f4 )
echo "Current lesspass-${package} version is ${current_version}"
yarn config set version-tag-prefix "${package}-v"
yarn config set version-git-message "${package}-v%s"
yarn workspace lesspass-${package} version ${bump_type}
yarn config set version-tag-prefix "v"
yarn config set version-git-message "v%s"
new_version=$( grep -m1 version packages/lesspass-${package}/package.json | cut -d '"' -f4 )
echo "New lesspass-${package} version is ${new_version}"
echo_green "git push --tags origin main"

+ 72
- 0
bin/bump_version.py ファイルの表示

@@ -0,0 +1,72 @@
import sys
import os
import json
import subprocess

root_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))


def usage():
script_name = os.path.basename(__file__)
print(f"Example: python {script_name} lesspass-web-extension patch")
print(f"Example: python {script_name} lesspass-site patch")
sys.exit(1)


def print_packages_version(packages):
len_col = len(max(packages, key=packages.get)) + 2
for package in packages:
with open(os.path.join(root_path, "packages", package, "package.json")) as f:
package_json = json.load(f)
printable_package_name = f"{package:{len_col}s}"
version = package_json["version"]
print(f"|{printable_package_name}|{version.rjust(9, ' ')}|")


if __name__ == "__main__":
if len(sys.argv) != 3:
usage()

has_error = False
package = sys.argv[1]
packages = {
"lesspass": "lesspass",
"lesspass-crypto": "crypto",
"lesspass-entropy": "entropy",
"lesspass-fingerprint": "fingerprint",
"lesspass-pure": "pure",
"lesspass-render-password": "render-password",
"lesspass-site": "site",
"lesspass-web-extension": "web-extension",
}
if package not in packages:
print(f"Error: {package} is invalid, should be one of:")
packages_joined = "\n ".join(packages.keys())
print(f" {packages_joined}")
has_error = True

bump = sys.argv[2]
bump = bump.replace("-", "")
valid_bumps = ["major", "minor", "patch"]
if bump not in valid_bumps:
valid_bump_joined = ",".join(valid_bumps)
print(f"Error: {bump} is invalid, should be one of {valid_bump_joined}")
has_error = True

if has_error:
usage()

print_packages_version(packages)

package_short_name = packages[package]
subprocess.run(
["yarn", "config", "set", "version-tag-prefix", f"{package_short_name}-v"]
)
subprocess.run(
["yarn", "config", "set", "version-git-message", f"{package_short_name}-v%s"]
)
subprocess.run(["yarn", "workspace", f"{package}", "version", f"--{bump}"])
subprocess.run(["yarn", "config", "set", "version-tag-prefix", "v"])
subprocess.run(["yarn", "config", "set", "version-git-message", "v%s"])

print_packages_version(packages)

読み込み中…
キャンセル
保存