farseerfc / farseerfc.github.io

My new blog style with bootstrap-material-design
17 stars 6 forks source link

travis-push-to-github-pages-blog #49

Open farseerfc opened 8 years ago

farseerfc commented 8 years ago

This issue is reserved for https://farseerfc.me/travis-push-to-github-pages-blog.html

PoiScript commented 7 years ago

fc 好棒! 在新版的 Travis-CI 已经加入了设置环境变量的功能, 像这样: screenshot_20170206_101308 所以还可以设置好 GitHub Token 的环境变量, 然后通过

git push -f -q https://<username>:$GITHUB_TOKEN@github.com/<username>/<repo>

来提交代码

farseerfc commented 7 years ago

Poi 說得對,現在不需要這麼麻煩了

SwiftSIQI commented 7 years ago

@PoiScript Hi,我看了你的评论后,十分好奇你是看到那个文档里面具体说明了这种 push 的方式的,我一直没有找到对应的文档或者资料,十分感谢

SwiftSIQI commented 7 years ago

@farseerfc @PoiScript 看了整个文章还有一点疑问没有解决

我在加密过程中的做法如下:

travis encrypt 'GIT_NAME=myname GIT_EMAIL=myemaildress GH_TOKEN=mytoken BLOG_NAME=myblogname --add

现在,我想解密后的的 push 地址是 https://myname:$mytoken@github.com/myname/myblogname

用上面的方法做加密转换后的样式如下 https://$GIT_NAME:$GH_TOKEN@github.com/$GIT_NAME/$BLOG_NAME

使用 Travis CI 后, 给出的解析结果是 https://myname:mytoken@github.com/myname/myblogname

也就是说在 mytoken 前少了一个 $ 号,我应该怎么解决呢?

望指点!

farseerfc commented 7 years ago

@SketchK 感覺你的 travis 配置寫錯了。另外現在不需要 travis encrypt 可以直接在項目裏面設置隱私信息啦。

SwiftSIQI commented 7 years ago

@farseerfc 我没太理解不需要 travis encrypt 的意思,是说直接用下面这种方式 push 么,但这样不是会暴露 token 的名称么,加上用户名等信息都有的话,是不是不安全啊?

git push -f -q https://<username>:$GITHUB_TOKEN@github.com/<username>/<repo>

第二个,我想理解下你说的 travis 配置写错了是说下面这话写错了么,还是其他配置么?

travis encrypt 'GIT_NAME=myname GIT_EMAIL=myemaildress GH_TOKEN=mytoken BLOG_NAME=myblogname --add

最后,我用了一个比较 stupid 的方法,在加密的时候 添加了一个字段 GH_TOKEN_SPECIAL=$mytoken 在 push 的时候写成这样就成功了

https://$GIT_NAME:$GH_TOKEN_SPECIAL@github.com/$GIT_NAME/$BLOG_NAME
farseerfc commented 7 years ago

@SketchK 上面 @PoiScript 的截圖,現在可以直接在設置界面裏面設置隱私環境變量,然後 travis 會在執行前設置好這些變量,就不會暴露隱私了呀。原本 travis encrypt 也就是爲了達成這個目的。

你那句 travis encrypt 最後的 --add 是什麼意思呀?

另外不知道你是怎麼寫 travis 配置的,是直接寫在 .travis.yml 還是寫在了別的腳本然後用 .travis.yml 調用,這兩種方式下環境變量的展開方式不太一樣。

SwiftSIQI commented 7 years ago

@farseerfc 这是我网站的源码分支 里面有 travis 文件 https://github.com/SketchK/SketchK.github.io/tree/blog-source

--add 的意思是把 travis 生成的 secure token 放到 travis.yml 文件里

至于保密性的问题,我理解的是,我通过你的 travis.yml 文件,知道了你的配置(比如 github ,email ,repo name等)以及 token 名称,我是可以用你的配置信息在 travis ci 上进行 push 或者 deleate 操作啊,这个你没法隐藏啊,因为 travis.yml 文件是会暴露出来的,安装 @PoiScript 的说法,且不对信息加密

farseerfc commented 7 years ago

@SketchK 應該最後不需要寫 --add 吧,你看到哪裏說需要 --add 的呢?寫 --add 反而感覺會因爲語法錯誤不能執行到……

token 的名字是啥?personal access token只是一串值,並沒有名字吧,最多有個你設的環境變量的名字,而知道這個環境變量的名字並沒有辦法得到 personal access token 的值,所以沒什麼問題呀。

travis.yml 裏面寫的 secure 是用 travis 提供的公鑰加密的,從而只有 travis 能解密看到 secure 裏的內容,別人即使看到了 travis.yml 的 secure 也沒法解密得到我的 token ,從而不可能代替我操作 travis ,這樣就沒問題了吧。

farseerfc commented 7 years ago

@SketchK 對了,我博客裏寫了 git push 需要 --quiet 否則 git push 的輸出裏面會把 token 作爲 URL 的一部分顯示出來,這加密就沒有意義了…… 我已經在你的 travis 頁面的 log 看到你的 token 了,快去吊銷 token 。

SwiftSIQI commented 7 years ago

@farseerfc 我明白了!之前对 Personal Access Token 和 Environment Variables 的理解没到位,以为是一个任何人都可以用的东西,刚才突然想明白,这个东西其实是 Travis CI 在配置环境时的一个系统变量,也只有我的项目里面才会有这个环境变量,即使别人知道了我的那个 Environment Variables 的 name , 在他自己的那个环境里面也没有用,因为它拿不到那个 value 对吧? 一会就去换 token,目前正在做测试,所以还是要看下报错信息啥的。。。

farseerfc commented 7 years ago

@SketchK 嗯對沒錯~

SwiftSIQI commented 7 years ago

@farseerfc 超级感谢!!!

PoiScript commented 7 years ago

@SketchK 抱歉来晚了... 不过看来讨论已经结束了

你问的 push 命令是我在另外一家 CI 服务的公司 AppVeyor 的文档里面发现的: https://www.appveyor.com/docs/how-to/git-push/

MichaelXoXo commented 5 years ago

帅气,我也搞定了 Travis CI 自动部署:https://michael728.github.io/2019/06/16/cicd-hexo-blog-travis/