Skip to content

Commit e9b0369

Browse files
committed
Add groups to clarify output and measure the time each group takes
1 parent 045dd42 commit e9b0369

File tree

5 files changed

+96
-24
lines changed

5 files changed

+96
-24
lines changed

common.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
const os = require('os')
22
const fs = require('fs')
3+
const core = require('@actions/core')
4+
const { performance } = require('perf_hooks')
5+
6+
export async function measure(name, block) {
7+
return await core.group(name, async () => {
8+
const start = performance.now()
9+
try {
10+
return await block()
11+
} finally {
12+
const end = performance.now()
13+
const duration = (end - start) / 1000.0
14+
console.log(`Took ${duration.toFixed(2).padStart(6)} seconds`)
15+
}
16+
})
17+
}
318

419
export function getVirtualEnvironmentName() {
520
const platform = os.platform()

dist/index.js

Lines changed: 52 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export async function run() {
2626

2727
setupPath(ruby, newPathEntries)
2828

29-
await installBundler(platform, rubyPrefix, engine, version)
29+
await common.measure('Installing Bundler', async () =>
30+
installBundler(platform, rubyPrefix, engine, version))
3031

3132
core.setOutput('ruby-prefix', rubyPrefix)
3233
} catch (error) {
@@ -101,12 +102,14 @@ function setupPath(ruby, newPathEntries) {
101102
let cleanPath = originalPath.filter(entry => !/\bruby\b/i.test(entry))
102103

103104
if (cleanPath.length !== originalPath.length) {
105+
core.startGroup('Cleaning PATH')
104106
console.log('Entries removed from PATH to avoid conflicts with Ruby:')
105107
for (const entry of originalPath) {
106108
if (!cleanPath.includes(entry)) {
107109
console.log(` ${entry}`)
108110
}
109111
}
112+
core.endGroup()
110113
}
111114

112115
core.exportVariable('PATH', [...newPathEntries, ...cleanPath].join(path.delimiter))

ruby-builder.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const path = require('path')
33
const exec = require('@actions/exec')
44
const io = require('@actions/io')
55
const tc = require('@actions/tool-cache')
6+
const common = require('./common')
67
const rubyBuilderVersions = require('./ruby-builder-versions')
78

89
const builderReleaseTag = 'enable-shared'
@@ -27,12 +28,15 @@ async function downloadAndExtract(platform, ruby) {
2728
const rubiesDir = path.join(os.homedir(), '.rubies')
2829
await io.mkdirP(rubiesDir)
2930

30-
const url = await getDownloadURL(platform, ruby)
31-
console.log(url)
31+
const downloadPath = await common.measure('Downloading Ruby', async () => {
32+
const url = getDownloadURL(platform, ruby)
33+
console.log(url)
34+
return await tc.downloadTool(url)
35+
})
3236

33-
const downloadPath = await tc.downloadTool(url)
3437
const tar = platform.startsWith('windows') ? 'C:\\Windows\\system32\\tar.exe' : 'tar'
35-
await exec.exec(tar, [ '-xz', '-C', rubiesDir, '-f', downloadPath ])
38+
await common.measure('Extracting Ruby', async () =>
39+
exec.exec(tar, [ '-xz', '-C', rubiesDir, '-f', downloadPath ]))
3640

3741
return path.join(rubiesDir, ruby)
3842
}

windows.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const cp = require('child_process')
77
const core = require('@actions/core')
88
const exec = require('@actions/exec')
99
const tc = require('@actions/tool-cache')
10+
const common = require('./common')
1011
const rubyInstallerVersions = require('./windows-versions').versions
1112

1213
// Extract to SSD, see https://github.com/ruby/setup-ruby/pull/14
@@ -35,15 +36,19 @@ export function getAvailableVersions(platform, engine) {
3536
export async function install(platform, ruby) {
3637
const version = ruby.split('-', 2)[1]
3738
const url = rubyInstallerVersions[version]
38-
console.log(url)
3939

4040
if (!url.endsWith('.7z')) {
41-
throw new Error('URL should end in .7z')
41+
throw new Error(`URL should end in .7z: ${url}`)
4242
}
4343
const base = url.slice(url.lastIndexOf('/') + 1, url.length - '.7z'.length)
4444

45-
const downloadPath = await tc.downloadTool(url)
46-
await exec.exec('7z', ['x', downloadPath, `-xr!${base}\\share\\doc`, `-o${drive}:\\`], { silent: true })
45+
const downloadPath = await common.measure('Downloading Ruby', async () => {
46+
console.log(url)
47+
return await tc.downloadTool(url)
48+
})
49+
50+
await common.measure('Extracting Ruby', async () =>
51+
exec.exec('7z', ['x', downloadPath, `-xr!${base}\\share\\doc`, `-o${drive}:\\`], { silent: true }))
4752
const rubyPrefix = `${drive}:\\${base}`
4853

4954
let toolchainPaths = (version === 'mswin') ?
@@ -62,15 +67,17 @@ async function symLinkToEmbeddedMSYS2() {
6267
}
6368
const latestVersion = toolCacheVersions.slice(-1)[0]
6469
const hostedRuby = tc.find('Ruby', latestVersion)
65-
await exec.exec(`cmd /c mklink /D ${msys2} ${hostedRuby}\\msys64`)
70+
await common.measure('Linking MSYS2', async () =>
71+
exec.exec(`cmd /c mklink /D ${msys2} ${hostedRuby}\\msys64`))
6672
}
6773

6874
async function setupMingw(version) {
6975
core.exportVariable('MAKE', 'make.exe')
7076

7177
if (version.startsWith('2.2') || version.startsWith('2.3')) {
7278
core.exportVariable('SSL_CERT_FILE', certFile)
73-
await installMSYS(version)
79+
await common.measure('Installing MSYS1', async () =>
80+
installMSYS(version))
7481

7582
return msysPathEntries
7683
} else {
@@ -117,7 +124,10 @@ async function setupMSWin() {
117124
await symLinkToEmbeddedMSYS2()
118125
}
119126

120-
return [...addVCVARSEnv(), ...msys2PathEntries]
127+
const VCPathEntries = await common.measure('Setting up MSVC environment', async () =>
128+
addVCVARSEnv())
129+
130+
return [...VCPathEntries, ...msys2PathEntries]
121131
}
122132

123133
/* Sets MSVC environment for use in Actions

0 commit comments

Comments
 (0)