#script #bash #rem #github #import #remote #execution

app rem-bash

远程bash脚本执行和库导入

4个版本

0.2.2 2021年10月3日
0.2.1 2021年9月26日
0.2.0 2021年9月26日
0.1.0 2021年9月26日

#1#rem

MIT 许可证

26KB
603

rem

rem 是一个用于管理远程bash脚本的工具。

它旨在用于CI/CD环境和本地自动化目的。 rem 可以将脚本库导入到新脚本中,或直接在命令行中运行脚本。

示例

# Add a github repository
rem repo add ansi github.com/fidian/ansi

# Import the repository
source <(rem import ansi:ansi)
echo "$(ansi --green SUCCESS:) We can now use the imported functions!"

# Add your private repositories (password will be read from $TOKEN)
rem repo add ci gitlab.com:mycompany/ci-scripts --password-env TOKEN

# Run your scripts whenever you need them
rem run ci:generate-coverage.sh ./tests/*

# Pin your scripts to a specific ref
rem run [email protected]:upload-results.sh

如何安装

rem是用Rust编写的,可以使用Cargo包管理器进行安装。

cargo install rem-bash

如果您尚未安装Rust,建议使用rustup。您需要Rust工具链的最新夜间版本

# Install rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Switch to nightly
rustup default nightly

脚本源

目前,通过API支持github和gitlab。您可以通过提供URL并为其提供一个别名,将任意数量的脚本保存到您的本地仓库列表中。

# Use either a short version
rem repo add github.com/me/myscripts

# Or the full URL
rem repo add scripts https://github.com/me/myscripts

# Provide a token/password through stdin
cat my-token.txt | rem repo add private github.com/me/privatescripts --password-stdin

# Or read it from a variable everytime you run the script
export MY_TOKEN="$(cat my-token.txt)"
rem repo add private github.com/me/privatescripts --password-env

# List your local repositories
rem repo ls

# And remove them
rem repo rm private

您添加的仓库将被保存到 $HOME/.remconf.toml。建议使用 --password-env 选项,这样您就不会不小心将任何明文密码留在bash历史记录中。
在CI/CD环境中,这也是首选方式,因为您可以在配置了仓库的docker镜像中安全地构建。配置中存储的将是读取令牌的变量的名称。

待办事项

该工具目前处于可用状态,但还有一些功能缺失,使其能够在更多环境中可靠和有用。以下是我计划要做的事情

  • 支持来自任何提供者的原始git仓库
  • 支持非git源中的脚本
  • 允许验证保存的仓库
  • 为离线环境添加本地缓存
  • 在运行之前验证脚本(shebang,静态分析,任意检查)
  • 添加测试

依赖项

~8–20MB
~298K SLoC