<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>GitHub on Harry&#39;s Blog</title>
    <link>https://sudo-djug.xyz/tags/github/</link>
    <description>Recent content in GitHub on Harry&#39;s Blog</description>
    <generator>Hugo</generator>
    <language>zh-cn</language>
    <lastBuildDate>Sat, 18 Feb 2023 00:00:00 +0800</lastBuildDate>
    <atom:link href="https://sudo-djug.xyz/tags/github/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>GitHub Actions自动化部署初体验</title>
      <link>https://sudo-djug.xyz/posts/2023-02-18-github-actions-deploy/</link>
      <pubDate>Sat, 18 Feb 2023 00:00:00 +0800</pubDate>
      <guid>https://sudo-djug.xyz/posts/2023-02-18-github-actions-deploy/</guid>
      <description>&lt;h1 id=&#34;github-actions自动化部署初体验&#34;&gt;GitHub Actions自动化部署初体验&lt;/h1&gt;
&lt;p&gt;之前每次改完博客都要手动 &lt;em&gt;build&lt;/em&gt; 再 &lt;em&gt;rsync&lt;/em&gt; 到服务器，步骤虽然不多，但重复多了也烦。今天学习了一下 &lt;em&gt;GitHub Actions&lt;/em&gt;，把部署流程自动化了。&lt;/p&gt;
&lt;p&gt;核心思路很简单：代码 &lt;em&gt;push&lt;/em&gt; 到 &lt;em&gt;main&lt;/em&gt; 分支 → 触发 &lt;em&gt;workflow&lt;/em&gt; → 执行 &lt;em&gt;hugo&lt;/em&gt; 构建 → &lt;em&gt;rsync&lt;/em&gt; 到 &lt;em&gt;VPS&lt;/em&gt;。&lt;/p&gt;
&lt;p&gt;&lt;code&gt;.github/workflows/deploy.yml&lt;/code&gt; 的关键配置：&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;on:
  push:
    branches: [main]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: peaceiris/actions-hugo@v2
      - run: hugo --minify
      - run: rsync -avz ./public/ user@host:/var/www/...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;踩了一个坑：&lt;em&gt;rsync&lt;/em&gt; 需要 &lt;em&gt;SSH&lt;/em&gt; 密钥，要把私钥存到仓库的 &lt;em&gt;Secrets&lt;/em&gt; 里，然后在 workflow 里引用。一开始密钥格式没弄对，报错 &lt;em&gt;Load key invalid format&lt;/em&gt;，后来删掉多余的换行才解决。&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;现在每次写完文章，&lt;em&gt;git push&lt;/em&gt; 之后等一分钟，网站就自动更新了。自动化果然是第一生产力。&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
