-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Enhance caching in setup-node with automatic package manager detection #1348
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
Merged
HarithaVattikuti
merged 9 commits into
actions:main
from
priya-kinthali:package-manager-field-caching
Aug 26, 2025
+167
−4
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2742b68
setup node in local
priya-kinthali 7b37530
Merge branch 'actions:main' into main
priya-kinthali e52cc8a
Merge branch 'actions:main' into main
priya-kinthali 9223e3a
Merge branch 'actions:main' into main
priya-kinthali 4dd8002
Merge branch 'actions:main' into main
priya-kinthali 1c26a09
Merge branch 'actions:main' into main
priya-kinthali 674c3e9
Enhance caching in setup-node with package manager filed detection
priya-kinthali 85d6eeb
updated with array
priya-kinthali 72899a8
update the field
priya-kinthali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -243,3 +243,28 @@ jobs: | |
| cache-dependency-path: | | ||
| sub2/*.lock | ||
| sub3/*.lock | ||
|
|
||
| node-npm-package-manager-cache: | ||
| name: Test enabling cache if package manager field is present (Node ${{ matrix.node-version }}, ${{ matrix.os }}) | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [ubuntu-latest, windows-latest, macos-latest, macos-13] | ||
| node-version: [18, 20, 22] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Create package.json with packageManager field | ||
| run: | | ||
| echo '{ "name": "test-project", "version": "1.0.0", "packageManager": "[email protected]" }' > package.json | ||
| - name: Clean global cache | ||
| run: npm cache clean --force | ||
| - name: Setup Node with caching enabled | ||
| uses: ./ | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| - name: Install dependencies | ||
| run: npm install | ||
| - name: Verify node and npm | ||
| run: __tests__/verify-node.sh "${{ matrix.node-version }}" | ||
| shell: bash | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ describe('main tests', () => { | |
|
|
||
| let infoSpy: jest.SpyInstance; | ||
| let warningSpy: jest.SpyInstance; | ||
| let saveStateSpy: jest.SpyInstance; | ||
| let inSpy: jest.SpyInstance; | ||
| let setOutputSpy: jest.SpyInstance; | ||
| let startGroupSpy: jest.SpyInstance; | ||
|
|
@@ -53,6 +54,8 @@ describe('main tests', () => { | |
| setOutputSpy.mockImplementation(() => {}); | ||
| warningSpy = jest.spyOn(core, 'warning'); | ||
| warningSpy.mockImplementation(() => {}); | ||
| saveStateSpy = jest.spyOn(core, 'saveState'); | ||
| saveStateSpy.mockImplementation(() => {}); | ||
| startGroupSpy = jest.spyOn(core, 'startGroup'); | ||
| startGroupSpy.mockImplementation(() => {}); | ||
| endGroupSpy = jest.spyOn(core, 'endGroup'); | ||
|
|
@@ -280,4 +283,87 @@ describe('main tests', () => { | |
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('cache feature tests', () => { | ||
| it('Should enable caching with the resolved package manager from devEngines.packageManager in package.json when the cache input is not provided', async () => { | ||
| inputs['package-manager-cache'] = 'true'; | ||
| inputs['cache'] = ''; // No cache input is provided | ||
|
|
||
| inSpy.mockImplementation(name => inputs[name]); | ||
|
|
||
| const readFileSpy = jest.spyOn(fs, 'readFileSync'); | ||
| readFileSpy.mockImplementation(() => | ||
| JSON.stringify({ | ||
| devEngines: { | ||
| packageManager: { | ||
| name: 'pnpm' | ||
| } | ||
| } | ||
| }) | ||
| ); | ||
|
|
||
| await main.run(); | ||
|
|
||
| expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'pnpm'); | ||
| }); | ||
|
|
||
| it('Should enable caching with the resolved package manager from packageManager field in package.json when the cache input is not provided', async () => { | ||
| inputs['package-manager-cache'] = 'true'; | ||
| inputs['cache'] = ''; // No cache input is provided | ||
|
|
||
| inSpy.mockImplementation(name => inputs[name]); | ||
|
|
||
| const readFileSpy = jest.spyOn(fs, 'readFileSync'); | ||
| readFileSpy.mockImplementation(() => | ||
| JSON.stringify({ | ||
| packageManager: '[email protected]' | ||
| }) | ||
| ); | ||
|
|
||
| await main.run(); | ||
|
|
||
| expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'yarn'); | ||
| }); | ||
|
|
||
| it('Should not enable caching if the packageManager field is missing in package.json and the cache input is not provided', async () => { | ||
| inputs['package-manager-cache'] = 'true'; | ||
| inputs['cache'] = ''; // No cache input is provided | ||
|
|
||
| inSpy.mockImplementation(name => inputs[name]); | ||
|
|
||
| const readFileSpy = jest.spyOn(fs, 'readFileSync'); | ||
| readFileSpy.mockImplementation(() => | ||
| JSON.stringify({ | ||
| //packageManager field is not present | ||
| }) | ||
| ); | ||
|
|
||
| await main.run(); | ||
|
|
||
| expect(saveStateSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('Should skip caching when package-manager-cache is false', async () => { | ||
| inputs['package-manager-cache'] = 'false'; | ||
| inputs['cache'] = ''; // No cache input is provided | ||
|
|
||
| inSpy.mockImplementation(name => inputs[name]); | ||
|
|
||
| await main.run(); | ||
|
|
||
| expect(saveStateSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('Should enable caching with cache input explicitly provided', async () => { | ||
| inputs['package-manager-cache'] = 'true'; | ||
| inputs['cache'] = 'npm'; // Explicit cache input provided | ||
|
|
||
| inSpy.mockImplementation(name => inputs[name]); | ||
| isCacheActionAvailable.mockReturnValue(true); | ||
|
|
||
| await main.run(); | ||
|
|
||
| expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm'); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.