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

@actions/artifact package #304

Merged
merged 48 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
3a20113
Initial commit for @actions/artifact
Jan 13, 2020
776270f
Alphabetize imports
Jan 13, 2020
f3ac746
Fix majority of lint errors
Jan 13, 2020
bd38a3f
Fix all lint errors
Jan 14, 2020
b2d67bb
Various fixes due to PR feedback
Jan 14, 2020
029f2a4
Add tests for search
Jan 15, 2020
4fda766
Rename test file
Jan 15, 2020
e025ef0
Test improvements
Jan 15, 2020
11c006c
Misc formatting fixes
Jan 15, 2020
4431cd8
Tests for artifactName
konradpabjan Jan 15, 2020
7cf5770
Misc improvements
konradpabjan Jan 28, 2020
b56cdb0
Hopefully fix failing tests
konradpabjan Jan 28, 2020
6b04ca5
🤞 this works
konradpabjan Jan 28, 2020
e12553e
Hmmm
konradpabjan Jan 28, 2020
83c8848
Really weird...
konradpabjan Jan 28, 2020
b6f59a0
Update tests for util.ts
konradpabjan Jan 28, 2020
c6d23c0
Succesfull http mocking along with more tests
konradpabjan Jan 30, 2020
da72c73
Spelling fixes and misc updates
Jan 30, 2020
206233a
Logic for fast failing in the event a chunk fails
Jan 30, 2020
e6f5591
Tests for artifact uploads
Jan 31, 2020
7f48237
Minor fixes
Jan 31, 2020
ddfdb57
PR Feedback
Jan 31, 2020
0768705
Format fix
Jan 31, 2020
31ff9e6
Fixes error with unbound methods being used in tests
konradpabjan Feb 1, 2020
c5216d2
.
konradpabjan Feb 1, 2020
a375c57
Remove directory deletion after tests finish
konradpabjan Feb 3, 2020
c71237b
Remove project GUID from API call
Feb 3, 2020
0cc46af
Misc Improvements
Feb 3, 2020
6f6aac1
Code cleanup
Feb 3, 2020
cd5d31a
Extra debug
Feb 3, 2020
09b1c39
Move glob search out of the package
Feb 4, 2020
049110f
Code cleanup
Feb 4, 2020
abd642c
Rename some thing and cleanup
Feb 4, 2020
813bcf1
Rename uploadInfo to uploadResponse
Feb 6, 2020
c8d2dd1
Misc Improvements
Feb 7, 2020
1dd4152
Format Fix
Feb 7, 2020
1fa883d
Test Improvements
Feb 7, 2020
7c6e6ac
Updates to continueOnError
Feb 7, 2020
6b6a5e0
Extra test
Feb 7, 2020
4ac6ef6
Normalize and Resolve all paths
Feb 7, 2020
d01f0f3
Change console.log to warning
Feb 7, 2020
7917754
Update upload-response.ts
konradpabjan Feb 10, 2020
21ce5cb
PR feedback
konradpabjan Feb 10, 2020
78605ae
Merge branch 'konradpabjan/actions/artifact' of https://github.com/ac…
konradpabjan Feb 10, 2020
fcec6a7
Update upload-http-client.ts
konradpabjan Feb 10, 2020
5288533
Silence output when running tests and rename files with internal
konradpabjan Feb 10, 2020
8a1220b
Use Factory to create ArtifactClient
konradpabjan Feb 10, 2020
332dfce
Merge branch 'konradpabjan/actions/artifact' of https://github.com/ac…
konradpabjan Feb 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added packages/artifact/README.md
Empty file.
290 changes: 290 additions & 0 deletions packages/artifact/__tests__/search.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
import {promises as fs} from 'fs'
import * as path from 'path'
import {findFilesToUpload} from '../src/search'
import * as io from '../../io/src/io'

