mirror of
https://github.com/actions/setup-node.git
synced 2026-06-17 14:23:47 +08:00
Compare commits
5 Commits
test-macos
...
41fec91c7b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41fec91c7b | ||
|
|
5e2628c959 | ||
|
|
d23de777e0 | ||
|
|
82af78e9c4 | ||
|
|
870d3d8e13 |
103
.github/workflows/e2e-cache.yml
vendored
103
.github/workflows/e2e-cache.yml
vendored
@@ -6,7 +6,7 @@ on:
|
|||||||
- '**.md'
|
- '**.md'
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- test-macos-x64-runner
|
- main
|
||||||
- releases/*
|
- releases/*
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '**.md'
|
- '**.md'
|
||||||
@@ -18,10 +18,10 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- name: Clean global cache
|
- name: Clean global cache
|
||||||
run: npm cache clean --force
|
run: npm cache clean --force
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
@@ -41,10 +41,10 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- name: Install pnpm
|
- name: Install pnpm
|
||||||
uses: pnpm/action-setup@v4
|
uses: pnpm/action-setup@v4
|
||||||
with:
|
with:
|
||||||
@@ -74,14 +74,14 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- name: Yarn version
|
- name: Yarn version
|
||||||
run: yarn --version
|
run: yarn --version
|
||||||
- name: Generate yarn file
|
- name: Generate yarn file
|
||||||
run: yarn install --ignore-engines
|
run: yarn install
|
||||||
- name: Remove dependencies
|
- name: Remove dependencies
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: Remove-Item node_modules -Force -Recurse
|
run: Remove-Item node_modules -Force -Recurse
|
||||||
@@ -106,10 +106,10 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- name: Update yarn
|
- name: Update yarn
|
||||||
run: yarn set version 3.6.4
|
run: yarn set version 3.6.4
|
||||||
- name: Yarn version
|
- name: Yarn version
|
||||||
@@ -139,11 +139,11 @@ jobs:
|
|||||||
name: Test yarn subprojects
|
name: Test yarn subprojects
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: prepare sub-projects
|
- name: prepare sub-projects
|
||||||
run: __tests__/prepare-yarn-subprojects.sh yarn1
|
run: __tests__/prepare-yarn-subprojects.sh yarn1
|
||||||
@@ -166,11 +166,11 @@ jobs:
|
|||||||
name: Test yarn subprojects all locally managed
|
name: Test yarn subprojects all locally managed
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: prepare sub-projects
|
- name: prepare sub-projects
|
||||||
run: __tests__/prepare-yarn-subprojects.sh keepcache keepcache
|
run: __tests__/prepare-yarn-subprojects.sh keepcache keepcache
|
||||||
@@ -193,11 +193,11 @@ jobs:
|
|||||||
name: Test yarn subprojects some locally managed
|
name: Test yarn subprojects some locally managed
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: prepare sub-projects
|
- name: prepare sub-projects
|
||||||
run: __tests__/prepare-yarn-subprojects.sh global
|
run: __tests__/prepare-yarn-subprojects.sh global
|
||||||
@@ -220,11 +220,11 @@ jobs:
|
|||||||
name: Test yarn subprojects managed by git
|
name: Test yarn subprojects managed by git
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: prepare sub-projects
|
- name: prepare sub-projects
|
||||||
run: /bin/bash __tests__/prepare-yarn-subprojects.sh keepcache
|
run: /bin/bash __tests__/prepare-yarn-subprojects.sh keepcache
|
||||||
@@ -243,62 +243,3 @@ jobs:
|
|||||||
cache-dependency-path: |
|
cache-dependency-path: |
|
||||||
sub2/*.lock
|
sub2/*.lock
|
||||||
sub3/*.lock
|
sub3/*.lock
|
||||||
|
|
||||||
node-npm-packageManager-auto-cache:
|
|
||||||
name: Test auto cache with top-level packageManager
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
|
||||||
node-version: [20, 22, 24]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v5
|
|
||||||
- name: Create package.json with packageManager field
|
|
||||||
run: |
|
|
||||||
echo '{ "name": "test-project", "version": "1.0.0", "packageManager": "npm@8.0.0" }' > 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
|
|
||||||
|
|
||||||
node-npm-devEngines-auto-cache:
|
|
||||||
name: Test auto cache with devEngines.packageManager
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
|
||||||
node-version: [20, 22, 24]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v5
|
|
||||||
- name: Create package.json with devEngines field
|
|
||||||
run: |
|
|
||||||
echo '{
|
|
||||||
"name": "test-project",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"devEngines": {
|
|
||||||
"packageManager": {
|
|
||||||
"name": "npm",
|
|
||||||
"onFail": "error"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}' > 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
|
|
||||||
|
|||||||
72
.github/workflows/versions.yml
vendored
72
.github/workflows/versions.yml
vendored
@@ -6,7 +6,7 @@ on:
|
|||||||
- '**.md'
|
- '**.md'
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- test-macos-x64-runner
|
- main
|
||||||
- releases/*
|
- releases/*
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '**.md'
|
- '**.md'
|
||||||
@@ -17,10 +17,10 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -34,10 +34,10 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-13]
|
||||||
node-version: [lts/dubnium, lts/erbium, lts/fermium, lts/*, lts/-1]
|
node-version: [lts/dubnium, lts/erbium, lts/fermium, lts/*, lts/-1]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -56,7 +56,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version:
|
node-version:
|
||||||
[
|
[
|
||||||
'20-v8-canary',
|
'20-v8-canary',
|
||||||
@@ -64,7 +64,7 @@ jobs:
|
|||||||
'20.0.0-v8-canary20221101e50e45c9f8'
|
'20.0.0-v8-canary20221101e50e45c9f8'
|
||||||
]
|
]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -81,10 +81,10 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20-nightly, 25-nightly, 24.0.0-nightly]
|
node-version: [20-nightly, 21-nightly, 18.0.0-nightly]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -101,10 +101,10 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20.0.0-rc.1, 22.14.0-rc.1, 24.0.0-rc.4]
|
node-version: [20.0.0-rc.1, 18.0.0-rc.2, 19.0.0-rc.0]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -121,10 +121,10 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20.10.0, 22.0.0, 24.9.0]
|
node-version: [18.20.0, 20.10.0, 22.0.0]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -138,10 +138,10 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- name: Setup Node and check latest
|
- name: Setup Node and check latest
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -156,57 +156,57 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version-file:
|
node-version-file:
|
||||||
[.nvmrc, .tool-versions, .tool-versions-node, package.json]
|
[.nvmrc, .tool-versions, .tool-versions-node, package.json]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- name: Setup node from node version file
|
- name: Setup node from node version file
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
node-version-file: '__tests__/data/${{ matrix.node-version-file }}'
|
node-version-file: '__tests__/data/${{ matrix.node-version-file }}'
|
||||||
- name: Verify node
|
- name: Verify node
|
||||||
run: __tests__/verify-node.sh 24
|
run: __tests__/verify-node.sh 20
|
||||||
|
|
||||||
version-file-volta:
|
version-file-volta:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- name: Setup node from node version file
|
- name: Setup node from node version file
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
node-version-file: '__tests__/data/package-volta.json'
|
node-version-file: '__tests__/data/package-volta.json'
|
||||||
- name: Verify node
|
- name: Verify node
|
||||||
run: __tests__/verify-node.sh 24
|
run: __tests__/verify-node.sh 20
|
||||||
|
|
||||||
version-file-volta-extends:
|
version-file-volta-extends:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- name: Setup node from node version file
|
- name: Setup node from node version file
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
node-version-file: '__tests__/data/package-volta-extends.json'
|
node-version-file: '__tests__/data/package-volta-extends.json'
|
||||||
- name: Verify node
|
- name: Verify node
|
||||||
run: __tests__/verify-node.sh 24
|
run: __tests__/verify-node.sh 20
|
||||||
|
|
||||||
node-dist:
|
node-dist:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [17, 19]
|
node-version: [17, 19]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- name: Setup Node from dist
|
- name: Setup Node from dist
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -220,9 +220,9 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-13]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
# test old versions which didn't have npm and layout different
|
# test old versions which didn't have npm and layout different
|
||||||
- name: Setup node 0.12.18 from dist
|
- name: Setup node 0.12.18 from dist
|
||||||
uses: ./
|
uses: ./
|
||||||
@@ -235,7 +235,7 @@ jobs:
|
|||||||
arch:
|
arch:
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- name: Setup node 20 x86 from dist
|
- name: Setup node 20 x86 from dist
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -250,7 +250,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [current, latest, node]
|
node-version: [current, latest, node]
|
||||||
steps:
|
steps:
|
||||||
- name: Get node version
|
- name: Get node version
|
||||||
@@ -259,7 +259,7 @@ jobs:
|
|||||||
echo "LATEST_NODE_VERSION=$latestNodeVersion" >> $GITHUB_OUTPUT
|
echo "LATEST_NODE_VERSION=$latestNodeVersion" >> $GITHUB_OUTPUT
|
||||||
id: version
|
id: version
|
||||||
shell: bash
|
shell: bash
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ describe('cache-restore', () => {
|
|||||||
])(
|
])(
|
||||||
'restored dependencies for %s',
|
'restored dependencies for %s',
|
||||||
async (packageManager, toolVersion, fileHash) => {
|
async (packageManager, toolVersion, fileHash) => {
|
||||||
|
const expectedCacheKey = `node-cache-${platform}-${arch}-${packageManager}-${fileHash}`;
|
||||||
getCommandOutputSpy.mockImplementation((command: string) => {
|
getCommandOutputSpy.mockImplementation((command: string) => {
|
||||||
if (command.includes('version')) {
|
if (command.includes('version')) {
|
||||||
return toolVersion;
|
return toolVersion;
|
||||||
@@ -142,12 +143,20 @@ describe('cache-restore', () => {
|
|||||||
await restoreCache(packageManager, '');
|
await restoreCache(packageManager, '');
|
||||||
expect(hashFilesSpy).toHaveBeenCalled();
|
expect(hashFilesSpy).toHaveBeenCalled();
|
||||||
expect(infoSpy).toHaveBeenCalledWith(
|
expect(infoSpy).toHaveBeenCalledWith(
|
||||||
`Cache restored from key: node-cache-${platform}-${arch}-${packageManager}-${fileHash}`
|
`Cache restored from key: ${expectedCacheKey}`
|
||||||
);
|
);
|
||||||
expect(infoSpy).not.toHaveBeenCalledWith(
|
expect(infoSpy).not.toHaveBeenCalledWith(
|
||||||
`${packageManager} cache is not found`
|
`${packageManager} cache is not found`
|
||||||
);
|
);
|
||||||
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', true);
|
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', true);
|
||||||
|
expect(setOutputSpy).toHaveBeenCalledWith(
|
||||||
|
'cache-key',
|
||||||
|
expectedCacheKey
|
||||||
|
);
|
||||||
|
expect(setOutputSpy).toHaveBeenCalledWith(
|
||||||
|
'cache-matched-key',
|
||||||
|
expectedCacheKey
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -161,6 +170,7 @@ describe('cache-restore', () => {
|
|||||||
])(
|
])(
|
||||||
'dependencies are changed %s',
|
'dependencies are changed %s',
|
||||||
async (packageManager, toolVersion, fileHash) => {
|
async (packageManager, toolVersion, fileHash) => {
|
||||||
|
const expectedCacheKey = `node-cache-${platform}-${arch}-${packageManager}-${fileHash}`;
|
||||||
getCommandOutputSpy.mockImplementation((command: string) => {
|
getCommandOutputSpy.mockImplementation((command: string) => {
|
||||||
if (command.includes('version')) {
|
if (command.includes('version')) {
|
||||||
return toolVersion;
|
return toolVersion;
|
||||||
@@ -176,10 +186,72 @@ describe('cache-restore', () => {
|
|||||||
`${packageManager} cache is not found`
|
`${packageManager} cache is not found`
|
||||||
);
|
);
|
||||||
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', false);
|
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', false);
|
||||||
|
expect(setOutputSpy).toHaveBeenCalledWith(
|
||||||
|
'cache-key',
|
||||||
|
expectedCacheKey
|
||||||
|
);
|
||||||
|
expect(setOutputSpy).toHaveBeenCalledWith(
|
||||||
|
'cache-matched-key',
|
||||||
|
undefined
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Cache key output', () => {
|
||||||
|
const packageManager = 'npm';
|
||||||
|
const cacheDependencyPath = 'package-lock.json';
|
||||||
|
const primaryKey = `node-cache-${platform}-${arch}-${packageManager}-${npmFileHash}`;
|
||||||
|
const cacheKey = `node-cache-${platform}-${arch}-${packageManager}-abc123`;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
getCommandOutputSpy.mockImplementation(command => {
|
||||||
|
if (command.includes('npm config get cache')) return npmCachePath;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets the cache-key output', async () => {
|
||||||
|
restoreCacheSpy.mockResolvedValue(cacheKey);
|
||||||
|
await restoreCache(packageManager, cacheDependencyPath);
|
||||||
|
expect(setOutputSpy).toHaveBeenCalledWith('cache-key', primaryKey);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets the cache-hit output to true when cache is found', async () => {
|
||||||
|
restoreCacheSpy.mockResolvedValue(cacheKey);
|
||||||
|
await restoreCache(packageManager, cacheDependencyPath);
|
||||||
|
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets the cache-hit output to false when cache is not found', async () => {
|
||||||
|
restoreCacheSpy.mockResolvedValue(undefined);
|
||||||
|
await restoreCache(packageManager, cacheDependencyPath);
|
||||||
|
|
||||||
|
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets the cache-matched-key output when cache is found', async () => {
|
||||||
|
(cache.restoreCache as jest.Mock).mockResolvedValue(cacheKey);
|
||||||
|
|
||||||
|
await restoreCache(packageManager, cacheDependencyPath);
|
||||||
|
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith(
|
||||||
|
'cache-matched-key',
|
||||||
|
cacheKey
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets the cache-matched-key output to undefined when cache is not found', async () => {
|
||||||
|
(cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
|
||||||
|
|
||||||
|
await restoreCache(packageManager, cacheDependencyPath);
|
||||||
|
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith(
|
||||||
|
'cache-matched-key',
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ describe('run', () => {
|
|||||||
let setFailedSpy: jest.SpyInstance;
|
let setFailedSpy: jest.SpyInstance;
|
||||||
let getStateSpy: jest.SpyInstance;
|
let getStateSpy: jest.SpyInstance;
|
||||||
let saveCacheSpy: jest.SpyInstance;
|
let saveCacheSpy: jest.SpyInstance;
|
||||||
|
let setOutputSpy: jest.SpyInstance;
|
||||||
let getCommandOutputSpy: jest.SpyInstance;
|
let getCommandOutputSpy: jest.SpyInstance;
|
||||||
let hashFilesSpy: jest.SpyInstance;
|
let hashFilesSpy: jest.SpyInstance;
|
||||||
let existsSpy: jest.SpyInstance;
|
let existsSpy: jest.SpyInstance;
|
||||||
@@ -53,6 +54,8 @@ describe('run', () => {
|
|||||||
saveCacheSpy = jest.spyOn(cache, 'saveCache');
|
saveCacheSpy = jest.spyOn(cache, 'saveCache');
|
||||||
saveCacheSpy.mockImplementation(() => undefined);
|
saveCacheSpy.mockImplementation(() => undefined);
|
||||||
|
|
||||||
|
setOutputSpy = jest.spyOn(core, 'setOutput');
|
||||||
|
|
||||||
// glob
|
// glob
|
||||||
hashFilesSpy = jest.spyOn(glob, 'hashFiles');
|
hashFilesSpy = jest.spyOn(glob, 'hashFiles');
|
||||||
hashFilesSpy.mockImplementation((pattern: string) => {
|
hashFilesSpy.mockImplementation((pattern: string) => {
|
||||||
@@ -228,6 +231,7 @@ describe('run', () => {
|
|||||||
expect(infoSpy).toHaveBeenLastCalledWith(
|
expect(infoSpy).toHaveBeenLastCalledWith(
|
||||||
`Cache saved with the key: ${npmFileHash}`
|
`Cache saved with the key: ${npmFileHash}`
|
||||||
);
|
);
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith('cache-key', npmFileHash);
|
||||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
expect(setFailedSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -258,6 +262,7 @@ describe('run', () => {
|
|||||||
expect(infoSpy).toHaveBeenLastCalledWith(
|
expect(infoSpy).toHaveBeenLastCalledWith(
|
||||||
`Cache saved with the key: ${npmFileHash}`
|
`Cache saved with the key: ${npmFileHash}`
|
||||||
);
|
);
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith('cache-key', npmFileHash);
|
||||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
expect(setFailedSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -288,6 +293,7 @@ describe('run', () => {
|
|||||||
expect(infoSpy).toHaveBeenLastCalledWith(
|
expect(infoSpy).toHaveBeenLastCalledWith(
|
||||||
`Cache saved with the key: ${yarnFileHash}`
|
`Cache saved with the key: ${yarnFileHash}`
|
||||||
);
|
);
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith('cache-key', yarnFileHash);
|
||||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
expect(setFailedSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -297,9 +303,9 @@ describe('run', () => {
|
|||||||
key === State.CachePackageManager
|
key === State.CachePackageManager
|
||||||
? inputs['cache']
|
? inputs['cache']
|
||||||
: key === State.CacheMatchedKey
|
: key === State.CacheMatchedKey
|
||||||
? pnpmFileHash
|
? 'no-match'
|
||||||
: key === State.CachePrimaryKey
|
: key === State.CachePrimaryKey
|
||||||
? npmFileHash
|
? pnpmFileHash
|
||||||
: key === State.CachePaths
|
: key === State.CachePaths
|
||||||
? '["/foo/bar"]'
|
? '["/foo/bar"]'
|
||||||
: 'not expected'
|
: 'not expected'
|
||||||
@@ -316,8 +322,9 @@ describe('run', () => {
|
|||||||
);
|
);
|
||||||
expect(saveCacheSpy).toHaveBeenCalled();
|
expect(saveCacheSpy).toHaveBeenCalled();
|
||||||
expect(infoSpy).toHaveBeenLastCalledWith(
|
expect(infoSpy).toHaveBeenLastCalledWith(
|
||||||
`Cache saved with the key: ${npmFileHash}`
|
`Cache saved with the key: ${pnpmFileHash}`
|
||||||
);
|
);
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith('cache-key', pnpmFileHash);
|
||||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
expect(setFailedSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ inputs:
|
|||||||
outputs:
|
outputs:
|
||||||
cache-hit:
|
cache-hit:
|
||||||
description: 'A boolean value to indicate if a cache was hit.'
|
description: 'A boolean value to indicate if a cache was hit.'
|
||||||
|
cache-key:
|
||||||
|
description: 'The key used for the cache.'
|
||||||
|
cache-matched-key:
|
||||||
|
description: 'The key used for the cache that resulted in a cache hit.'
|
||||||
node-version:
|
node-version:
|
||||||
description: 'The installed node version.'
|
description: 'The installed node version.'
|
||||||
runs:
|
runs:
|
||||||
|
|||||||
1383
dist/cache-save/index.js
vendored
1383
dist/cache-save/index.js
vendored
File diff suppressed because it is too large
Load Diff
4531
dist/setup/index.js
vendored
4531
dist/setup/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -45,6 +45,7 @@ export const restoreCache = async (
|
|||||||
core.debug(`primary key is ${primaryKey}`);
|
core.debug(`primary key is ${primaryKey}`);
|
||||||
|
|
||||||
core.saveState(State.CachePrimaryKey, primaryKey);
|
core.saveState(State.CachePrimaryKey, primaryKey);
|
||||||
|
core.setOutput('cache-key', primaryKey);
|
||||||
|
|
||||||
const isManagedByYarnBerry = await repoHasYarnBerryManagedDependencies(
|
const isManagedByYarnBerry = await repoHasYarnBerryManagedDependencies(
|
||||||
packageManagerInfo,
|
packageManagerInfo,
|
||||||
@@ -61,6 +62,8 @@ export const restoreCache = async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
core.setOutput('cache-hit', Boolean(cacheKey));
|
core.setOutput('cache-hit', Boolean(cacheKey));
|
||||||
|
core.setOutput('cache-matched-key', cacheKey);
|
||||||
|
core.debug(`cache-matched-key is ${cacheKey}`);
|
||||||
|
|
||||||
if (!cacheKey) {
|
if (!cacheKey) {
|
||||||
core.info(`${packageManager} cache is not found`);
|
core.info(`${packageManager} cache is not found`);
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ const cachePackages = async (packageManager: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
core.info(`Cache saved with the key: ${primaryKey}`);
|
core.info(`Cache saved with the key: ${primaryKey}`);
|
||||||
|
core.setOutput('cache-key', primaryKey);
|
||||||
};
|
};
|
||||||
|
|
||||||
run(true);
|
run(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user