-
Notifications
You must be signed in to change notification settings - Fork 668
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
Reorganize upload code in prep for merge logic & add more tests #504
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,231 @@ | ||
import * as core from '@actions/core' | ||
import * as github from '@actions/github' | ||
import artifact, {ArtifactNotFoundError} from '@actions/artifact' | ||
import {run} from '../src/upload/upload-artifact' | ||
import {Inputs} from '../src/upload/constants' | ||
import * as search from '../src/shared/search' | ||
|
||
const fixtures = { | ||
artifactName: 'artifact-name', | ||
rootDirectory: '/some/artifact/path', | ||
filesToUpload: [ | ||
'/some/artifact/path/file1.txt', | ||
'/some/artifact/path/file2.txt' | ||
] | ||
} | ||
|
||
jest.mock('@actions/github', () => ({ | ||
context: { | ||
repo: { | ||
owner: 'actions', | ||
repo: 'toolkit' | ||
}, | ||
runId: 123, | ||
serverUrl: 'https://github.com' | ||
} | ||
})) | ||
|
||
jest.mock('@actions/core') | ||
|
||
/* eslint-disable no-unused-vars */ | ||
const mockInputs = (overrides?: Partial<{[K in Inputs]?: any}>) => { | ||
const inputs = { | ||
[Inputs.Name]: 'artifact-name', | ||
[Inputs.Path]: '/some/artifact/path', | ||
[Inputs.IfNoFilesFound]: 'warn', | ||
[Inputs.RetentionDays]: 0, | ||
[Inputs.CompressionLevel]: 6, | ||
[Inputs.Overwrite]: false, | ||
...overrides | ||
} | ||
|
||
;(core.getInput as jest.Mock).mockImplementation((name: string) => { | ||
return inputs[name] | ||
}) | ||
;(core.getBooleanInput as jest.Mock).mockImplementation((name: string) => { | ||
return inputs[name] | ||
}) | ||
|
||
return inputs | ||
} | ||
|
||
describe('upload', () => { | ||
beforeEach(async () => { | ||
mockInputs() | ||
|
||
jest.spyOn(search, 'findFilesToUpload').mockResolvedValue({ | ||
filesToUpload: fixtures.filesToUpload, | ||
rootDirectory: fixtures.rootDirectory | ||
}) | ||
|
||
jest.spyOn(artifact, 'uploadArtifact').mockResolvedValue({ | ||
size: 123, | ||
id: 1337 | ||
}) | ||
}) | ||
|
||
it('uploads a single file', async () => { | ||
jest.spyOn(search, 'findFilesToUpload').mockResolvedValue({ | ||
filesToUpload: [fixtures.filesToUpload[0]], | ||
rootDirectory: fixtures.rootDirectory | ||
}) | ||
|
||
await run() | ||
|
||
expect(artifact.uploadArtifact).toHaveBeenCalledWith( | ||
fixtures.artifactName, | ||
[fixtures.filesToUpload[0]], | ||
fixtures.rootDirectory, | ||
{compressionLevel: 6} | ||
) | ||
}) | ||
|
||
it('uploads multiple files', async () => { | ||
await run() | ||
|
||
expect(artifact.uploadArtifact).toHaveBeenCalledWith( | ||
fixtures.artifactName, | ||
fixtures.filesToUpload, | ||
fixtures.rootDirectory, | ||
{compressionLevel: 6} | ||
) | ||
}) | ||
|
||
it('sets outputs', async () => { | ||
await run() | ||
|
||
expect(core.setOutput).toHaveBeenCalledWith('artifact-id', 1337) | ||
expect(core.setOutput).toHaveBeenCalledWith( | ||
'artifact-url', | ||
`${github.context.serverUrl}/${github.context.repo.owner}/${ | ||
github.context.repo.repo | ||
}/actions/runs/${github.context.runId}/artifacts/${1337}` | ||
) | ||
}) | ||
|
||
it('supports custom compression level', async () => { | ||
mockInputs({ | ||
[Inputs.CompressionLevel]: 2 | ||
}) | ||
|
||
await run() | ||
|
||
expect(artifact.uploadArtifact).toHaveBeenCalledWith( | ||
fixtures.artifactName, | ||
fixtures.filesToUpload, | ||
fixtures.rootDirectory, | ||
{compressionLevel: 2} | ||
) | ||
}) | ||
|
||
it('supports custom retention days', async () => { | ||
mockInputs({ | ||
[Inputs.RetentionDays]: 7 | ||
}) | ||
|
||
await run() | ||
|
||
expect(artifact.uploadArtifact).toHaveBeenCalledWith( | ||
fixtures.artifactName, | ||
fixtures.filesToUpload, | ||
fixtures.rootDirectory, | ||
{retentionDays: 7, compressionLevel: 6} | ||
) | ||
}) | ||
|
||
it('supports warn if-no-files-found', async () => { | ||
mockInputs({ | ||
[Inputs.IfNoFilesFound]: 'warn' | ||
}) | ||
|
||
jest.spyOn(search, 'findFilesToUpload').mockResolvedValue({ | ||
filesToUpload: [], | ||
rootDirectory: fixtures.rootDirectory | ||
}) | ||
|
||
await run() | ||
|
||
expect(core.warning).toHaveBeenCalledWith( | ||
`No files were found with the provided path: ${fixtures.rootDirectory}. No artifacts will be uploaded.` | ||
) | ||
}) | ||
|
||
it('supports error if-no-files-found', async () => { | ||
mockInputs({ | ||
[Inputs.IfNoFilesFound]: 'error' | ||
}) | ||
|
||
jest.spyOn(search, 'findFilesToUpload').mockResolvedValue({ | ||
filesToUpload: [], | ||
rootDirectory: fixtures.rootDirectory | ||
}) | ||
|
||
await run() | ||
|
||
expect(core.setFailed).toHaveBeenCalledWith( | ||
`No files were found with the provided path: ${fixtures.rootDirectory}. No artifacts will be uploaded.` | ||
) | ||
}) | ||
|
||
it('supports ignore if-no-files-found', async () => { | ||
mockInputs({ | ||
[Inputs.IfNoFilesFound]: 'ignore' | ||
}) | ||
|
||
jest.spyOn(search, 'findFilesToUpload').mockResolvedValue({ | ||
filesToUpload: [], | ||
rootDirectory: fixtures.rootDirectory | ||
}) | ||
|
||
await run() | ||
|
||
expect(core.info).toHaveBeenCalledWith( | ||
`No files were found with the provided path: ${fixtures.rootDirectory}. No artifacts will be uploaded.` | ||
) | ||
}) | ||
|
||
it('supports overwrite', async () => { | ||
mockInputs({ | ||
[Inputs.Overwrite]: true | ||
}) | ||
|
||
jest.spyOn(artifact, 'deleteArtifact').mockResolvedValue({ | ||
id: 1337 | ||
}) | ||
|
||
await run() | ||
|
||
expect(artifact.uploadArtifact).toHaveBeenCalledWith( | ||
fixtures.artifactName, | ||
fixtures.filesToUpload, | ||
fixtures.rootDirectory, | ||
{compressionLevel: 6} | ||
) | ||
|
||
expect(artifact.deleteArtifact).toHaveBeenCalledWith(fixtures.artifactName) | ||
}) | ||
|
||
it('supports overwrite and continues if not found', async () => { | ||
mockInputs({ | ||
[Inputs.Overwrite]: true | ||
}) | ||
|
||
jest | ||
.spyOn(artifact, 'deleteArtifact') | ||
.mockRejectedValue(new ArtifactNotFoundError('not found')) | ||
|
||
await run() | ||
|
||
expect(artifact.uploadArtifact).toHaveBeenCalledWith( | ||
fixtures.artifactName, | ||
fixtures.filesToUpload, | ||
fixtures.rootDirectory, | ||
{compressionLevel: 6} | ||
) | ||
|
||
expect(artifact.deleteArtifact).toHaveBeenCalledWith(fixtures.artifactName) | ||
expect(core.debug).toHaveBeenCalledWith( | ||
`Skipping deletion of '${fixtures.artifactName}', it does not exist` | ||
) | ||
}) | ||
}) |
This file contains 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: this was not working properly, the build npm script did not change the
dist/
contents. I fixed it so it's properly calling release now to ncc the new js