docusaurus: Github Actions deployment error

🐛 Bug Report

(A clear and concise description of what the bug is) Following the guidelines of GitHub Actions deployment here: https://v2.docusaurus.io/docs/deployment/#deploy The actions fail to build and deploy the site with this error:

 Release to GitHub Pages5s
##[error]Process completed with exit code 1.
Run git config --global user.email "actions@gihub.com"
npm ERR! cipm can only install packages with an existing package-lock.json or npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm@5 or later to generate it, then try again.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2020-05-30T17_04_14_260Z-debug.log
##[error]Process completed with exit code 1.

To Reproduce

  1. Added contents of documentation.yml from https://v2.docusaurus.io/docs/deployment/#deploy to file .github/workflows/documentation.yml in documentation branch of repository
  2. Followed the instructions to generate/deploy ssh key and secret

Expected behavior

successfully build the site and deploy to branch gh-pages

Actual Behavior

The actions fail to build and deploy the site with this error:

 Release to GitHub Pages5s
##[error]Process completed with exit code 1.
Run git config --global user.email "actions@gihub.com"
npm ERR! cipm can only install packages with an existing package-lock.json or npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm@5 or later to generate it, then try again.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2020-05-30T17_04_14_260Z-debug.log
##[error]Process completed with exit code 1.

Your Environment

  • Docusaurus version used: 2.0.0-alpha.56
  • Environment name and version (e.g. Chrome 78.0.3904.108, Node.js 10.17.0): Node v14.2.0
  • Operating system and version (desktop or mobile): Desktop Arch Linux

Reproducible Demo

https://github.com/pdimens/PopGen.jl/tree/documentation/.github/workflows

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 20 (8 by maintainers)

Most upvoted comments

This an example github action that I am using to deploy to gh pages with peaceiris/actions-gh-pages. This action works fine without a new deploy ssh key.

name: deploy

on:
  pull_request:
    branches: [master]
  push:
    branches: [master]

jobs:
  checks:
    if: github.event_name != 'push'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: '12.x'
      - name: Test Build
        run: |
          if [ -e yarn.lock ]; then
          yarn install --frozen-lockfile
          elif [ -e package-lock.json ]; then
          npm ci
          else
          npm i
          fi
          npm run build
  gh-release:
    if: github.event_name != 'pull_request'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: '12.x'
      - name: Build
        run: |
          if [ -e yarn.lock ]; then
          yarn install --frozen-lockfile
          elif [ -e package-lock.json ]; then
          npm ci
          else
          npm i
          fi
          npm run build
      - name: Release to GitHub Pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./build

@anshulrgoyal to follow up, I tried to see if it would make a difference to set up an SSH key for actions@github.com rather than the email account associated with my github account, and that seemed to do the trick. I pushed a minor commit and GitHub Actions finally ran the job successfully. If what I did was the the correct method all along, I recommend adding the specificity in the docusaurus deploy docs of creating an SSH key for actions@github.com .

Following @slorber suggestion, I modified the GitHub Actions workflow to:

name: documentation

on:
  pull_request:
    branches: [documentation]
  push:
    branches: [documentation]

jobs:
  checks:
    if: github.event_name != 'push'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: '12.x'
      - run: npm install -g yarn
      - name: Deploy
        run: |
          yarn install --frozen-lockfile
          yarn build
  gh-release:
    if: github.event_name != 'pull_request'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: '12.x'
      - name: Add key to allow access to repository
        env:
          SSH_AUTH_SOCK: /tmp/ssh_agent.sock
        run: |
          mkdir -p ~/.ssh
          ssh-keyscan github.com >> ~/.ssh/known_hosts
          echo "${{ secrets.GH_PAGES_DEPLOY }}" > ~/.ssh/id_rsa
          chmod 600 ~/.ssh/id_rsa
          cat <<EOT >> ~/.ssh/config
          Host github.com
          HostName github.com
          IdentityFile ~/.ssh/id_rsa
          EOT
      - name: Release to GitHub Pages
        env:
          USE_SSH: true
          GIT_USER: git
        run: |
          git config --global user.email "actions@gihub.com"
          git config --global user.name "gh-actions"
          npm ci
          npx docusaurus deploy

and the result now seems to be an authentication error. I am under the impression that I followed the documentation about this process correctly, but now I’m unsure.

Cloning into 'PopGen.jl-gh-pages'...
Warning: Permanently added the RSA host key for IP address '140.82.112.3' to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Error: Error: git clone failed
    at runDeploy (/home/runner/work/PopGen.jl/PopGen.jl/node_modules/@docusaurus/core/lib/commands/deploy.js:80:19)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
##[error]Process completed with exit code 1.

It wouldn’t work if u have passcode on ssh key

Hey,

Using NPM ?

If you don’t have a package-lock.json file, do you use npm locally?

If yes, have you run npm install locally?

Since npm5, all npm installs normally create a package-lock.json file. Maybe you should upgrade to npm5 if you are using an older version (there are options to create a package-lock.json for older versions afaik)

Have you committed this lockfile? you should.

Using Yarn ?

Then you have a yarn.lock, and it would be better to use yarn in the CI to be sure to use the same versions in dev and CI (those in the lockfile)

So you should replace all NPM commands by yarn equivalent

yarn install --frozen-lockfile , according to https://stackoverflow.com/questions/58482655/what-is-the-closest-to-npm-ci-in-yarn

so when you see:

          run: |
            npm ci
            npm run build

You can replace by:

          run: |
            yarn install --frozen-lockfile
            yarn build

Don’t forget to install yarn in the Github CI first: https://codyogden.blog/yarn-with-github-actions-ci-cd/