nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.56k stars 2.36k forks source link

Hashes in nx print-affected differ from hashes that are computed when actually running the command #16153

Closed ValentinFunk closed 7 months ago

ValentinFunk commented 1 year ago

Current Behavior

I run nx print-affected --targets=lint | jq .targets to see which lint commands need to be run. This gives back a JSON with targets, commands and the task hash:

...
{
    "id": "crush-report-e2e:lint",
    "overrides": {
      "__overrides_unparsed__": []
    },
    "target": {
      "project": "crush-report-e2e",
      "target": "lint"
    },
    "hash": "13337821e832dcffc9afa0bdf9598aea274acc99f03f9defa6a2d21f91705890",
    "command": "yarn nx run crush-report-e2e:lint",
    "outputs": []
  }
...

We can see that the task hash for running the command yarn nx run crush-report-e2e:lint should be 13337821e832dcffc9afa0bdf9598aea274acc99f03f9defa6a2d21f91705890.

I then run rm -rf .nx-cache and yarn nx run crush-report-e2e:lint which lints and then writes the cache files - but with a different hash. e.g. 5bbb49c819e3dcd0bfc4b7a8b05a31ea86a3250ecccae516a0a28d05e1791bba.

Expected Behavior

I'd expect that the hash from .targets[0].hash that nx print-affected outputs matches the hash that is computed for running .targets[0].command.

GitHub Repo

No response

Steps to Reproduce

This can be reproduced in nrwl/nx-examples

  1. Clear NX cache
  2. Modify apps/cart/src/index.ts (e.g. add a comment)
  3. yarn nx run cart:lint
  4. Look at node_modules/.cache/nx/run.json, this shows the hash that yarn nx run cart:lint used for remote cache:
    {
    "run": {
      "command": "nx lint cart",
      "startTime": "2023-04-06T10:16:09.148Z",
      "endTime": "2023-04-06T10:16:11.954Z",
      "inner": false
    },
    "tasks": [
      {
        "taskId": "cart:lint",
        "target": "lint",
        "projectName": "cart",
        "hash": "f13951bb4173982415b9895bc9b868c5a92f9b5d799fc59c3576bb11331746d9",
        "startTime": "2023-04-06T10:16:09.160Z",
        "endTime": "2023-04-06T10:16:11.954Z",
        "params": "",
        "cacheStatus": "cache-miss",
        "status": 0
      }
    ]
    }
  5. Run yarn nx print-affected --target=lint and look at the JSON output. The task has a different hash:
    {
      "id": "cart:lint",
      "overrides": {
        "__overrides_unparsed__": []
      },
      "target": {
        "project": "cart",
        "target": "lint"
      },
      "hash": "6b0ac0657cc986a38228f50791b5b03e7467c648f0664e9f398e2f39dd7d75ae",
      "command": "yarn nx run cart:lint",
      "outputs": []
    }

Nx Report

>  NX   Report complete - copy this into the issue template

   Node : 18.13.0
   OS   : darwin arm64
   yarn : 1.22.19

   nx                      : 15.8.3
   @nrwl/js                : 15.8.3
   @nrwl/jest              : 15.8.3
   @nrwl/linter            : 15.8.3
   @nrwl/workspace         : 15.8.3
   @nrwl/angular           : 15.8.3
   @nrwl/cli               : 15.8.3
   @nrwl/cypress           : 15.8.3
   @nrwl/devkit            : 15.8.3
   @nrwl/eslint-plugin-nx  : 15.8.3
   @nrwl/node              : 15.8.3
   @nrwl/react             : 15.8.3
   @nrwl/rollup            : 15.8.3
   @nrwl/storybook         : 15.8.3
   @nrwl/tao               : 15.8.3
   @nrwl/web               : 15.8.3
   @nrwl/webpack           : 15.8.3
   typescript              : 4.9.5
   ---------------------------------------
   Community plugins:
   @fortawesome/angular-fontawesome : 0.10.2
   @ng-bootstrap/ng-bootstrap       : 12.1.2
   @ngrx/component-store            : 15.3.0
   @rx-angular/cdk                  : 1.0.0-rc.2
   @rx-angular/template             : 1.0.0-rc.3
   rxjs                             : 6.6.6
   @compodoc/compodoc               : 1.1.19
   @ngneat/spectator                : 14.0.0
   @storybook/angular               : 6.5.16

Failure Logs

No response

Additional Information

Brief investigation into this makes me suspect that the difference is coming from hasher.ts in https://github.com/nrwl/nx/blob/c53d9c325c2f6309b5f1da493e32e002455e9007/packages/linter/src/executors/eslint/hasher.ts#L10

The call to the default Hasher.hashTask() returns the same hash in both cases. But the custom hasher for the linter returns a different hash (and details).

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

ValentinFunk commented 1 year ago

Still care about this fwiw

FrozenPandaz commented 7 months ago

This cannot always be the case because tasks can depend on something from dependent tasks. This is only correct when the dependent task is actually run. I'm going to close this issue in favor of the discussion here which also discusses seeing hashes in affected --graph

https://github.com/nrwl/nx/discussions/22623

github-actions[bot] commented 6 months ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.