Jekyll 使用 private repo 建立 gh-pages
免費版的 github 建立 gh-pages 必須公開 repository。 如果想省錢又不想把 markdown 直接公諸於世該怎麼辦?
目標
本文使用 jekyll , 透過一個 private repository (原始碼), 搭配一個 public repository (產出的 html), 來達到目標。
graph LR
subgraph client
A[source code]
end
A[source code] -->|git push| B(private repo)
subgraph github
B -->|"deploy(by action)"| D[public repo]
end
步驟
- 先到 github 上建立好兩個 repo 。例如:myblog_private, myblog_public,
- 加入 github action,並 push 到 myblog_private
# .github/workflows/jekyll.yml name: Deploy Jekyll site to Pages on: push: branches: ["main"] workflow_dispatch: permissions: contents: read pages: write id-token: write concurrency: group: "pages" cancel-in-progress: true jobs: deploy: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 - name: Setup Ruby uses: ruby/setup-ruby@v1 with: ruby-version: '3.0' bundler-cache: true cache-version: 0 # Increment this number if you need to re-download cached gems - name: Build with Jekyll run: bundle exec jekyll build env: JEKYLL_ENV: production - name: Upload artifact uses: actions/upload-pages-artifact@v1 - name: Deploy to GitHub Pages 🚀 uses: peaceiris/actions-gh-pages@v3 with: deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} external_repository: mygithub/myblog_public publish_branch: main publish_dir: ./_site
- 產生一組 gh-pages 專用的 public key 和 private key
ssh-keygen -t rsa -b 4096 -C "$(git config user.email)" -f gh-pages -N ""
- public key: gh-pages.pub
- private key: gh-pages
- 把 private key 加到 private repo 的 secerts 中,並取名為
ACTIONS_DEPLOY_KEY
- 把 public key 加到 public repo 的 deploy keys 中
留言