Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ValentinFunk opened this issue Apr 6, 2023 · 4 comments
Labels

Comments

@ValentinFunk
Copy link

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
    }
  ]
}
  1. 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

export default async function run(

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
Copy link

github-actions bot commented Oct 6, 2023

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! 🙏

@github-actions github-actions bot added the stale label Oct 6, 2023
@ValentinFunk
Copy link
Author

Still care about this fwiw

@github-actions github-actions bot removed the stale label Oct 8, 2023
@FrozenPandaz
Copy link
Collaborator

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

#22623

Copy link

github-actions bot commented May 3, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants