bundlesize icon indicating copy to clipboard operation
bundlesize copied to clipboard

Could not add github status: 404 Not Found

Open kumar303 opened this issue 8 years ago • 14 comments

I'm trying to use bundlesize without github integration. Is that possible? In other words, I haven't added a token but I thought I could still use the output to tell me if my bundle has reached the threshold or not.

I set up my TravisCI to run bundlesize in my build step. This worked fine in a branch but when I merged it to master it failed every time like this:

$ bundlesize
 ERROR  Could not add github status.
        404: Not Found 

error Command failed with exit code 1.

Here is an example of a failure: https://travis-ci.org/mozilla/addons-frontend/builds/262798345?utm_source=github_status&utm_medium=notification

kumar303 avatar Aug 09 '17 19:08 kumar303

Ah, that's a bug

I'll take care of that!

siddharthkp avatar Aug 10 '17 02:08 siddharthkp

@siddharthkp Is this fixed?

jorgebucaran avatar Aug 17 '17 09:08 jorgebucaran

No 😢

Haven't been able to make time for this. Would you like to take a shot at it?

siddharthkp avatar Aug 17 '17 10:08 siddharthkp

@siddharthkp BTW I was getting the same error locally. 🤔 Where does one start looking?

jorgebucaran avatar Aug 17 '17 11:08 jorgebucaran

@jbucaran I'm sorry you had to remove the integration because it was unusable. https://github.com/siddharthkp/bundlesize/blob/accf79cf8db19e40b34c8a0f263626e7ef2b1fc6/src/build.js#L22 is where the error is thrown and https://github.com/siddharthkp/github-build/blob/bdc53116ccf94cf6d2294fe1607aadca6bfdc26e/index.js#L9 is where it actually comes from.

It seems like a good idea to run in some kindda CI_ONLY mode if GITHUB_TOKEN isn't available. Just to understand a bit more exactly what you need, are you saying you would like to manually check the CI logs to tell you that the bundlesizes have crossed the limit? Or would you want bundlesize to exit with a non-zero error code to signify that the build broke?

karanjthakkar avatar Aug 27 '17 07:08 karanjthakkar

Hey @karanjthakkar. I actually removed bundlesize because it wasn't really so useful in that particular project, but I'd definitely use this or a similar tool on a project with a lot of dependencies or where the code changes a lot.

Just to understand a bit more exactly what you need, are you saying you would like to manually check the CI logs to tell you that the bundlesizes have crossed the limit?

I used to have this in my pkgjson.

"test": "bundlesize && npm run test"

And bundlesize would exit with a non-zero error code preventing "npm run test" to execute. Last time I checked, "npm run test" wouldn't even run and I was getting an error resembling (unfortunately I can't remember exactly what):

ERROR  Could not add github status.
  404: Not Found  

jorgebucaran avatar Aug 27 '17 08:08 jorgebucaran

@jbucaran @karanjthakkar Ooh, a couple of interesting things here.

  1. If you want your tests to continue running, you can make that bundlesize || npm run test, but then bundlesize would not be able to fail your builds!

    Alternatively, you can split them into different commands and let your CI configuration decide whether it wants to fail early or run all the tests (I know travis CI supports this, don't know about the rest, sorry!)

  2. Could not add github status can happen in a few cases:

    a) This is an enterprise repo (bundlesize doesn't support enterprise yet, open issue here: https://github.com/siddharthkp/github-build/issues/3)

    b) You have given a wrong github token and setting the status failed. Github API returns a 404 in such cases (bundlesize should handle this better)

    c) You are not giving a github token, but bundlesize didn't know that and tried to set values for master anyways and failed. Potential bug on this line: reporter.js#L80, can be fixed by adding if (api.enabled)

siddharthkp avatar Aug 27 '17 10:08 siddharthkp

For me this is an issue because I have a GITHUB_TOKEN in my local environment, but only for some automated gists. Naturally that token does not have access to any repos. And it should not because when I run builds locally I do not want bundlesize to do anything with my github token. But I still would like to know if something I did accidently raised the size of the bundle before I push it to the pull-request and CI tells me.

Is it important that bundlesize looks for the GITHUB_TOKEN variable? Because it is often used by tools in development environments. E.g. by some vim plugins.

Raigen avatar Jan 30 '18 15:01 Raigen

