Skip to content

Commit 33a3f87

Browse files
committed
setup-ruby logging
1 parent 60daef6 commit 33a3f87

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

common.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ const httpc = require('@actions/http-client')
88

99
const { performance } = require('perf_hooks')
1010

11-
const yel = '\x1b[33m'
12-
const blu = '\x1b[94m' // eslint-disable-line no-unused-vars
11+
const colors = {
12+
'yel': '\x1b[33m',
13+
'blu': '\x1b[94m'
14+
}
1315
const rst = '\x1b[0m'
1416

15-
export const download = async (uri, dest) => {
17+
export const download = async (uri, dest, log = true) => {
1618
// make sure the folder exists
1719
if (!fs.existsSync(path.dirname(dest))) {
1820
fs.mkdirSync(path.dirname(dest), { recursive: true })
1921
}
2022

21-
console.log(`[command]Downloading:\n ${uri}`)
23+
if (log) { console.log(`[command]Downloading:\n ${uri}`) }
2224

2325
const http = new httpc.HttpClient('MSP-Greg', [], {
2426
allowRetries: true,
@@ -78,13 +80,17 @@ export const execSyncQ = (cmd) => {
7880
}
7981

8082
export const grpSt = (desc) => {
81-
console.log(`##[group]${yel}${desc}${rst}`)
83+
console.log(`##[group]${colors['yel']}${desc}${rst}`)
8284
return performance.now()
8385
}
8486

8587
export const grpEnd = (msSt) => {
8688
const timeStr = ((performance.now() - msSt)/1000).toFixed(2).padStart(6)
87-
console.log(`::[endgroup]\n time: ${timeStr} s`)
89+
console.log(`::[endgroup]\n took ${timeStr} s`)
90+
}
91+
92+
export const log = (logText, color = 'yel') => {
93+
console.log(`${colors[color]}${logText}${rst}`)
8894
}
8995

9096
export const getInput = (name) => core.getInput(name).replace(/[^a-z_ \d.-]+/gi, '').trim().toLowerCase()

dist/index.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ __webpack_require__.r(__webpack_exports__);
397397
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "execSyncQ", function() { return execSyncQ; });
398398
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "grpSt", function() { return grpSt; });
399399
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "grpEnd", function() { return grpEnd; });
400+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "log", function() { return log; });
400401
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getInput", function() { return getInput; });
401402

402403

@@ -408,17 +409,19 @@ const httpc = __webpack_require__(553)
408409

409410
const { performance } = __webpack_require__(630)
410411

411-
const yel = '\x1b[33m'
412-
const blu = '\x1b[94m' // eslint-disable-line no-unused-vars
412+
const colors = {
413+
'yel': '\x1b[33m',
414+
'blu': '\x1b[94m'
415+
}
413416
const rst = '\x1b[0m'
414417

415-
const download = async (uri, dest) => {
418+
const download = async (uri, dest, log = true) => {
416419
// make sure the folder exists
417420
if (!fs.existsSync(path.dirname(dest))) {
418421
fs.mkdirSync(path.dirname(dest), { recursive: true })
419422
}
420423

421-
console.log(`[command]Downloading:\n ${uri}`)
424+
if (log) { console.log(`[command]Downloading:\n ${uri}`) }
422425

423426
const http = new httpc.HttpClient('MSP-Greg', [], {
424427
allowRetries: true,
@@ -478,13 +481,17 @@ const execSyncQ = (cmd) => {
478481
}
479482

480483
const grpSt = (desc) => {
481-
console.log(`##[group]${yel}${desc}${rst}`)
484+
console.log(`##[group]${colors['yel']}${desc}${rst}`)
482485
return performance.now()
483486
}
484487

485488
const grpEnd = (msSt) => {
486489
const timeStr = ((performance.now() - msSt)/1000).toFixed(2).padStart(6)
487-
console.log(`::[endgroup]\n time: ${timeStr} s`)
490+
console.log(`::[endgroup]\n took ${timeStr} s`)
491+
}
492+
493+
const log = (logText, color = 'yel') => {
494+
console.log(`${colors[color]}${logText}${rst}`)
488495
}
489496

490497
const getInput = (name) => core.getInput(name).replace(/[^a-z_ \d.-]+/gi, '').trim().toLowerCase()
@@ -1644,6 +1651,8 @@ module.exports = require("fs");
16441651
(async () => {
16451652
const core = __webpack_require__(276)
16461653

1654+
const { performance } = __webpack_require__(630)
1655+
16471656
const common = __webpack_require__(498)
16481657

16491658
const platform = __webpack_require__(87).platform()
@@ -1657,8 +1666,12 @@ module.exports = require("fs");
16571666

16581667
if (core.getInput('ruby-version') !== '') {
16591668
const fn = `${process.env.RUNNER_TEMP}\\setup_ruby.js`
1660-
await common.download('https://raw.githubusercontent.com/ruby/setup-ruby/v1/dist/index.js', fn)
1669+
common.log(' Running ruby/setup-ruby')
1670+
const msSt = performance.now()
1671+
await common.download('https://raw.githubusercontent.com/ruby/setup-ruby/v1/dist/index.js', fn, false)
16611672
await require(fn).run()
1673+
const timeStr = ((performance.now() - msSt)/1000).toFixed(2).padStart(6)
1674+
console.log(` took ${timeStr} s`)
16621675
}
16631676

16641677
let runner

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
(async () => {
44
const core = require('@actions/core')
55

6+
const { performance } = require('perf_hooks')
7+
68
const common = require('./common')
79

810
const platform = require('os').platform()
@@ -16,8 +18,12 @@
1618

1719
if (core.getInput('ruby-version') !== '') {
1820
const fn = `${process.env.RUNNER_TEMP}\\setup_ruby.js`
19-
await common.download('https://raw.githubusercontent.com/ruby/setup-ruby/v1/dist/index.js', fn)
21+
common.log(' Running ruby/setup-ruby')
22+
const msSt = performance.now()
23+
await common.download('https://raw.githubusercontent.com/ruby/setup-ruby/v1/dist/index.js', fn, false)
2024
await require(fn).run()
25+
const timeStr = ((performance.now() - msSt)/1000).toFixed(2).padStart(6)
26+
console.log(` took ${timeStr} s`)
2127
}
2228

2329
let runner

0 commit comments

Comments
 (0)