D.A.
D.A.

Reputation: 140

Github deploy pages from private repo with actions

I am trying to get a public github page from a private source repo following this tutorial which utilizes PUBLIC and PRIVATE key variables from ssh-keygen -t rsa -b 4096 -C "$(git config user.email)" -f deployment -N ""

I have the same setup as described in the link, but I am not able to wrap my head around what is actually not working.

By using the same GitHub action

name: Github Pages

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  deploy:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true  # Fetch Hugo themes (true OR recursive)
          fetch-depth: 0    # Fetch all history for .GitInfo and .Lastmod

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: '0.83.0'

      - name: Build
        run: hugo --minify

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          deploy_key: ${{ secrets.PRIVATE_KEY }}
          external_repository: <username/username.github.io>
          publish_dir: ./public

It does not build because

Error: Unable to locate config file or config directory. Perhaps you need to create a new site.Run `hugo help new` for details.

Then I replaced the entire workflow with the one suggested by [Hugo] (https://gohugo.io/hosting-and-deployment/hosting-on-github/) which is much more recent. I then added to the last deployment action

   steps:
       - name: Deploy to GitHub Pages
         id: deployment
         uses: actions/deploy-pages@v2
         with:
           deploy_key: ${{ secrets.PRIVATE_KEY }}
           external_repository: <username/username.github.io>
           publish_dir: ./public

which fails with

Error: Get Pages site failed. Please verify that the repository has Pages enabled and configured to build using GitHub Actions, or consider exploring the `enablement` parameter for this action. Error: HttpError: Not Found

I have set up both deploy keys and private keys as well as the urls seems to be correct and in the public repo I have the following setup for pages

Deploy from branch, brain main and /root. In the previous tutorial they mention a gh-page source but it is not available (I have nothing else beside main). Should there be an additional branch?

Sorry for the long post and thanks for any help!

Upvotes: 0

Views: 1821

Answers (1)

RandomWalker
RandomWalker

Reputation: 831

I was searching for similar GH action workflows that allow deployment from a private repo to a public one. I came across this post which has a workflow that is very close to yours. The workflow works perfectly for my purpose. I include it in the following. The only difference I can see is the Deploy section. In my case, there is a publish_branch variable, although this probably is not directly related to the issue.

On the other hand, base on the first error message, perhaps you want to check if you have config.yml or config.toml defined in the root directory of your source repo. Also remember to put .nojekyll in the root of the gh-pages branch.

name: github pages

on:
  push:
    branches:
      - main  # Set a branch to deploy
  pull_request:

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true  # Fetch Hugo themes (true OR recursive)
          fetch-depth: 0    # Fetch all history for .GitInfo and .Lastmod

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: 'latest'
          extended: true

      - name: Build
        run: hugo --minify

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          deploy_key: ${{ secrets.PRIVATE_KEY }}
          external_repository: your_github_username/your_github_username.github.io
          publish_branch: gh-pages
          publish_dir: ./public

Upvotes: 0

Related Questions