tschaub / gh-pages

General purpose task for publishing files to a gh-pages branch on GitHub

Home Page:https://www.npmjs.com/package/gh-pages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use with GitHub Actions?

RehanSaeed opened this issue · comments

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)')

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

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 }}

Switched to ubuntu and it works. thanks!

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

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",

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 }}

@hutch120 You need to make the build of react first

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).

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"

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

commented

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)