@Raigen, as far as I remember, you can run it on local without giving a token and it should work. (correct me if this isn't happening in your case)

siddharthkp avatar Jan 30 '18 17:01 siddharthkp

@siddharthkp I already use a token for some gist things, but bundlesize tries to use it and then fails the build because of a 404 from github because the token is meant for gist only. An option/cli parameter would be nice to opt-in github status feature in CI and do nothing locally even when there is a token. Or an opt-out for locale machines to not break existing integrations.

Raigen avatar Jan 31 '18 09:01 Raigen

My view here is that it should just ignore tokens on non-ci env

Can you open a different issue for this?

siddharthkp avatar Jan 31 '18 09:01 siddharthkp

I opened a PR that will fix the issue on running bundlesize on NON CI environments #291

vigneshshanmugam avatar Mar 26 '19 16:03 vigneshshanmugam

I'm facing the same error. Using the --debug flag, it seems that the request to bundlesize-store.now.sh is hitting an internal server error.

$ GITHUB_REPOSITORY="alloc/wana" GITHUB_SHA="master" BUNDLESIZE_GITHUB_TOKEN="[redacted]" ./node_modules/.bin/bundlesize -f "dist/index.js" --debug

 WARN  cli config: [
  {
    "path": "dist/index.js",
    "compression": "gzip"
  }
] 

 WARN  file config: undefined 

 WARN  selected config: [
  {
    "path": "dist/index.js",
    "compression": "gzip"
  }
] 

 WARN  files: [
  {
    "maxSize": null,
    "path": "dist/index.js",
    "size": 4877,
    "compression": "gzip"
  }
] 

 WARN  token exists: true 

 WARN  repo: undefined 

 WARN  sha: undefined 

 WARN  api enabled: false 

 PASS  dist/index.js: 4.76KB (gzip) 

 WARN  message: "dist/index.js: 4.76KB (gzip)" 

 WARN  url before shortening: "https://bundlesize-store.now.sh/build?info=%7B%22files%22%3A%5B%7B%22maxSize%22%3Anull%2C%22path%22%3A%22dist%2Findex.js%22%2C%22size%22%3A4877%2C%22compression%22%3A%22gzip%22%7D%5D%7D" 

 WARN  err while shortening: {
  "message": "Request failed with status code 403",
  "name": "Error",
  "stack": "Error: Request failed with status code 403\n    at createError (/dev/wana/node_modules/.registry.npmjs.org/axios/0.19.0/node_modules/axios/lib/core/createError.js:16:15)\n    at settle (/dev/wana/node_modules/.registry.npmjs.org/axios/0.19.0/node_modules/axios/lib/core/settle.js:17:12)\n    at IncomingMessage.handleStreamEnd (/dev/wana/node_modules/.registry.npmjs.org/axios/0.19.0/node_modules/axios/lib/adapters/http.js:237:11)\n    at IncomingMessage.emit (events.js:202:15)\n    at endReadableNT (_stream_readable.js:1129:12)\n    at processTicksAndRejections (internal/process/next_tick.js:76:17)",
  "config": {
    "url": "https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyACIqikanS3eoHsy14JYyFAHU1aU5w1YoA",
    "method": "post",
    "data": "{\"longUrl\":\"https://bundlesize-store.now.sh/build?info=%7B%22files%22%3A%5B%7B%22maxSize%22%3Anull%2C%22path%22%3A%22dist%2Findex.js%22%2C%22size%22%3A4877%2C%22compression%22%3A%22gzip%22%7D%5D%7D\"}",
    "headers": {
      "Accept": "application/json, text/plain, */*",
      "Content-Type": "application/json;charset=utf-8",
      "User-Agent": "axios/0.19.0",
      "Content-Length": 199
    },
    "transformRequest": [
      null
    ],
    "transformResponse": [
      null
    ],
    "timeout": 0,
    "xsrfCookieName": "XSRF-TOKEN",
    "xsrfHeaderName": "X-XSRF-TOKEN",
    "maxContentLength": -1
  }
} 

 WARN  global message: "dist/index.js: 4.76KB (gzip)" 

 ERROR  Could not add github status.
        404: Not Found 

aleclarson avatar Aug 27 '19 16:08 aleclarson

Temp. fix is to clear the env var before running your build e.g.: GITHUB_TOKEN='' npm publish

JoshMcCullough avatar Dec 13 '19 14:12 JoshMcCullough