gpt4 book ai didi

git - 如何从 Travis CI 发布到 Github Pages?

转载 作者:IT王子 更新时间:2023-10-29 00:57:39 24 4
gpt4 key购买 nike

我们正在 travis-ci 服务器上编译 Doxygen 文档,并希望将它们推送到我们的 gh-pages 分支。

如何处理git push的授权?有人有在 travis-ci 中使用加密变量的例子吗?我应该使用 https 授权还是使用 SSH key ?

最佳答案

在环境变量中使用 HTTPS API token 的分步示例

其他人已经提到了,但这里有更详细的过程。

  1. 为网站创建一个单独的存储库(可选)。这将降低您覆盖主存储库的可能性,并防止输出文件污染它。

  2. https://github.com/settings/tokens 下获取个人访问 token

    只为公共(public)仓库启用“public_repo”访问,为私有(private)仓库启用“repo”。

    将 token 保存在某处,因为您只能看到它一次。

  3. 关于存储库的 Travis 设置 https://travis-ci.org/<me>/<myrepo>/settings创建一个环境变量:

    GITHUB_API_KEY=<token>

    并确保将“在构建日志中显示值”标记为“关闭”。

    这是安全的,因为只有您授权的推送才能看到此类环境变量,因此,如果恶意用户试图发出 pull 请求以获取您的字符串,则变量不会存在。

    只需确保您永远不会在您的构建中列出您的环境变量!

  4. 将以下内容添加到您的 .travis.yml :

    after_success: |
    if [ -n "$GITHUB_API_KEY" ]; then
    cd "$TRAVIS_BUILD_DIR"
    # This generates a `web` directory containing the website.
    make web
    cd web
    git init
    git checkout -b gh-pages
    git add .
    git -c user.name='travis' -c user.email='travis' commit -m init
    # Make sure to make the output quiet, or else the API token will leak!
    # This works because the API key can replace your password.
    git push -f -q https://<me>:$GITHUB_API_KEY@github.com/<me>/<myrepo>-gh-pages gh-pages &>/dev/null
    cd "$TRAVIS_BUILD_DIR"
    fi

替代的travis加密方式

详细解释:https://stackoverflow.com/a/33109519/895245

加密字符串GITHUB_API_KEY=<key>travis gem ,并将其添加到您的 .travis.yml :

env:
secure: <encrypted>

这样做的好处是它不需要使用 Travis 网络界面,但确实需要使用 Gem 和更多的复制粘贴。

关于git - 如何从 Travis CI 发布到 Github Pages?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23277391/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com