自动 git push

工作中有大量的仓库需要单独维护,一个个push很麻烦,这时通过 shell 脚本操作就很方便

新建 git_push.sh 并写入

# Repos to push
GitRepos=(
    '.\some_package_to_push'
    '.\some_package_to_push_too'
)
# Run
cd 'your repo dir'
for i in ${GitRepos[@]}; do
    echo --------------------------------------------------
    echo - Processing: $i
    echo --------------------------------------------------
    cd $i
    git status
    git add .
    git commit -m 'update'
    git push
    echo Done.
    cd -
done

修改 ~/.bashrc 添加别名 alias gpsh='.\your script dir\git_push.sh',可以便捷地调用脚本

$ gpsh

自动打包并发布到自建 pypi

打包和自建pypi就不赘述了,可以自行搜索学习

强烈建议自己纯手动打包 + 部署pypi server 发布一次理解整个过程

同样是通过 shell 脚本可以实现批量快速发布

set -e  # Quit under any error
dev_path='your package path'
pypi_host_dir='your package save path on host'
all_packages=(mypackage1 mypackage2)

read -p '>>> Package to publish: ' package_name

function main() {
    cd $dev_path$1
    python setup.py sdist bdist_wheel
    cd dist
    new_tar=$(ls -lt | grep .tar.gz | head -n 1 | awk '{print $9}')
    new_whl=$(ls -lt | grep .whl | head -n 1 | awk '{print $9}')
    scp $new_tar $new_whl $pypi_host_dir
    if [ "$?" = "0" ]; then
        echo -e "\n"
        echo '>>>' Package is successfully published!
        echo '>>>' Please install with pip3:
        echo pip3 install $package_name -i http://*.*.*.*/simple --trusted-
        echo pip3 install $package_name --upgrade -i http://*.*.*.*:8080/simple --trusted-host *.*.*.*
    fi
}
if [ $package_name == all ]; then
    for pkg in ${all_packages[*]}; do
        main $pkg
    done
else
    main $package_name
fi