Skip to content

Commit 7409ad5

Browse files
Aiqiao YanAiqiao Yan
authored andcommitted
Change variable path to a list
1 parent 932779c commit 7409ad5

File tree

9 files changed

+213
-411
lines changed

9 files changed

+213
-411
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ $ npm install @actions/artifact --save
8787
Provides functions to interact with actions cache. Read more [here](packages/cache)
8888

8989
```bash
90-
$ npm install @actions/artifact --save
90+
$ npm install @actions/cache --save
9191
```
9292
<br/>
9393

packages/cache/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
11
# `@actions/cache`
2+
3+
> Functions necessary for caching dependencies and build outputs to improve workflow execution time.
4+
5+
## Usage
6+
7+
#### Restore Cache
8+
9+
#### Save Cache
10+
11+
## Additional Documentation
12+
13+
See ["Caching dependencies to speed up workflows"](https://help.github.com/github/automating-your-workflow-with-github-actions/caching-dependencies-to-speed-up-workflows).

packages/cache/__tests__/cacheHttpClient.test.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
import {getCacheVersion} from '../src/internal/cacheHttpClient'
22
import {CompressionMethod} from '../src/internal/constants'
33

4-
test('getCacheVersion with path input and compression method undefined returns version', async () => {
5-
const inputPath = 'node_modules'
6-
const result = getCacheVersion(inputPath)
4+
test('getCacheVersion with one path returns version', async () => {
5+
const paths = ['node_modules']
6+
const result = getCacheVersion(paths)
77
expect(result).toEqual(
88
'b3e0c6cb5ecf32614eeb2997d905b9c297046d7cbf69062698f25b14b4cb0985'
99
)
1010
})
1111

12+
test('getCacheVersion with multiple paths returns version', async () => {
13+
const paths = ['node_modules', 'dist']
14+
const result = getCacheVersion(paths)
15+
expect(result).toEqual(
16+
'165c3053bc646bf0d4fac17b1f5731caca6fe38e0e464715c0c3c6b6318bf436'
17+
)
18+
})
19+
1220
test('getCacheVersion with zstd compression returns version', async () => {
13-
const inputPath = 'node_modules'
14-
const result = getCacheVersion(inputPath, CompressionMethod.Zstd)
21+
const paths = ['node_modules']
22+
const result = getCacheVersion(paths, CompressionMethod.Zstd)
1523

1624
expect(result).toEqual(
1725
'273877e14fd65d270b87a198edbfa2db5a43de567c9a548d2a2505b408befe24'
1826
)
1927
})
2028

2129
test('getCacheVersion with gzip compression does not change vesion', async () => {
22-
const inputPath = 'node_modules'
23-
const result = getCacheVersion(inputPath, CompressionMethod.Gzip)
30+
const paths = ['node_modules']
31+
const result = getCacheVersion(paths, CompressionMethod.Gzip)
2432

2533
expect(result).toEqual(
2634
'b3e0c6cb5ecf32614eeb2997d905b9c297046d7cbf69062698f25b14b4cb0985'

packages/cache/__tests__/cacheUtils.test.ts

Lines changed: 0 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import * as core from '@actions/core'
21
import * as io from '@actions/io'
32
import {promises as fs} from 'fs'
4-
import * as os from 'os'
53
import * as path from 'path'
6-
import {v4 as uuidV4} from 'uuid'
74
import * as cacheUtils from '../src/internal/cacheUtils'
85

96
jest.mock('@actions/core')
@@ -26,143 +23,6 @@ test('getArchiveFileSize returns file size', () => {
2623
expect(size).toBe(11)
2724
})
2825

29-
test('logWarning logs a message with a warning prefix', () => {
30-
const message = 'A warning occurred.'
31-
32-
const infoMock = jest.spyOn(core, 'info')
33-
34-
cacheUtils.logWarning(message)
35-
36-
expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`)
37-
})
38-
39-
test('resolvePaths with no ~ in path', async () => {
40-
const filePath = '.cache'
41-
42-
// Create the following layout:
43-
// cwd
44-
// cwd/.cache
45-
// cwd/.cache/file.txt
46-
47-
const root = path.join(getTempDir(), 'no-tilde')
48-
// tarball entries will be relative to workspace
49-
process.env['GITHUB_WORKSPACE'] = root
50-
51-
await fs.mkdir(root, {recursive: true})
52-
const cache = path.join(root, '.cache')
53-
await fs.mkdir(cache, {recursive: true})
54-
await fs.writeFile(path.join(cache, 'file.txt'), 'cached')
55-
56-
const originalCwd = process.cwd()
57-
58-
try {
59-
process.chdir(root)
60-
61-
const resolvedPath = await cacheUtils.resolvePaths([filePath])
62-
63-
const expectedPath = [filePath]
64-
expect(resolvedPath).toStrictEqual(expectedPath)
65-
} finally {
66-
process.chdir(originalCwd)
67-
}
68-
})
69-
70-
test('resolvePaths with ~ in path', async () => {
71-
const cacheDir = uuidV4()
72-
const filePath = `~/${cacheDir}`
73-
// Create the following layout:
74-
// ~/uuid
75-
// ~/uuid/file.txt
76-
77-
const homedir = jest.requireActual('os').homedir()
78-
const homedirMock = jest.spyOn(os, 'homedir')
79-
homedirMock.mockReturnValue(homedir)
80-
81-
const target = path.join(homedir, cacheDir)
82-
await fs.mkdir(target, {recursive: true})
83-
await fs.writeFile(path.join(target, 'file.txt'), 'cached')
84-
85-
const root = getTempDir()
86-
process.env['GITHUB_WORKSPACE'] = root
87-
88-
try {
89-
const resolvedPath = await cacheUtils.resolvePaths([filePath])
90-
91-
const expectedPath = [path.relative(root, target)]
92-
expect(resolvedPath).toStrictEqual(expectedPath)
93-
} finally {
94-
await io.rmRF(target)
95-
}
96-
})
97-
98-
test('resolvePaths with home not found', async () => {
99-
const filePath = '~/.cache/yarn'
100-
const homedirMock = jest.spyOn(os, 'homedir')
101-
homedirMock.mockReturnValue('')
102-
103-
await expect(cacheUtils.resolvePaths([filePath])).rejects.toThrow(
104-
'Unable to determine HOME directory'
105-
)
106-
})
107-
108-
test('resolvePaths inclusion pattern returns found', async () => {
109-
const pattern = '*.ts'
110-
// Create the following layout:
111-
// inclusion-patterns
112-
// inclusion-patterns/miss.txt
113-
// inclusion-patterns/test.ts
114-
115-
const root = path.join(getTempDir(), 'inclusion-patterns')
116-
// tarball entries will be relative to workspace
117-
process.env['GITHUB_WORKSPACE'] = root
118-
119-
await fs.mkdir(root, {recursive: true})
120-
await fs.writeFile(path.join(root, 'miss.txt'), 'no match')
121-
await fs.writeFile(path.join(root, 'test.ts'), 'match')
122-
123-
const originalCwd = process.cwd()
124-
125-
try {
126-
process.chdir(root)
127-
128-
const resolvedPath = await cacheUtils.resolvePaths([pattern])
129-
130-
const expectedPath = ['test.ts']
131-
expect(resolvedPath).toStrictEqual(expectedPath)
132-
} finally {
133-
process.chdir(originalCwd)
134-
}
135-
})
136-
137-
test('resolvePaths exclusion pattern returns not found', async () => {
138-
const patterns = ['*.ts', '!test.ts']
139-
// Create the following layout:
140-
// exclusion-patterns
141-
// exclusion-patterns/miss.txt
142-
// exclusion-patterns/test.ts
143-
144-
const root = path.join(getTempDir(), 'exclusion-patterns')
145-
// tarball entries will be relative to workspace
146-
process.env['GITHUB_WORKSPACE'] = root
147-
148-
await fs.mkdir(root, {recursive: true})
149-
await fs.writeFile(path.join(root, 'miss.txt'), 'no match')
150-
await fs.writeFile(path.join(root, 'test.ts'), 'no match')
151-
152-
const originalCwd = process.cwd()
153-
154-
try {
155-
process.chdir(root)
156-
157-
const resolvedPath = await cacheUtils.resolvePaths(patterns)
158-
159-
const expectedPath: string[] = []
160-
expect(resolvedPath).toStrictEqual(expectedPath)
161-
} finally {
162-
process.chdir(originalCwd)
163-
}
164-
})
165-
16626
test('unlinkFile unlinks file', async () => {
16727
const testDirectory = await fs.mkdtemp('unlinkFileTest')
16828
const testFile = path.join(testDirectory, 'test.txt')

0 commit comments

Comments
 (0)