andresz1/size-limit-action

Command runs successfully locally, but Github Action fails

hhimanshu opened this issue · 13 comments

Hello
The command, if I run locally runs well

➜  ts-react-components-lib git:(hhimanshu/update-deps) npx size-limit --json
[
  {
    "name": "dist/ts-react-components-lib.cjs.production.min.js",
    "passed": true,
    "size": 696
  },
  {
    "name": "dist/ts-react-components-lib.esm.js",
    "passed": true,
    "size": 696
  }
]

But the same command, when using the Github Action is failing

/usr/local/bin/npx size-limit --json
{
  "error": "WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.\n - configuration.entry['index'] should be an non-empty array.\n   -> A non-empty array of non-empty strings\n    at webpack (/home/runner/work/ts-react-components-lib/ts-react-components-lib/node_modules/webpack/lib/webpack.js:31:9)\n    at /home/runner/work/ts-react-components-lib/ts-react-components-lib/node_modules/@size-limit/webpack/run-webpack.js:5:20\n    at new Promise (<anonymous>)\n    at runWebpack (/home/runner/work/ts-react-components-lib/ts-react-components-lib/node_modules/@size-limit/webpack/run-webpack.js:4:10)\n    at Object.step40 (/home/runner/work/ts-react-components-lib/ts-react-components-lib/node_modules/@size-limit/webpack/index.js:86:38)\n    at /home/runner/work/ts-react-components-lib/ts-react-components-lib/node_modules/size-limit/calc.js:17:47\n    at Array.map (<anonymous>)\n    at step (/home/runner/work/ts-react-components-lib/ts-react-components-lib/node_modules/size-limit/calc.js:16:29)\n    at calc (/home/runner/work/ts-react-components-lib/ts-react-components-lib/node_modules/size-limit/calc.js:44:42)\n    at processTicksAndRejections (internal/process/task_queues.js:95:5)"
}
Error parsing size-limit output. The output should be a json.
Error: results.reduce is not a function
```
Here is the link to the build log
https://github.com/hhimanshu/ts-react-components-lib/pull/7/checks?check_run_id=3164196064

Could you please help me understand what's wrong here?
Thanks

The actual error is

/usr/local/bin/npx size-limit --json
{
  "error": "WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.\n - configuration.entry['index'] should be an non-empty array.\n   -> A non-empty array of non-empty strings\n    at webpack (/home/runner/work/ts-react-components-lib/ts-react-components-lib/node_modules/webpack/lib/webpack.js:31:9)\n    at /home/runner/work/ts-react-components-lib/ts-react-components-lib/node_modules/@size-limit/webpack/run-webpack.js:5:20\n    at new Promise (<anonymous>)\n    at runWebpack (/home/runner/work/ts-react-components-lib/ts-react-components-lib/node_modules/@size-limit/webpack/run-webpack.js:4:10)\n    at Object.step40 (/home/runner/work/ts-react-components-lib/ts-react-components-lib/node_modules/@size-limit/webpack/index.js:86:38)\n    at /home/runner/work/ts-react-components-lib/ts-react-components-lib/node_modules/size-limit/calc.js:17:47\n    at Array.map (<anonymous>)\n    at step (/home/runner/work/ts-react-components-lib/ts-react-components-lib/node_modules/size-limit/calc.js:16:29)\n    at calc (/home/runner/work/ts-react-components-lib/ts-react-components-lib/node_modules/size-limit/calc.js:44:42)\n    at processTicksAndRejections (internal/process/task_queues.js:95:5)"
}
Error parsing size-limit output. The output should be a json.
Error: results.reduce is not a function

I can confirm that the action is consistently failing. See another log at
https://github.com/hhimanshu/ts-react-components-lib/pull/7/checks?check_run_id=3165572896

Hello @ai , any help on this one?

ai commented

AS I told to @hhimanshu it happens because there is no files listed in path. Seems like you are calling Size Limit action before build (or Size Limit action doesn’t see the build file, or the path is wrong).

@ai , I will give it a try again, but since dependency updates, the job is failing. If you look at the actions history, no change to this job has been made.

Hello @ai , I can also share more findings to confirm that the build runs before size-limit action runs.
The files it looks for are available in the pull request
In the job, the size-limit job runs successfully once.

Then, in the same job, I do not know why it runs it again, and that's when it fails

I hope these links will give you access to what's going on in this Github Action and recommend something that would fix it.

Looking forward to learning more. Thank you

ai commented

Let’s wait @andresz1. If npx size-limit runs locally, it means that something is broken (or work in unexpected way) in the action.

Hi @hhimanshu! thank you for reporting this issue. Let me explain you what the action does:

  • Run size limit in the current branch (hhimanshu/update-deps)
  • Checkout to the base branch (master)
  • Run size limit
  • Compare the results
  • Post or update the comment in the PR

Looks like is working in your current branch (hhimanshu/update-deps) but it does not in master. Could you please try executing the following command in master and let me know if it works ?

npx size-limit --json

Thanks @ai for also taking care

Thanks @andresz1 , it doesn't run and for the same reason that in the master branch, file names in package.json is incorrect.
So I must fix it there first to test

➜  ts-react-components-lib git:(master) npx size-limit --json
{
  "error": "WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.\n - configuration.entry['index'] should be an non-empty array.\n   -> A non-empty array of non-empty strings\n    at webpack (/Users/hhimanshu/code/prsnl/ts/ts-react-components-lib/node_modules/webpack/lib/webpack.js:31:9)\n    at /Users/hhimanshu/code/prsnl/ts/ts-react-components-lib/node_modules/@size-limit/webpack/run-webpack.js:5:20\n    at new Promise (<anonymous>)\n    at runWebpack (/Users/hhimanshu/code/prsnl/ts/ts-react-components-lib/node_modules/@size-limit/webpack/run-webpack.js:4:10)\n    at Object.step40 (/Users/hhimanshu/code/prsnl/ts/ts-react-components-lib/node_modules/@size-limit/webpack/index.js:88:38)\n    at /Users/hhimanshu/code/prsnl/ts/ts-react-components-lib/node_modules/size-limit/calc.js:17:47\n    at Array.map (<anonymous>)\n    at step (/Users/hhimanshu/code/prsnl/ts/ts-react-components-lib/node_modules/size-limit/calc.js:16:29)\n    at calc (/Users/hhimanshu/code/prsnl/ts/ts-react-components-lib/node_modules/size-limit/calc.js:44:42)\n    at processTicksAndRejections (internal/process/task_queues.js:95:5)"
}
➜  ts-react-components-lib git:(master) yarn build
yarn run v1.22.4
$ tsdx build
@rollup/plugin-replace: 'preventAssignment' currently defaults to false. It is recommended to set this option to `true`, as the next major version will default this option to `true`.
@rollup/plugin-replace: 'preventAssignment' currently defaults to false. It is recommended to set this option to `true`, as the next major version will default this option to `true`.
✓ Creating entry file 1.7 secs
✓ Building modules 5.2 secs
✨  Done in 8.81s.
➜  ts-react-components-lib git:(master) ls -lh dist
total 64
drwxr-xr-x  4 hhimanshu  staff   128B 28 Jul 13:29 components
-rw-r--r--  1 hhimanshu  staff    75B 28 Jul 13:29 index.d.ts
-rw-r--r--  1 hhimanshu  staff   224B 28 Jul 13:29 index.js
-rw-r--r--  1 hhimanshu  staff   3.4K 28 Jul 13:29 ts-react-components-lib.cjs.development.js
-rw-r--r--  1 hhimanshu  staff   3.3K 28 Jul 13:29 ts-react-components-lib.cjs.development.js.map
-rw-r--r--  1 hhimanshu  staff   1.8K 28 Jul 13:29 ts-react-components-lib.cjs.production.min.js
-rw-r--r--  1 hhimanshu  staff   2.8K 28 Jul 13:29 ts-react-components-lib.cjs.production.min.js.map
-rw-r--r--  1 hhimanshu  staff   3.1K 28 Jul 13:29 ts-react-components-lib.esm.js
-rw-r--r--  1 hhimanshu  staff   3.3K 28 Jul 13:29 ts-react-components-lib.esm.js.map
➜  ts-react-components-lib git:(master)

Perfect @hhimanshu! please let me know if it works 🙌🏻

No problem @hhimanshu

Hi @hhimanshu! thank you for reporting this issue. Let me explain you what the action does:

* Run size limit in the current branch (`hhimanshu/update-deps`)

* Checkout to the base branch (`master`)

* Run size limit

* Compare the results

* Post or update the comment in the PR

Looks like is working in your current branch (hhimanshu/update-deps) but it does not in master. Could you please try executing the following command in master and let me know if it works ?

npx size-limit --json

Thanks @ai for also taking care

@andresz1

Thanks for the explanation! Your action has been much help to me.
Yet, some of my repos use develop branch as its main branch.
Can I tweak to action to compare current branch to develop branch instead of master branch?