Skip to content

Commit

Permalink
Merge pull request #567 from dennisameling/use-d-drive-if-available
Browse files Browse the repository at this point in the history
Use fast D: drive if available
  • Loading branch information
dscho authored Jan 2, 2023
2 parents e8f2204 + 6f5c3c0 commit 2338b17
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
20 changes: 18 additions & 2 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

25 changes: 23 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ import * as fs from 'fs'
const flavor = core.getInput('flavor')
const architecture = core.getInput('architecture')

/**
* Some Azure VM types have a temporary disk which is local to the VM and therefore provides
* _much_ faster disk IO than the OS Disk (or any other attached disk).
*
* Hosted GitHub Actions runners also leverage this disk and do their work in D:/a/_work, so let's
* use it too if we can. It leads to a ~25% speed increase when doing heavy IO operations.
*
* https://learn.microsoft.com/en-us/azure/virtual-machines/managed-disks-overview#temporary-disk
*/
function getDriveLetterPrefix(): string {
if (fs.existsSync('D:/')) {
core.info('Found a fast, temporary disk on this VM (D:/). Will use that.')
return 'D:/'
}

return 'C:/'
}

async function run(): Promise<void> {
try {
if (process.platform !== 'win32') {
Expand All @@ -37,7 +55,8 @@ async function run(): Promise<void> {
architecture,
githubToken
)
const outputDirectory = core.getInput('path') || `C:/${artifactName}`
const outputDirectory =
core.getInput('path') || `${getDriveLetterPrefix()}${artifactName}`
let useCache: boolean
switch (core.getInput('cache')) {
case 'true':
Expand Down Expand Up @@ -153,7 +172,9 @@ function cleanup(): void {

const outputDirectory =
core.getInput('path') ||
`C:/${getArtifactMetadata(flavor, architecture).artifactName}`
`${getDriveLetterPrefix()}${
getArtifactMetadata(flavor, architecture).artifactName
}`

/**
* Shelling out to `rm -rf` is more than twice as fast as Node's `fs.rmSync` method.
Expand Down

0 comments on commit 2338b17

Please sign in to comment.