const artifactName = 'my-artifact'
const root = path.join(__dirname, '_temp', 'artifact-search')
const goodItem1Path = path.join(
root,
'folder-a',
'folder-b',
'folder-c',
'good-item1.txt'
)
const goodItem2Path = path.join(root, 'folder-d', 'good-item2.txt')
const goodItem3Path = path.join(root, 'folder-d', 'good-item3.txt')
const goodItem4Path = path.join(root, 'folder-d', 'good-item4.txt')
const goodItem5Path = path.join(root, 'good-item5.txt')
const badItem1Path = path.join(
root,
'folder-a',
'folder-b',
'folder-c',
'bad-item1.txt'
)
const badItem2Path = path.join(root, 'folder-d', 'bad-item2.txt')
const badItem3Path = path.join(root, 'folder-f', 'bad-item3.txt')
const badItem4Path = path.join(root, 'folder-h', 'folder-i', 'bad-item4.txt')
const badItem5Path = path.join(root, 'folder-h', 'folder-i', 'bad-item5.txt')
const extraFileInFolderCPath = path.join(
root,
'folder-a',
'folder-b',
'folder-c',
'extra-file-in-folder-c.txt'
)
const amazingFileinFolderHPath = path.join(root, 'folder-h', 'amazing-item.txt')

