Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 GitHub Actions 部署 Hugo 博客到 GitHub Pages #90

Closed
reuixiy opened this issue Aug 9, 2020 · 6 comments
Closed

使用 GitHub Actions 部署 Hugo 博客到 GitHub Pages #90

reuixiy opened this issue Aug 9, 2020 · 6 comments
Labels
Todo 待写的新文章

Comments

@reuixiy
Copy link
Owner

reuixiy commented Aug 9, 2020

  1. 复制 .github 文件夹

  2. 修改 .github/workflows/build.ymlGIT_REPOGIT_BRANCH

  3. 生成 id_rsaid_rsa.pub

    ssh-keygen -t rsa -b 4096 -C "reuixiy@users.noreply.github.com"

    1. id_rsa 的内容复制,添加到源码仓库的 Settings > Secrets > New secret,Name 必须为 GIT_DEPLOY_KEY
    2. id_ras_pub 的内容复制,添加到部署仓库的 Settings > Deploy keys > Add deploy key,Title 随便,可以为 GitHub Pages,务必勾选 Allow write access。
    3. 如果源码仓库和部署仓库为同一仓库,则在同一仓库配置。
  4. static 文件夹下添加一个 CNAME 文件,里面加上自己的域名,如 io-oi.me
    https://docs.github.com/en/github/working-with-github-pages/managing-a-custom-domain-for-your-github-pages-site#configuring-an-apex-domain

  5. git add & git commit & git push

  6. 前往部署仓库,Settings > Options > GitHub Pages,将 Source 中的 Branch 选择为 GIT_BRANCH

  7. 前往域名提供商,修改 DNS 记录,减少第三方 #87 (comment)

  8. 返回部署仓库,将 Enforce HTTPS 勾选

其它:可修改 README.md,加上官方提供的 badge:[![Built on GitHub](https://github.com/reuixiy/io-oi.me/workflows/build/badge.svg)](https://github.com/reuixiy/io-oi.me/actions)

脚注:对于 GitHub Pages,一个是用户的 GitHub Pages,仓库名必须为 <user>.github.io;一个项目的 GitHub Pages,将会部署到 http(s)://<user>.github.io/<repository>https://docs.github.com/en/github/working-with-github-pages/about-github-pages#types-of-github-pages-sites

@reuixiy reuixiy added the Todo 待写的新文章 label Aug 9, 2020
@reuixiy
Copy link
Owner Author

reuixiy commented Aug 9, 2020

Git 删除所有 commits:https://gist.github.com/heiswayi/350e2afda8cece810c0f6116dadbe651

@reuixiy
Copy link
Owner Author

reuixiy commented Aug 11, 2020

使用后,貌似 GitInfo 出了问题,待解决

@reuixiy
Copy link
Owner Author

reuixiy commented Aug 12, 2020

https://github.com/actions/checkout 知,需 set fetch-depth: 0

为什么要使用 checkout 呢?在 entrypoint.sh 上加一行 git clone 不就行了吗?

待验证

@reuixiy
Copy link
Owner Author

reuixiy commented Aug 12, 2020

可以新建一个仓库了,这样就可以将 .github/actions 删除了,build.yml 里直接写 uses: reuixiy/{repo}@master 即可,别人也可以直接用,顺便还能发布一下?

可以直接使用环境变量,这样还能发布到 Docker Hub 上,使用起来也不会仅限于 GitHub Actions。同时,在 Actions 中,还能用 uses: docker://reuixiy/{repo}。只不过,Actions 里 workflow 里配置的是 env,而不是 with

可以使用 Actions 的 Default environment variables,这样在 workflow 里面可以减少配置项。而对于 Actions 外,则只需添加名字相同的环境变量即可。

对于时区,除了目前的这种方法,

ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

还可以通过 TZ 环境变量来实现:

jobs:
  deploy:
    runs-on: ubuntu-latest
    env:
      TZ: Asia/Shanghai

@reuixiy
Copy link
Owner Author

reuixiy commented Aug 14, 2020

往 commit message 中加入 timezone

@reuixiy
Copy link
Owner Author

reuixiy commented Aug 18, 2020

GitInfo 出问题的另一个原因:reuixiy/hugo-theme-meme#27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Todo 待写的新文章
Projects
None yet
Development

No branches or pull requests

1 participant