tw4ld6 发表于 2024-10-3 05:23:34

Github Action协同Hexo连续集成博客


    <h1 style="color: black; text-align: left; margin-bottom: 10px;">Github Action<span style="color: black;">协同</span>Hexo<span style="color: black;">连续</span>集成博客</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;"><span style="color: black;">经过</span>Hexo写博客,<span style="color: black;">按照</span>Hexo文档安装hexo并且找一个自己<span style="color: black;">爱好</span>的主题,<span style="color: black;">安排</span>在GitPage上,节省<span style="color: black;">咱们</span>自己的服务器资源</span></span></span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">新建Github仓库</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">新建github仓库,如</span><span style="color: black;">hexo-blog</span> ,仓库<span style="color: black;">倘若</span>要<span style="color: black;">安排</span>gitpage<span style="color: black;">不可</span><span style="color: black;">选取</span>private。</span></span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">新建Hexo目录</h1>hexo&nbsp;<span style="color: black;">init</span>&nbsp;hexo-blog<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">正常配置hexo和hexo主题并<span style="color: black;">起始</span>写作,写作完成后:</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;"><span style="color: black;"><span style="color: black;">倘若</span>你的主题文件夹theme中有.git文件夹,请将其删除后再push代码</span></span></span></span></p>git&nbsp;init
    git&nbsp;add&nbsp;.
    git&nbsp;<span style="color: black;">commit</span>&nbsp;-m&nbsp;<span style="color: black;">"first&nbsp;commit"</span>
    git&nbsp;branch&nbsp;-M&nbsp;<span style="color: black;">main</span>
    git&nbsp;remote&nbsp;<span style="color: black;">add</span>&nbsp;origin&nbsp;git@github.com:xxxx/hexo-blog&nbsp;(xxx是你的github用户名)
    git&nbsp;push&nbsp;-u&nbsp;origin&nbsp;<span style="color: black;">main</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">新建Git Page仓库</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">在Github中新建一个仓库,仓库名为:</span></span></span></p>&lt;你的Git用户名&gt;.github.<span style="color: black;">io</span>//用户名
    如:&nbsp;sawyersven.github.<span style="color: black;">io</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">至此准备工作完成,</span><span style="color: black;">hexo-blog</span>仓库存放博客的源码,xxx.github.io仓库存放打包生成的静态资源,下边<span style="color: black;">起始</span>配置CI</span></span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">配置hexo deploy</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">添加hexo的git deploy依赖:</span></span></span></p>npm&nbsp;<span style="color: black;">install</span>hexo-deployer-git&nbsp;&nbsp;&nbsp;/&nbsp;yarn<span style="color: black;">add</span>&nbsp;hexo-deployer-git<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">在hexo-blog根目录的</span><span style="color: black;">_config.yml</span>文件中找到deploy字段并添加:</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">type为git(必须是git)</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">repo是要发布的repo的<span style="color: black;">位置</span></span></span></span></p>...
    deploy:
    &nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">type</span>:&nbsp;<span style="color: black;">git</span>
    &nbsp;&nbsp;&nbsp;&nbsp;repo:&nbsp;<span style="color: black;">git@github.com:&lt;gitusername&gt;/&lt;gitusername&gt;.github.io.git</span>
    ...<h1 style="color: black; text-align: left; margin-bottom: 10px;">配置Github Action</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">GithubAction的</span><span style="color: black;">文档</span></span></span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">配置workflows</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">在</span><span style="color: black;">hexo-blog</span>项目根目录下创建一个<span style="color: black;">.github\workflows</span>结构的目录,<span style="color: black;">而后</span>新建一个yml文件:</span></span></p>mkdir&nbsp;-p&nbsp;.github/workflows<span style="color: black;">cd</span>&nbsp;./github/workflows&nbsp;
    touch&nbsp;main.yml<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;"><span style="color: black;">而后</span><span style="color: black;">咱们</span>编辑main.yml:</span></span></span></p>name:&nbsp;Deploy&nbsp;&nbsp;<span style="color: black;">#随便取</span>
    on:
    &nbsp;&nbsp;push:
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;branches:&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;当main<span style="color: black;">或</span>master分支被push到远端仓库的时候,触发ci</span>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;main&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;master
    &nbsp;jobs:
    &nbsp;&nbsp;build:
    &nbsp;&nbsp;&nbsp;&nbsp;runs-on:&nbsp;ubuntu-latest&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;在ubuntu下执行后续的操作</span>steps:
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;name:&nbsp;Checkout&nbsp;Respository&nbsp;master&nbsp;branch<span style="color: black;">#actions/checkout&nbsp;checkout到$GITHUB_WORKSPACE下的repo&nbsp;&nbsp;默认为当前repo</span>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uses:&nbsp;actions/checkout@master
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;name:&nbsp;Setup&nbsp;Node.js&nbsp;14.x&nbsp;<span style="color: black;">#&nbsp;安装node14</span>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uses:&nbsp;actions/setup-node@master
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">with</span>:
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;node-<span style="color: black;">version</span>:&nbsp;<span style="color: black;">14.17.3</span>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;<span style="color: black;">name</span>:&nbsp;<span style="color: black;">Cache</span>&nbsp;node&nbsp;modules&nbsp;&nbsp;<span style="color: black;">#&nbsp;缓存依赖<span style="color: black;">增多</span>工作流的执行速度</span>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uses:&nbsp;actions/<span style="color: black;">cache</span>@v1
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">id</span>:&nbsp;<span style="color: black;">cache</span>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">with</span>:
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">path</span>:&nbsp;node_modules
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">key</span>:&nbsp;${{&nbsp;runner.os&nbsp;}}-node-${{&nbsp;hashFiles(<span style="color: black;">**/.json</span>)&nbsp;}}&nbsp;&nbsp;<span style="color: black;">#&nbsp;<span style="color: black;">这儿</span><span style="color: black;">按照</span>用的包管理工具切换lock文件,hashFile会为匹配的文件计算SHA-256哈希值</span>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">restore</span>-<span style="color: black;">keys</span>:&nbsp;|
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${{runner.os}}-node-
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;<span style="color: black;">name</span>:&nbsp;Setup&nbsp;Hexo&nbsp;Dependencies&nbsp;<span style="color: black;">#&nbsp;安装hexo-cli&nbsp;并且安装依赖</span>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;run:&nbsp;|
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;npm&nbsp;<span style="color: black;">install</span>hexo-cli&nbsp;-g
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;npm<span style="color: black;">install</span>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;<span style="color: black;">name</span>:&nbsp;Setup&nbsp;Deploy&nbsp;<span style="color: black;">Private</span>&nbsp;<span style="color: black;">Key</span>&nbsp;&nbsp;<span style="color: black;">#&nbsp;给ubuntu环境添加ssh的私钥,先按<span style="color: black;">这儿</span>填,后边单独讲</span>env:
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HEXO_DEPLOY_PRIVATE_KEY:&nbsp;${{secrets.HEXO_DEPLOY_PRI}}
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;run:&nbsp;|
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mkdir&nbsp;-p&nbsp;~/.ssh/
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo<span style="color: black;">"$HEXO_DEPLOY_PRIVATE_KEY"</span>&nbsp;&gt;&nbsp;~/.ssh/id_rsa
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chmod&nbsp;<span style="color: black;">600</span>~/.ssh/id_rsa
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ssh-keyscan&nbsp;github.com&nbsp;&gt;&gt;&nbsp;~/.ssh/know_hosts
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-<span style="color: black;">name</span>:&nbsp;Setup&nbsp;Git&nbsp;Infomation&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;hexo&nbsp;deploy必须有git&nbsp;user.name和git&nbsp;user.email<span style="color: black;">才可</span>运行</span>run:&nbsp;|
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;git&nbsp;config<span style="color: black;">--global&nbsp;user.name&nbsp;"sawyersven"</span>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;git&nbsp;config&nbsp;<span style="color: black;">--global&nbsp;user.email&nbsp;"kormondor@gmail.com"</span>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;<span style="color: black;">name</span>:&nbsp;Deploy&nbsp;Hexo
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;run:&nbsp;|
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hexo&nbsp;clean
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hexo&nbsp;generate
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hexo&nbsp;deploy<h1 style="color: black; text-align: left; margin-bottom: 10px;">配置SSH key</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;"><span style="color: black;">由于</span>是,在</span><span style="color: black;">hexo-blog</span>的仓库中提交代码<span style="color: black;">而后</span>构建到了<span style="color: black;">xxx.github.io</span>的仓库中,<span style="color: black;">因此</span>需要把SSH key配置在执行action的ubuntu环境中</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;"><span style="color: black;">首要</span>在命令行中执行:</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;"><span style="color: black;">设置filename的时候<span style="color: black;">意见</span>设置为github_id_rsa<span style="color: black;">或</span>其他名<span style="color: black;">叫作</span>,以便区分</span></span></span></span></p>ssh-keygen&nbsp;&nbsp;&nbsp;#&nbsp;生成的key默认在~<span style="color: black;">/.ssh/gi</span>thub_id_rsa,windows在C:<span style="color: black;">/User/</span>&lt;username&gt;<span style="color: black;">/.ssh/gi</span>thub_id_rsa<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;"><span style="color: black;">而后</span>将公钥上传到github的ssh key中:</span><span style="color: black;">点我直达配置页</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;"><span style="color: black;">选取</span></span><span style="color: black;">New SSH key</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">title : 任意填</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">key: 用记事本或编辑器打开</span><span style="color: black;">github_id_rsa.pub</span>,将里面的文本粘贴进去.</span></span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">配置Action Secrets</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;"><span style="color: black;">因为</span>workflow的文件是在代码仓库中,脚本中的内容是对仓库可见的,<span style="color: black;">倘若</span><span style="color: black;">咱们</span>将<span style="color: black;">有些</span>隐私内容直接明文写在文件中,会被<span style="color: black;">泄密</span>。<span style="color: black;">因此</span>github<span style="color: black;">供给</span>了Action secrect来帮<span style="color: black;">咱们</span>存放<span style="color: black;">敏锐</span>信息。在Actions中<span style="color: black;">经过</span>${{secrets.}}<span style="color: black;">就可</span>获取</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">进入</span><span style="color: black;">blog-hexo</span>的repo中,点击<span style="color: black;">settings</span>,<span style="color: black;">而后</span>在侧边栏<span style="color: black;">选取</span><span style="color: black;">Secrets</span>-<span style="color: black;">Actions</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;"><span style="color: black;">而后</span><span style="color: black;">选取</span></span><span style="color: black;">New repository secret</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">name中填写HEXO_DEPLOY_PRI</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">value将</span><span style="color: black;">github_id_rsa</span>的内容复制后粘贴进去<span style="color: black;">就可</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">至此github Action的配置就完<span style="color: black;">成为了</span>,<span style="color: black;">能够</span>尝试更新</span><span style="color: black;">hexo-blog</span>的代码并push到github,<span style="color: black;">而后</span>观察Action中job的执行<span style="color: black;">状况</span>.</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;"><span style="color: black;">而后</span><span style="color: black;">拜访</span>xxx.github.io<span style="color: black;">就可</span>查看效果。</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;"><span style="color: black;"><span style="color: black;">这儿</span>不<span style="color: black;">意见</span>将本机正在<span style="color: black;">运用</span>的ssh密钥对上传到github中,尤其是私钥.</span></span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;"><span style="color: black;">到<span style="color: black;">这儿</span>配置就完<span style="color: black;">成为了</span>,后文是<span style="color: black;">有些</span>知识点的<span style="color: black;">弥补</span>,可<span style="color: black;">选取</span>阅读</span></span></span></span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">弥补</span>阅读</h1>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">main.yml中的Setup Deploy Private Key</h1>-&nbsp;name:&nbsp;Setup&nbsp;Deploy&nbsp;Private&nbsp;Key<span style="color: black;">#&nbsp;给ubuntu环境添加ssh的私钥,先按<span style="color: black;">这儿</span>填,后边单独讲</span>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;env:
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HEXO_DEPLOY_PRIVATE_KEY:&nbsp;<span style="color: black;">${{secrets.HEXO_DEPLOY_PRI}</span>}&nbsp;&nbsp;<span style="color: black;">#&nbsp;设置环境变量</span>run:&nbsp;|
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mkdir&nbsp;-p&nbsp;~/.ssh/<span style="color: black;">echo</span>&nbsp;<span style="color: black;">"<span style="color: black;">$HEXO_DEPLOY_PRIVATE_KEY</span>"</span>&nbsp;&gt;&nbsp;~/.ssh/id_rsa
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chmod&nbsp;600&nbsp;~/.ssh/id_rsa
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ssh-keyscan&nbsp;github.com&nbsp;&gt;&gt;&nbsp;~/.ssh/know_hosts<h1 style="color: black; text-align: left; margin-bottom: 10px;">拆分理解</h1>mkdir&nbsp;-p&nbsp;~<span style="color: black;">/.ssh/</span><p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">创建.ssh文件夹</span></span></span></p>&nbsp;<span style="color: black;">echo</span>&nbsp;<span style="color: black;">"<span style="color: black;">$HEXO_DEPLOY_PRIVATE_KEY</span>"</span>&nbsp;&gt;&nbsp;~/.ssh/id_rsa<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">读取环境变量$HEXO_DEPLOY_PRIVATE_KEY的值,并将其写入id_rsa中 , 其实这步操作约等于<span style="color: black;">咱们</span>在本地生成ssh key并将公钥上传到github的ssh key中,只是<span style="color: black;">次序</span>对调了<span style="color: black;">罢了</span>。</span></span></span></p>chmod&nbsp;<span style="color: black;">600</span>&nbsp;~<span style="color: black;">/.ssh/i</span>d_rsa<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">设置文件权限为<span style="color: black;">持有</span>者可读写,其他人不可读写执行</span></span></span></p>ssh-keyscan&nbsp;github.com&nbsp;&gt;&gt;&nbsp;~<span style="color: black;">/.ssh/</span>know_hosts<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">收集github.com的公钥并将其写入know_hosts,避免被openSSH警告</span></span></span></p><h1 style="color: black; text-align: left; margin-bottom: 10px;">将Gitpage解析到自己的域名</h1><p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">在购买域名的服务商中添加新的CNAME解析,解析值填为:xxx.github.io (你的gitpage的<span style="color: black;">拜访</span><span style="color: black;">位置</span>)</span></span></span></p><p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">进入gitpage的仓库,并点击settings</span></span></span></p><div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/211533c6f2a3494fa1827019fc6ca97d~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728086120&amp;x-signature=T9kv8GepF2wm1vIO3U8X5BHfS%2Fs%3D" style="width: 50%; margin-bottom: 20px;"></div><p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">image-20220715224453906</p><p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在custom domain中填写刚才解析的<span style="color: black;">位置</span>,github会校验域名的解析<span style="color: black;">是不是</span>是gitpage,<span style="color: black;">倘若</span>是就会successful.</p><p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">这个时候<span style="color: black;">拜访</span>你解析的<span style="color: black;">位置</span>,就<span style="color: black;">能够</span>看到你的Github Page被解析过去了。</span></span></span></p><h1 style="color: black; text-align: left; margin-bottom: 10px;">CNAME文件</h1><p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;"><span style="color: black;">发掘</span>每次提交以后设置的Customer domain会被清除掉</span></span></span></p><p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;"><span style="color: black;">因此</span><span style="color: black;">运用</span>CNAME文件<span style="color: black;">守护</span></span></span></span></p><p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">在hexo-blog的source文件夹下创建一个CNAM的文件,内容如下:</span></span></span></p>
<span style="color: black;">blog</span><span style="color: black;">.sawyersven</span><span style="color: black;">.xyz</span>&nbsp;&nbsp;#&nbsp;<span style="color: black;">仅有</span>一行代码,<span style="color: black;">便是</span>你要解析的自定义域名
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;"><span style="color: black;">而后</span>每次deploy后就<span style="color: black;">不消</span>手动<span style="color: black;">调节</span>custom domain了</span></span></span></p>

b1gc8v 发表于 2024-10-16 01:22:18

回顾过去一年,是艰难的一年;展望未来,是辉煌的一年。

4lqedz 发表于 2024-10-29 18:27:43

大势所趋,用于讽刺一些制作目的就是为了跟风玩梗,博取眼球的作品。

j8typz 发表于 2024-11-5 17:29:33

“沙发”(SF,第一个回帖的人)‌

7wu1wm0 发表于 2024-11-12 09:36:55

回顾历史,我们感慨万千;放眼未来,我们信心百倍。
页: [1]
查看完整版本: Github Action协同Hexo连续集成博客