describe('Search', () => {
beforeAll(async () => {
// clear temp directory
await io.rmRF(root)
await fs.mkdir(path.join(root, 'folder-a', 'folder-b', 'folder-c'), {
recursive: true
})
await fs.mkdir(path.join(root, 'folder-a', 'folder-b', 'folder-e'), {
recursive: true
})
await fs.mkdir(path.join(root, 'folder-d'), {
recursive: true
})
await fs.mkdir(path.join(root, 'folder-f'), {
recursive: true
})
await fs.mkdir(path.join(root, 'folder-g'), {
recursive: true
})
await fs.mkdir(path.join(root, 'folder-h', 'folder-i'), {
recursive: true
})

await fs.writeFile(goodItem1Path, 'good item1 file')
await fs.writeFile(goodItem2Path, 'good item2 file')
await fs.writeFile(goodItem3Path, 'good item3 file')
await fs.writeFile(goodItem4Path, 'good item4 file')
await fs.writeFile(goodItem5Path, 'good item5 file')

await fs.writeFile(badItem1Path, 'bad item1 file')
await fs.writeFile(badItem2Path, 'bad item2 file')
await fs.writeFile(badItem3Path, 'bad item3 file')
await fs.writeFile(badItem4Path, 'bad item4 file')
await fs.writeFile(badItem5Path, 'bad item5 file')

await fs.writeFile(extraFileInFolderCPath, 'extra file')

await fs.writeFile(amazingFileinFolderHPath, 'amazing file')
/*
Directory structure of files that were created:
root/
folder-a/
folder-b/
folder-c/
good-item1.txt
bad-item1.txt
extra-file-in-folder-c.txt
folder-e/
folder-d/
good-item2.txt
good-item3.txt
good-item4.txt
bad-item2.txt
folder-f/
bad-item3.txt
folder-g/
folder-h/
amazing-item.txt
folder-i/
bad-item4.txt
bad-item5.txt
good-item5.txt
*/
})

afterAll(async () => {
await io.rmRF(root)
})

/**
* Creates a single item in <TempDir>/single-file-artifact/folder-a/folder-b/folder-b/file-under-c.txt
* Expected to find that item with full file path provided
* Only 1 item is expected to be found so the uploadFilePath is expected to be {artifactName}/file-under-c.txt
*/
it('Single file search - full path', async () => {
const exepectedUploadFilePath = path.join(
artifactName,
'extra-file-in-folder-c.txt'
)
const searchResult = await findFilesToUpload(
artifactName,
extraFileInFolderCPath
)
/*
searchResult[] should be equal to:
[
{
absoluteFilePath: extraFileInFolderCPath
uploadFilePath: my-artifact/extra-file-in-folder-c.txt
}
]
*/

expect(searchResult.length).toEqual(1)
expect(searchResult[0].uploadFilePath).toEqual(exepectedUploadFilePath)
expect(searchResult[0].absoluteFilePath).toEqual(extraFileInFolderCPath)
})

/**
* Creates a single item in <TempDir>/single-file-artifact/folder-a/folder-b/folder-b/file-under-c.txt
* Expected to find that one item with a provided wildcard pattern
* Only 1 item is expected to be found so the uploadFilePath is expected to be {artifactName}/file-under-c.txt
*/
it('Single file search - wildcard pattern', async () => {
const searchPath = path.join(root, '**/good*m1.txt')
const exepectedUploadFilePath = path.join(artifactName, 'good-item1.txt')
const searchResult = await findFilesToUpload(artifactName, searchPath)
/*
searchResult should be equal to:
[
{
absoluteFilePath: goodItem1Path
uploadFilePath: my-artifact/good-item1.txt
}
]
*/

expect(searchResult.length).toEqual(1)
expect(searchResult[0].uploadFilePath).toEqual(exepectedUploadFilePath)
expect(searchResult[0].absoluteFilePath).toEqual(goodItem1Path)
})

/**
* Creates a directory with multiple files and subdirectories, includes some empty directories and misc files
* Only files corresponding to the good* pattern should be found
*/
it('Wildcard search for mulitple files', async () => {
const searchPath = path.join(root, '**/good*')
const searchResult = await findFilesToUpload(artifactName, searchPath)
/*
searchResult should be equal to:
[
{
absoluteFilePath: goodItem1Path
uploadFilePath: my-artifact/folder-a/folder-b/folder-c/good-item1.txt
},
{
absoluteFilePath: goodItem2Path
uploadFilePath: my-artifact/folder-d/good-item2.txt
},
{
absoluteFilePath: goodItem3Path
uploadFilePath: my-artifact/folder-d/good-item3.txt
},
{
absoluteFilePath: goodItem4Path
uploadFilePath: my-artifact/folder-d/good-item4.txt
},
{
absoluteFilePath: goodItem5Path
uploadFilePath: my-artifact/good-item5.txt
}
]
*/

expect(searchResult.length).toEqual(5)

const absolutePaths = searchResult.map(item => item.absoluteFilePath)
expect(absolutePaths.includes(goodItem1Path)).toEqual(true)
expect(absolutePaths.includes(goodItem2Path)).toEqual(true)
expect(absolutePaths.includes(goodItem3Path)).toEqual(true)
expect(absolutePaths.includes(goodItem4Path)).toEqual(true)
expect(absolutePaths.includes(goodItem5Path)).toEqual(true)

for (const result of searchResult) {
if (result.absoluteFilePath === goodItem1Path) {
expect(result.uploadFilePath).toEqual(
path.join(
artifactName,
'folder-a',
'folder-b',
'folder-c',
'good-item1.txt'
)
)
}
if (result.absoluteFilePath === goodItem2Path) {
expect(result.uploadFilePath).toEqual(
path.join(artifactName, 'folder-d', 'good-item2.txt')
)
}
if (result.absoluteFilePath === goodItem3Path) {
expect(result.uploadFilePath).toEqual(
path.join(artifactName, 'folder-d', 'good-item3.txt')
)
}
if (result.absoluteFilePath === goodItem4Path) {
expect(result.uploadFilePath).toEqual(
path.join(artifactName, 'folder-d', 'good-item4.txt')
)
}
if (result.absoluteFilePath === goodItem5Path) {
expect(result.uploadFilePath).toEqual(
path.join(artifactName, 'good-item5.txt')
)
}
}
})

/**
* Creates a directory with multiple files and subdirectories, includes some empty directories
* All items are expected to be found
*/
it('Directory search - find everything', async () => {
const searchResult = await findFilesToUpload(
artifactName,
path.join(root, 'folder-h')
)
/*
searchResult should be equal to:
[
{
absoluteFilePath: amazingFileinFolderHPath
uploadFilePath: my-artifact/folder-h/amazing-item.txt
},
{
absoluteFilePath: badItem4Path
uploadFilePath: my-artifact/folder-h/folder-i/bad-item4.txt
},
{
absoluteFilePath: badItem5Path
uploadFilePath: my-artifact/folder-h/folder-i/bad-item5.txt
}
]
*/

expect(searchResult.length).toEqual(3)

const absolutePaths = searchResult.map(item => item.absoluteFilePath)
expect(absolutePaths.includes(amazingFileinFolderHPath)).toEqual(true)
expect(absolutePaths.includes(badItem4Path)).toEqual(true)
expect(absolutePaths.includes(badItem5Path)).toEqual(true)

for (const result of searchResult) {
if (result.absoluteFilePath === amazingFileinFolderHPath) {
expect(result.uploadFilePath).toEqual(
path.join(artifactName, 'amazing-item.txt')
)
}
if (result.absoluteFilePath === badItem4Path) {
expect(result.uploadFilePath).toEqual(
path.join(artifactName, 'folder-i', 'bad-item4.txt')
)
}
if (result.absoluteFilePath === badItem5Path) {
expect(result.uploadFilePath).toEqual(
path.join(artifactName, 'folder-i', 'bad-item5.txt')
)
}
}
})
})
Loading