-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Artifacts] Exempt certain types of files from gzip compression (#956)
* Exempt certain types of files from gzip compression * Fix lint issue
- Loading branch information
1 parent
88062ec
commit cdd4e10
Showing
2 changed files
with
100 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as core from '@actions/core' | ||
import * as tmp from 'tmp-promise' | ||
import * as path from 'path' | ||
import * as io from '../../io/src/io' | ||
import {promises as fs} from 'fs' | ||
import {createGZipFileOnDisk} from '../src/internal/upload-gzip' | ||
|
||
const root = path.join(__dirname, '_temp', 'upload-gzip') | ||
const tempGzipFilePath = path.join(root, 'file1.gzip') | ||
const tempZipFilePath = path.join(root, 'file2.zip') | ||
const tempTarlzFilePath = path.join(root, 'file3.tar.lz') | ||
const tempGzFilePath = path.join(root, 'file4.tar.gz') | ||
const tempBz2FilePath = path.join(root, 'file5.tar.bz2') | ||
const temp7zFilePath = path.join(root, 'file6.7z') | ||
const tempNormalFilePath = path.join(root, 'file6.txt') | ||
|
||
jest.mock('../src/internal/config-variables') | ||
|
||
beforeAll(async () => { | ||
// mock all output so that there is less noise when running tests | ||
jest.spyOn(console, 'log').mockImplementation(() => {}) | ||
jest.spyOn(core, 'debug').mockImplementation(() => {}) | ||
jest.spyOn(core, 'info').mockImplementation(() => {}) | ||
jest.spyOn(core, 'warning').mockImplementation(() => {}) | ||
jest.spyOn(core, 'error').mockImplementation(() => {}) | ||
|
||
// clear temp directory and create files that will be "uploaded" | ||
await io.rmRF(root) | ||
await fs.mkdir(path.join(root)) | ||
await fs.writeFile(tempGzipFilePath, 'a file with a .gzip file extension') | ||
await fs.writeFile(tempZipFilePath, 'a file with a .zip file extension') | ||
await fs.writeFile(tempTarlzFilePath, 'a file with a tar.lz file extension') | ||
await fs.writeFile(tempGzFilePath, 'a file with a gz file file extension') | ||
await fs.writeFile(tempBz2FilePath, 'a file with a .bz2 file extension') | ||
await fs.writeFile(temp7zFilePath, 'a file with a .7z file extension') | ||
await fs.writeFile(tempNormalFilePath, 'a file with a .txt file extension') | ||
}) | ||
|
||
test('Number.MAX_SAFE_INTEGER is returned when an existing compressed file is used', async () => { | ||
// create temporary file | ||
const tempFile = await tmp.file() | ||
|
||
expect(await createGZipFileOnDisk(tempGzipFilePath, tempFile.path)).toEqual( | ||
Number.MAX_SAFE_INTEGER | ||
) | ||
expect(await createGZipFileOnDisk(tempZipFilePath, tempFile.path)).toEqual( | ||
Number.MAX_SAFE_INTEGER | ||
) | ||
expect(await createGZipFileOnDisk(tempTarlzFilePath, tempFile.path)).toEqual( | ||
Number.MAX_SAFE_INTEGER | ||
) | ||
expect(await createGZipFileOnDisk(tempGzFilePath, tempFile.path)).toEqual( | ||
Number.MAX_SAFE_INTEGER | ||
) | ||
expect(await createGZipFileOnDisk(tempBz2FilePath, tempFile.path)).toEqual( | ||
Number.MAX_SAFE_INTEGER | ||
) | ||
expect(await createGZipFileOnDisk(temp7zFilePath, tempFile.path)).toEqual( | ||
Number.MAX_SAFE_INTEGER | ||
) | ||
expect( | ||
await createGZipFileOnDisk(tempNormalFilePath, tempFile.path) | ||
).not.toEqual(Number.MAX_SAFE_INTEGER) | ||
}) | ||
|
||
test('gzip file on disk gets successfully created', async () => { | ||
// create temporary file | ||
const tempFile = await tmp.file() | ||
|
||
const gzipFileSize = await createGZipFileOnDisk( | ||
tempNormalFilePath, | ||
tempFile.path | ||
) | ||
const fileStat = await fs.stat(tempNormalFilePath) | ||
const totalFileSize = fileStat.size | ||
|
||
// original file and gzip file should not be equal in size | ||
expect(gzipFileSize).not.toEqual(totalFileSize) | ||
}) |
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