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

How to use with GitHub Actions? #345

Closed
RehanSaeed opened this issue Apr 1, 2020 · 13 comments
Closed

How to use with GitHub Actions? #345

RehanSaeed opened this issue Apr 1, 2020 · 13 comments

Comments

@RehanSaeed
Copy link

RehanSaeed commented Apr 1, 2020

I have an npm script like this in packages.json:

"deploy": "gh-pages --branch master --dist dist --repo"

Then in my GitHub Actions build.yml I have the following step:

- name: 'Deploy'
  run: npm run deploy -- https://${{ secrets.GITHUB_TOKEN }}@github.com/foo/bar.github.io.git
  shell: bash

Note that adding any arguments after npm run deploy -- get double quoted, so I moved --repo into the packages.json file.

However, this errors with:

> gh-pages --branch master --dist dist --repo "https://***@github.com/foo/bar.github.io.git"


*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'runneradmin@fv-az31.(none)')
@seveibar
Copy link

seveibar commented Apr 3, 2020

You'll want to set the user properly and make sure you have the correct credentials. Try using the user flag like this:

npx gh-pages -d -u "github-actions-bot <support+actions@github.com>"

Make sure you have the "env" key for the GITHUB_TOKEN. You may need to set the remote url (I had to do this because of my checkout action). All together, the step should look like this:

- name: Publish github pages
  run: |
    git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/USER_OR_ORG/REPO.git
    npx gh-pages -d build -u "github-actions-bot <support+actions@github.com>"
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Props go to @nchaulet for writing a github action that demonstrated this here

@RehanSaeed
Copy link
Author

RehanSaeed commented Apr 4, 2020

That didn't seem to work for me. I tried without git remote set-url:


Run npx gh-pages --branch master --dist dist --user "github-actions-bot <support+actions@github.com>"
  npx gh-pages --branch master --dist dist --user "github-actions-bot <support+actions@github.com>"
  shell: C:\Program Files\Git\bin\bash.EXE --noprofile --norc -e -o pipefail {0}
  env:
    GITHUB_TOKEN: ***
The syntax of the command is incorrect.
##[error]Process completed with exit code 1.

And without:

Run git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/RehanSaeed/rehansaeed.github.io.git
  git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/RehanSaeed/rehansaeed.github.io.git
  npx gh-pages --branch master --dist dist --user "github-actions-bot <support+actions@github.com>"
  shell: C:\Program Files\Git\bin\bash.EXE --noprofile --norc -e -o pipefail {0}
  env:
    GITHUB_TOKEN: ***
The syntax of the command is incorrect.
##[error]Process completed with exit code 1.

Here is my full yaml:

    - name: 'Deploy'
      if: github.event_name != 'pull_request'
      run: |
        git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/RehanSaeed/rehansaeed.github.io.git
        npx gh-pages --branch master --dist dist --user "github-actions-bot <support+actions@github.com>"
      shell: bash
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

@seveibar
Copy link

seveibar commented Apr 4, 2020 via email

@seveibar
Copy link

seveibar commented Apr 4, 2020

@RehanSaeed
Copy link
Author

Switched to ubuntu and it works. thanks!

@igormcsouza
Copy link

You'll want to set the user properly and make sure you have the correct credentials. Try using the user flag like this:

npx gh-pages -d -u "github-actions-bot <support+actions@github.com>"

Make sure you have the "env" key for the GITHUB_TOKEN. You may need to set the remote url (I had to do this because of my checkout action). All together, the step should look like this:

- name: Publish github pages
  run: |
    git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/USER_OR_ORG/REPO.git
    npx gh-pages -d build -u "github-actions-bot <support+actions@github.com>"
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Props go to @nchaulet for writing a github action that demonstrated this here

thanks it saved me so much!! hahaha

@lukesmurray
Copy link

complete working example

name: "Deployment"
# the event that will trigger the action
on: push

# what the action will do
jobs:
  test:
    # the operating system it will run on
    runs-on: ubuntu-latest
    # the list of steps that the action will go through
    steps:
      - name: "Checkout"
        uses: actions/checkout@v2
      - name: Get yarn cache directory path # get yarn cache path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"
      - uses: actions/cache@v2 # cache yarn
        id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: "Install Dependencies"
        run: yarn
      - name: "Github Pages Deployment"
        run: |
          git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
          yarn deploy -u "github-actions-bot <support+actions@github.com>"
        if: ${{ github.ref == 'refs/heads/master' }} # only deploy master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Assumes that the following deploy scripts exist in package.json

  "scripts": {
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build",

SuaYoo added a commit to bestprogrammingclub/rabbithole that referenced this issue Feb 21, 2021
@hutch120
Copy link

Hi All,

I can't get this to work... it seems to be doubling up on the repo name?VictorianPremierMediaCentreSearch/VictorianPremierMediaCentreSearch . I've tried everything I can think of... any assistance would be appreciated. This is the repo

Error:

$ gh-pages -d build -u 'github-actions-bot <support+actions@github.com>'
ENOENT: no such file or directory, stat '/home/runner/work/VictorianPremierMediaCentreSearch/VictorianPremierMediaCentreSearch/build'

action.yml

name: Upload Website

on:
  push:
    branches:
      - main

jobs:
  deploy:
    name: Deploy site to gh-pages
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Load dependancies
        run: yarn

      - name: Deploy with gh-pages
        run: |
          git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
          yarn deploy -- -u "github-actions-bot <support+actions@github.com>"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

@alt-art
Copy link

alt-art commented Oct 30, 2021

@hutch120 You need to make the build of react first

notsidney added a commit to notsidney/material-you-palette-visual that referenced this issue Nov 15, 2021
@AriPerkkio
Copy link

I've been able to set up gh-pages deployments for multiple projects using instructions mentioned here. However with a new project I ran into permissions errors, fatal: unable to access <repository>: The requested URL returned error: 403.

I think Github has introduced new default settings which need to be changed: #429 (comment).

@sharadbhat
Copy link

sharadbhat commented Oct 9, 2022

Error:

$ gh-pages -d build -u 'github-actions-bot <support+actions@github.com>'
ENOENT: no such file or directory, stat '/home/runner/work/VictorianPremierMediaCentreSearch/VictorianPremierMediaCentreSearch/build'

I faced the same issue, turns out the production files were in dist/ and I was trying to deploy build/.

I changed "deploy": "gh-pages -d build" to "deploy": "gh-pages -d dist"

@vaynevayne
Copy link

ENOENT: no such file or directory, stat '/home/runner/work/soul/soul/build'
hi, The problem is solved, but there is no safe solution. Could you take a look at it for me? @seveibar
https://github.com/vaynevayne/soul/actions/runs/5025901406/jobs/9013476225

@xucian
Copy link

xucian commented Jul 7, 2023

I've been able to set up gh-pages deployments for multiple projects using instructions mentioned here. However with a new project I ran into permissions errors, fatal: unable to access <repository>: The requested URL returned error: 403.

I think Github has introduced new default settings which need to be changed: #429 (comment).

thanks, solved my issue! I was about to use the fine-grained tokens (but they're a bad deal as they expire quickly)

akash1810 added a commit to guardian/cdk that referenced this issue Oct 30, 2023
Updates how `GITHUB_TOKEN` and `GITHUB_REPOSITORY` are referenced to fix the build.

tschaub/gh-pages#345 (comment) used for inspiration.
akash1810 added a commit to guardian/cdk that referenced this issue Oct 30, 2023
Updates how `GITHUB_TOKEN` and `GITHUB_REPOSITORY` are referenced to fix the build.

tschaub/gh-pages#345 (comment) used for inspiration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants