{"id":597,"date":"2019-09-08T16:29:12","date_gmt":"2019-09-08T16:29:12","guid":{"rendered":"https:\/\/www.haoyuan.info\/?p=597"},"modified":"2019-09-08T16:29:12","modified_gmt":"2019-09-08T16:29:12","slug":"github-pages-vuepress-travis-ci-%e5%ae%9e%e7%8e%b0%e8%87%aa%e5%8a%a8%e9%83%a8%e7%bd%b2%e6%96%87%e6%a1%a3","status":"publish","type":"post","link":"https:\/\/haoyuan.info\/?p=597","title":{"rendered":"Github Pages + VuePress + Travis CI \u5b9e\u73b0\u81ea\u52a8\u90e8\u7f72\u6587\u6863"},"content":{"rendered":"<p>\u60f3\u7740\u6309\u7167\u7f51\u4e0a\u7684\u6559\u7a0b\u76f4\u63a5\u90e8\u7f72\u7684<a href=\"https:\/\/zhuanlan.zhihu.com\/p\/36390666\">https:\/\/zhuanlan.zhihu.com\/p\/36390666<\/a>&#8230; \u4e0d\u77e5\u9053\u600e\u4e48\u603b\u662f\u51fa\u9519<\/p>\n<p>\u4e8e\u662f\u7528\u4e86\u5176\u4ed6\u7684\u65b9\u6cd5\u5b9e\u73b0\u4e86\u8fd9\u4e2a\u8fc7\u7a0b<\/p>\n<h2>\u51c6\u5907<\/h2>\n<ul>\n<li>Git<\/li>\n<li>Github repo<\/li>\n<li>openssl<\/li>\n<li>travis<\/li>\n<li>travis-ci<\/li>\n<\/ul>\n<h2>\u6dfb\u52a0travis.yml<\/h2>\n<p>\u5efa\u7acb\u4e00\u4e2atravis.yml\u6a21\u677f:<\/p>\n<pre><code class=\"language-yaml line-numbers\">language: node_js\nsudo: required\nnode_js:\n- node\nbranch: master\ncache:\n  directories:\n  - node_modules\nbefore_install:\n\nscript:\n\ndist: xenial\n<\/code><\/pre>\n<h2>\u6dfb\u52a0Deploy key<\/h2>\n<p>\u5230\u76ee\u6807\u4ed3\u5e93\uff0c\u5728\u4ed3\u5e93\u8bbe\u7f6e\u4e2d\u6dfb\u52a0deploy key\u3002<br \/>\n\u5728\u672c\u5730\u4f7f\u7528<code>ssh-keygen<\/code>\u751f\u6210key<\/p>\n<pre><code class=\"language-shell line-numbers\">ssh-keygen -t rsa -C \"your_email@example.com\"\n<\/code><\/pre>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4f1a\u5728<code>~\/.ssh<\/code>\u751f\u6210\u4e24\u4e2a\u6587\u4ef6:<code>id_rsa<\/code>\u548c<code>id_rsa.pub<\/code>\u3002\u5c06<code>id_rsa.pub<\/code>\u7684\u5185\u5bb9\u7c98\u8d34\u5230Github\u7684deploy key\u5904\uff0c<strong>\u8981\u52fe\u9009&#8217;Allow write access&#8217;<\/strong><\/p>\n<h2>\u5b89\u88c5travis<\/h2>\n<p><strong>\u6839\u636e\u60c5\u51b5\uff0c\u4e0b\u5217\u547d\u4ee4\u4e2d\u4f60\u53ef\u80fd\u4e0d\u9700\u8981\u7528<code>--pro<\/code>\u8fd9\u4e2aarg,\u8bf7\u77e5\u6089<\/strong><br \/>\n\u4f7f\u7528gem\u5b89\u88c5travis cli,\u8fd9\u4e2a\u53ef\u4ee5\u53c2\u770b\u7f51\u4e0a\u6559\u7a0b<\/p>\n<p>\u767b\u5f55travis<\/p>\n<pre><code class=\"language-shell line-numbers\">gem install travis\ntravis login --auto --pro\n<\/code><\/pre>\n<p>\u4f7f\u7528travis\u52a0\u5bc6\u751f\u6210\u79c1\u94a5\u6587\u4ef6<\/p>\n<pre><code class=\"language-shell line-numbers\">travis encrypt-file id_rsa --add -r your_account\/your_repo --pro --com\n<\/code><\/pre>\n<p>\u6ce8\u610f\uff0c\u6211\u7684\u8d26\u53f7\u8981\u52a0\u4e0a&#8211;pro\uff0c\u7531\u4e8etravis-ci\u4eceorg\u8fc1\u79fb\u81f3com\u7ed3\u5c3e\u7684\u57df\uff0c\u56e0\u6b64\u8981\u52a0<code>--com<\/code><\/p>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u81ea\u52a8\u751f\u6210<code>before_install<\/code>\u7684\u90e8\u5206\u3002<\/p>\n<pre><code class=\"language-yaml line-numbers\">before_install:\n- openssl aes-256-cbc -K $encrypted_xxxxxxxx_key -iv $encrypted_xxxxxxxx_iv\n  -in id_rsa.enc -out ~\/.ssh\/id_rsa -d\n<\/code><\/pre>\n<p>\u5176\u4e2d\u6709\u4e24\u4e2a\u5173\u952e\u7684<code>key<\/code>\u503c\u4f1a\u4f20\u5230travis-ci\u5bf9\u5e94\u7684repo\u4e0a\uff0c\u5c31\u662fencrypt_xxx_key\u548cencrypt_xxx_iv \u8fd9\u4e2a\u4f1a\u6dfb\u52a0\u5230travis-ci\u7684repo\u4e2d\u7684environment variable\u4e2d\u3002<\/p>\n<p>\u5728\u6839\u76ee\u5f55\u521b\u5efa<code>.travis<\/code>\u6587\u4ef6\u5939\uff0c\u5e76\u628a\u521a\u624d\u7528\u547d\u4ee4\u540c\u65f6\u751f\u6210\u7684<code>id_rsa.enc<\/code>\u653e\u5165\u6587\u4ef6\u5939\u4e2d\uff0c\u66f4\u6539\u521a\u624d\u7684\u547d\u4ee4\u4e3a<\/p>\n<pre><code class=\"language-yaml line-numbers\">before_install:\n- openssl aes-256-cbc -K $encrypted_xxxxxxxx_key -iv $encrypted_xxxxxxxx_iv\n  -in .travis\/id_rsa.enc -out ~\/.ssh\/id_rsa -d\n<\/code><\/pre>\n<p>\u5728\u8be5\u6587\u4ef6\u5939\u4e0b\u521b\u5efa\u6587\u4ef6ssh_config<\/p>\n<pre><code class=\"line-numbers\">Host github.com\n  User git\n  StrictHostKeyChecking no\n  IdentityFile ~\/.ssh\/id_rsa\n  IdentitiesOnly yes\n<\/code><\/pre>\n<p>\u5b8c\u5584before_install<\/p>\n<pre><code class=\"language-yaml line-numbers\">before_install:\n- openssl aes-256-cbc -K $encrypted_xxxxxxxx_key -iv $encrypted_xxxxxxxx_iv\n  -in .travis\/id_rsa.enc -out ~\/.ssh\/id_rsa -d\n# Set the permission of the key\n- chmod 600 ~\/.ssh\/id_rsa\n# Start SSH agent\n- eval $(ssh-agent)\n# Add the private key to the system\n- ssh-add ~\/.ssh\/id_rsa\n# Copy SSH config\n- cp .travis\/ssh_config ~\/.ssh\/config\n\n- git config --global user.name 'your_name'\n- git config --global user.email 'your@email.com'\n<\/code><\/pre>\n<p>\u5728\u6839\u76ee\u5f55\u521b\u5efa<code>deploy<\/code>\u6587\u4ef6\u5939\uff0c\u5728\u5176\u4e2d\u6dfb\u52a0<code>deploy.sh<\/code>\u6587\u4ef6<\/p>\n<pre><code class=\"language-shell line-numbers\">#!\/usr\/bin\/env sh\n\n# \u786e\u4fdd\u811a\u672c\u629b\u51fa\u9047\u5230\u7684\u9519\u8bef\nset -e\n\n# \u751f\u6210\u9759\u6001\u6587\u4ef6\nnpm run docs:build\n\ngit clone https:\/\/github.com\/CUP-ACM-Programming-Club\/CUPACM-Docs.git -b gh-pages pages\nrm -rf pages\/*.html\nrm -rf pages\/assets\nrm -rf pages\/dist\ncp -r docs\/.vuepress\/dist\/* pages\ncd pages\ngit add -A\ngit commit -m \"deploy `TZ=UTC-8 date +'%Y-%m-%d %H:%M:%S'`\"\ngit config user.email 'your@email'\ngit config user.name 'your_name'\ngit push -f git@github.com:CUP-ACM-Programming-Club\/CUPACM-Docs.git gh-pages\n\ncd -\n<\/code><\/pre>\n<p>\u4ee5\u4e0a\u5185\u5bb9\u8bf7\u6839\u636e\u81ea\u8eab\u9700\u8981\u66f4\u6539<br \/>\n\u6267\u884c\u547d\u4ee4<\/p>\n<pre><code class=\"language-shell line-numbers\">git update-index --chmod=+x .\/deploy\/deploy.sh\n<\/code><\/pre>\n<p>\u5728<code>install<\/code>\u6dfb\u52a0\u6267\u884c\u4ee3\u7801<\/p>\n<pre><code class=\"language-yaml line-numbers\">install:\n- .\/deploy\/deploy.sh\n<\/code><\/pre>\n<p>\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728PR\u7684\u65f6\u5019encrypt_xxxx\u8fd9\u4e24\u4e2a\u53d8\u91cfTravis CI\u662f\u4e0d\u4f1a\u4f20\u5165\u865a\u62df\u673a\u5b9e\u4f8b\u7684\uff0c\u56e0\u6b64\u5982\u679c\u6309\u7167\u6b63\u5e38\u7684\u6d41\u7a0b\u8fd9\u4e2a\u8fc7\u7a0b\u662f\u4e0d\u4f1a\u8fdb\u884c\u81ea\u52a8\u90e8\u7f72\u7684\u3002\u6211\u4eec\u4e5f\u4e0d\u5e0c\u671b\u5728PR\u524d\u4efb\u4f55fork\u5206\u652f\u90fd\u88ab\u6267\u884c\u81ea\u52a8\u90e8\u7f72\u5230\u4e3b\u5206\u652f\u4e2d\u53bb\u3002<\/p>\n<p>\u56e0\u6b64\u7528\u6761\u4ef6\u5224\u65ad\u8bed\u53e5\u505a\u4ee5\u4e0b\u5904\u7406<\/p>\n<pre><code class=\"language-yaml line-numbers\">before_install:\n- '[[ -n ${encrypted_xxxxxxx_iv+x} ]] &amp;&amp; openssl aes-256-cbc -K $encrypted_xxxxxx_key -iv $encrypted_xxxxxx_iv\n  -in .travis\/id_rsa.enc -out ~\/.ssh\/id_rsa -d &amp;&amp; chmod 600 ~\/.ssh\/id_rsa &amp;&amp; eval $(ssh-agent) &amp;&amp; ssh-add ~\/.ssh\/id_rsa &amp;&amp; cp .travis\/ssh_config ~\/.ssh\/config\n  || echo \"Pull Request mode\"'\n- git config --global user.name 'yourname'\n- git config --global user.email your@email.com'\n- export TZ='Asia\/Shanghai'\nscript:\n- '[[ -n ${encrypted_xxxxxx_iv+x} ]] &amp;&amp; chmod a+x .\/deploy\/deploy.sh &amp;&amp; .\/deploy\/deploy.sh || npm run docs:build'\n<\/code><\/pre>\n<p>\u8fd9\u6837\u95ee\u9898\u5c31\u80fd\u5f97\u5230\u89e3\u51b3\u3002<\/p>\n<p>\u7136\u540e\u6839\u636e\u4e0a\u9762\u7684shell\uff0c\u6211\u4eec\u4f1a\u628aPage push\u5230gh-pages\u5206\u652f\u4e0a\u3002\u56e0\u6b64\u8981\u5728repo\u7684setting\u4e2d\u8bbe\u7f6eGithub Pages\u5206\u652f\u4e3agh-pages<\/p>\n<p>\u5b8c\u6210<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u60f3\u7740\u6309\u7167\u7f51\u4e0a\u7684\u6559\u7a0b\u76f4\u63a5\u90e8\u7f72\u7684https:\/\/zhuanlan.zhihu.com\/p\/36390666&#038;#82 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[65,66,67],"tags":[9,69,68],"class_list":["post-597","post","type-post","status-publish","format-standard","hentry","category-git","category-travis-ci","category-vuepress","tag-github","tag-travis-ci","tag-vuepress"],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8UC2c-9D","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/597","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=597"}],"version-history":[{"count":0,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/597\/revisions"}],"wp:attachment":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}