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

Working directory not respected when reading nx version from package.json #126

Open
la-we opened this issue Mar 25, 2024 · 2 comments
Open

Comments

@la-we
Copy link

la-we commented Mar 25, 2024

Hey Timon,

really appreciate your project, nice work!

I was about to set-up a worklfow using your action for a different repo and noticed that it was unable to find package.json, even though i specified the working directory correctly at the workflow level.

I suspect the below line to be the caulprit:

const packageJson = fs.readFileSync('./package.json', 'utf8')

When comparing this to the way the official setup-node action resolves its files, we can see that they specifically prefix this with process.cwd to include the specified working directory.

Example from github/setup-node

I can open up a PR if you want, but i am not sure on how i would go about testing the action locally for correctness.

@la-we
Copy link
Author

la-we commented Mar 28, 2024

I've forked your action now and started to work a little bit on the issue. Turns out that working-directory parameter is not passed to a action from a workflow. Therefore i have introduced an additional path parameter to the actions inputs and am passing it to every exec call as cwd option. This seems to work quite well.

@timonmasberg
Copy link
Owner

Sorry and thank you for your patience. Interesting issue. A workaround for that issue would be to run the action after you performed a directory change, e.g. with cd. I believe the action always runs in the context of the current job. The file path should therefore always be related to the current state of the job. At least this is how we can use it over here https://github.com/kordis-leitstelle/kordis/blob/main/.github/workflows/nx-migration-checker.yml. If you open a PR, it will run a integration test by creating running the acton once, so you can open a PR if you like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants