enriikke / gatsby-gh-pages-action

GitHub Action to build and deploy your Gatsby site to GitHub Pages ❤️🎩
MIT License
295 stars 62 forks source link

Run fails at `npm run build` in v2.1.1 #29

Closed willcoughlin closed 3 years ago

willcoughlin commented 4 years ago

I am running a simple workflow with v2.1.1 which appears to fail when at npm run build. It looks like something is causing a pair of quotes to be inserted as an arg when it calls gatsby build. Any idea what could be causing this? I don't think this comes from my configuration.

Here's the relevant output, picking up at the end of the npm install step:

Finished installing dependencies.
Ready to build your Gatsby site!
Building with: npm run build 
npm run build 

> gatsby-starter-hello-world@0.1.0 build /home/runner/work/willcoughlin.github.io/willcoughlin.github.io
> gatsby build ""

error gatsby build

Build a Gatsby project.

Options:
  --verbose                   Turn on verbose output  [boolean] [default: false]
  --no-color, --no-colors     Turn off the color in output  [boolean] [default: false]
  --json                      Turn on the JSON logger  [boolean] [default: false]
  --prefix-paths              Build site with link paths prefixed with the pathPrefix value in gatsby-config.js. Default is env.PREFIX_PATHS or false.  [boolean] [default: false]
  --no-uglify                 Build site without uglifying JS bundles (for debugging).  [boolean] [default: false]
  --profile                   Build site with react profiling (this can add some additional overhead). See https://reactjs.org/docs/profiler  [boolean] [default: false]
  --graphql-tracing           Trace every graphql resolver, may have performance implications  [boolean] [default: false]
  --open-tracing-config-file  Tracer configuration file (OpenTracing compatible). See https://gatsby.dev/tracing  [string]
  -h, --help                  Show help  [boolean]
  -v, --version               Show the version of the Gatsby CLI and the Gatsby package in the current project  [boolean]
error There was an error
error Unknown argument: 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gatsby-starter-hello-world@0.1.0 build: `gatsby build ""`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the gatsby-starter-hello-world@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2020-06-02T20_32_35_409Z-debug.log
##[error]The process 'npm' failed with exit code 1

In my package.json, build is defined as gatsby build:

"scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write \"**/*.{js,jsx,json,md}\"",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "clean": "gatsby clean",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1",
    "deploy": "gatsby build && gh-pages -d public -b master"
  },

Finally, here's my workflow file:

name: Gatsby Publish

on:
  push:
    branches:
      - dev

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: enriikke/gatsby-gh-pages-action@v2.1.1
        with:
          access-token: ${{ secrets.ACCESS_TOKEN }}
          deploy-branch: master

Any more helpful info, I can gladly provide!

rjriel commented 4 years ago

I believe I've figured out what the issue is here. I think it has to do with this line: https://github.com/enriikke/gatsby-gh-pages-action/blob/2156f7ec65e2fa9d8b981a2eee9f5233bfa4995d/index.ts#L40

it seems that what is happening is that when you attempt to run the action without gatsby-args present then the resulting run will be either npm run build "" or yarn build '' depending if you have a package-lock.json file or not. Either way this results in an empty string being passed to the gatsby build (gatsby build "") which the later versions of gatsby doesn't appreciate.

I was unable to solve this with npm being used instead of yarn. My solution to this issue was to remove the package-lock.json file in my repo and run yarn to create a yarn.lock file, which I committed. Then in my workflow I added gatsby-args: --verbose into the with section of the steps for this action. That resulted in the build command yarn build --verbose which successfully built my gatsby project.

I'll submit a PR for this soon and maybe the next release will happen at some point, but hopefully my workaround helps in the meantime

danwhitston commented 4 years ago

I've also run into this issue, after updating gatsby version in package.json to 2.23.11. Unsure how far I'll need to drop the version down again to start working, but will post here if I find out. Ideally, of course, this PR would get merged and a new version released, assuming it fixes the issue.

willcoughlin commented 4 years ago

@danwhitston rather than downgrading, another workaround I've seen is to add the --no-color arg in gatsby-args.

ronihcohen commented 4 years ago

@willcoughlin I tried to use your fork without success. image I'm I missing something?

willcoughlin commented 4 years ago

Interesting, and sorry to see that. What's your workflow yaml file look like?

On Mon, Jun 29, 2020, 7:33 AM Roni Hacohen notifications@github.com wrote:

@willcoughlin https://github.com/willcoughlin I tried to use your fork without success. [image: image] https://user-images.githubusercontent.com/3350618/86005829-cc24c080-ba1d-11ea-9931-db2b44cad9cf.png I'm I missing something?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/enriikke/gatsby-gh-pages-action/issues/29#issuecomment-651088120, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHDNPBOMCVIBCZOBWMT3QLRZCCZPANCNFSM4NRCGLSQ .

ronihcohen commented 4 years ago
      - name: Gatsby Publish
        uses: willcoughlin/gatsby-gh-pages-action@v2.1.1
        with:
          # A personal access token needed to push your site after it has been built.
          access-token: XXXX
willcoughlin commented 4 years ago

It's the tag. It should work if you change @v2.1.1 to @TestTag. Pardon the name, I didn't intend for its public use 😉.

On Mon, Jun 29, 2020, 11:20 PM Roni Hacohen notifications@github.com wrote:

  - name: Gatsby Publish
    uses: willcoughlin/gatsby-gh-pages-action@v2.1.1
    with:
      # A personal access token needed to push your site after it has been built.
      access-token: XXXX

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/enriikke/gatsby-gh-pages-action/issues/29#issuecomment-651522442, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHDNPDOC2NLNQYHTY6WIM3RZFR2VANCNFSM4NRCGLSQ .

xiaodeaux commented 4 years ago

Actually, the latest version of this action (tag v2) has already solved this issue that exists in version 2.1.1.

Just do - uses: enriikke/gatsby-gh-pages-action@v2

danwhitston commented 4 years ago

Yup, fixed this by using @v2 instead of 2.1.1.