Skip to content

GitHub Actions deployment error: "Git push failed" #4336

@mrousavy

Description

@mrousavy

🐛 Bug Report

I am trying to use GitHub actions to automatically build my documentation from the main branch (docs/ folder) and deploy it to the gh-pages branch.

I've followed the official guide, but can't seem to get it working.

Success! Generated static files in build. Use `npm run serve` to test your build locally.

Site successfully built in locale=en
CMD: git clone https://git@github.com/cuvent/react-native-vision-camera.git react-native-vision-camera-gh-pages (code=0)
CMD: git checkout origin/gh-pages (code=0)
CMD: git checkout -b gh-pages (code=0)
CMD: git branch --set-upstream-to=origin/gh-pages (code=0)
CMD: git rm -rf . (code=0)
CMD: git add --all (code=0)
CMD: git commit -m "Deploy website - based on a97a3cf6ec9602e116bdd774c50c85c1f8d89097" (code=0)
CMD: git push --force origin gh-pages (code=128)
/home/runner/work/react-native-vision-camera/react-native-vision-camera/docs/node_modules/@docusaurus/core/lib/commands/deploy.js:145
                throw new Error('Error: Git push failed');
                ^

Error: Error: Git push failed
    at /home/runner/work/react-native-vision-camera/react-native-vision-camera/docs/node_modules/@docusaurus/core/lib/commands/deploy.js:145:23
    at copyDirItems (/home/runner/work/react-native-vision-camera/react-native-vision-camera/docs/node_modules/fs-extra/lib/copy/copy.js:171:21)
    at /home/runner/work/react-native-vision-camera/react-native-vision-camera/docs/node_modules/fs-extra/lib/copy/copy.js:183:14
    at /home/runner/work/react-native-vision-camera/react-native-vision-camera/docs/node_modules/graceful-fs/polyfills.js:247:20
    at FSReqCallback.oncomplete (fs.js:156:23)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Process completed with exit code 1.

This is my GitHub Action:

name: Build Documentation

on:
  pull_request:
    branches: [main]
  push:
    branches: [main]

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: 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: false
          GIT_USER: git
          CURRENT_BRANCH: main
          DEPLOYMENT_BRANCH: gh-pages
          github_token: ${{ secrets.GITHUB_TOKEN }}
        run: |
          git config --global user.email "actions@github.com"
          git config --global user.name "gh-actions"
          cd docs
          yarn install --frozen-lockfile
          yarn deploy

Have you read the Contributing Guidelines on issues?

yea

Your Environment

Reproducible Demo

See my repo, especially the docusaurus config file and the github action.

And here's the log output from the GitHub action.

Note that it does work if I run it locally, so I'm guessing something in the action isn't correctly configured/authenticated...

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed: questionThis issue is a user error/misunderstanding.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions