如何发布到Travis CI的Github页面? [英] How to publish to Github Pages from Travis CI?

查看:149
本文介绍了如何发布到Travis CI的Github页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

解决方案

HTTPS API令牌的分步示例在环境变量中



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


  1. 为网站创建一个单独的存储库(可选)。这将减少覆盖主存储库的可能性,并保持输出文件不会污染它。

  2. https://github.com/settings/tokens



    只为公共仓库启用public_repo访问权限,为私有仓库启用repo。



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


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

      GITHUB_API_KEY =< token> 

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



    这是安全的,因为只有您通过授权推送才能看到此类环境变量,因此如果恶意用户尝试提取请求来获取您的字符串,变量将不会存在。 / p>

    只要确保永远不要,就可以在您的构建中列出您的环境变量!

  4. 添加跟随你的 .travis.yml

      after_success:| 
    if [-n$ GITHUB_API_KEY];然后
    cd$ TRAVIS_BUILD_DIR
    #这将生成一个包含网站的web目录。
    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
    #确保输出安静,否则API令牌会泄漏!
    #这是可行的,因为API密钥可以替代您的密码。
    git push -f -q https://< me>:$ GITHUB_API_KEY@github.com/< me> /< myrepo> -gh-pages gh-pages& 2> / 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 Web界面,但需要使用Gem和一些更复制粘贴。

We are compiling Doxygen docs on the travis-ci server and want to push them onto our gh-pages branch.

How do I handle the authorization for git push? Does someone have an example for using encrypted variables in travis-ci? Should I go for https authorization or for an SSH key?

解决方案

Step-by-step example with HTTPS API Token in environment variable

Others have mentioned it, but here goes a more detailed procedure.

  1. Create a separate repository for the website (optional). This will reduce the likelihood that you overwrite your main repository, and will keep output files from polluting it.

  2. Get a Personal Access Token under https://github.com/settings/tokens

    Only enable "public_repo" access for public repositories, "repo" for private.

    Save the token somewhere as you can only see it once.

  3. On the Travis settings for the repository https://travis-ci.org/<me>/<myrepo>/settings create an environment variable:

    GITHUB_API_KEY=<token>
    

    and make sure to mark "Display value in build log" as "Off".

    This is safe because only authorized pushes by you see such environment variables, so if a malicious user tries to make a pull request to get your string, the variable won't be there.

    Just make sure that you never, ever list your environment variables on your build!

  4. Add the following to your .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 &2>/dev/null
        cd "$TRAVIS_BUILD_DIR"
      fi
    

Alternative travis encrypt method

Explained in detail at: https://stackoverflow.com/a/33109519/895245

Encrypt the string GITHUB_API_KEY=<key> with the travis gem, and add it to your .travis.yml:

env:
  secure: <encrypted>

This has the advantage that it does not require using the Travis web interface, but does require using a Gem and some more copy pasting.

这篇关于如何发布到Travis CI的Github页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