Skip to content

Commit

Permalink
🐛 Zip results without relying on GitHub API (QD-8962)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiulpin committed Jul 2, 2024
1 parent e995eec commit 30054d0
Show file tree
Hide file tree
Showing 6 changed files with 20,426 additions and 750 deletions.
51 changes: 51 additions & 0 deletions common/qodana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import {checksum, version} from './cli.json'
import {createHash} from 'crypto'
import fs from 'fs'
import path from 'path'
import fsp from 'fs/promises'
import JSZip from 'jszip'

export const SUPPORTED_PLATFORMS = ['windows', 'linux']
export const SUPPORTED_ARCHS = ['x86_64', 'arm64']
Expand Down Expand Up @@ -293,3 +296,51 @@ export function validateBranchName(branchName: string): string {
}
return branchName
}

async function getFilePathsRecursively(dir: string): Promise<string[]> {
const list = await fsp.readdir(dir)
const statPromises = list.map(async file => {
const fullPath = path.resolve(dir, file)
const stat = await fsp.stat(fullPath)
if (stat && stat.isDirectory()) {
return getFilePathsRecursively(fullPath)
}
return fullPath
})
return (await Promise.all(statPromises)).flat(
Number.POSITIVE_INFINITY
) as string[]
}

async function createZipFromFolder(dir: string): Promise<JSZip> {
const absRoot = path.resolve(dir)
const filePaths = await getFilePathsRecursively(dir)
const zip = new JSZip()
for (const filePath of filePaths) {
const relative = filePath.replace(absRoot, '')
zip.file(relative, fs.createReadStream(filePath), {
unixPermissions: '777'
})
}
return zip
}

/**
* Compresses the given folder into a ZIP archive.
* @param srcDir the source directory to compress.
* @param destFile the destination ZIP file.
*/
export async function compressFolder(
srcDir: string,
destFile: string
): Promise<void> {
await fsp.mkdir(path.dirname(destFile), {recursive: true})
const zip = await createZipFromFolder(srcDir)
await new Promise((resolve, reject) => {
zip
.generateNodeStream({streamFiles: true, compression: 'DEFLATE'})
.pipe(fs.createWriteStream(destFile))
.on('error', err => reject(err))
.on('finish', resolve)
})
}
81 changes: 75 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 30054d0

Please sign in to comment.