Skip to content

Commit

Permalink
setup-ruby logging
Browse files Browse the repository at this point in the history
  • Loading branch information
MSP-Greg committed Apr 5, 2020
1 parent 60daef6 commit 33a3f87
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
18 changes: 12 additions & 6 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ const httpc = require('@actions/http-client')

const { performance } = require('perf_hooks')

const yel = '\x1b[33m'
const blu = '\x1b[94m' // eslint-disable-line no-unused-vars
const colors = {
'yel': '\x1b[33m',
'blu': '\x1b[94m'
}
const rst = '\x1b[0m'

export const download = async (uri, dest) => {
export const download = async (uri, dest, log = true) => {
// make sure the folder exists
if (!fs.existsSync(path.dirname(dest))) {
fs.mkdirSync(path.dirname(dest), { recursive: true })
}

console.log(`[command]Downloading:\n ${uri}`)
if (log) { console.log(`[command]Downloading:\n ${uri}`) }

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

export const grpSt = (desc) => {
console.log(`##[group]${yel}${desc}${rst}`)
console.log(`##[group]${colors['yel']}${desc}${rst}`)
return performance.now()
}

export const grpEnd = (msSt) => {
const timeStr = ((performance.now() - msSt)/1000).toFixed(2).padStart(6)
console.log(`::[endgroup]\n time: ${timeStr} s`)
console.log(`::[endgroup]\n took ${timeStr} s`)
}

export const log = (logText, color = 'yel') => {
console.log(`${colors[color]}${logText}${rst}`)
}

export const getInput = (name) => core.getInput(name).replace(/[^a-z_ \d.-]+/gi, '').trim().toLowerCase()
27 changes: 20 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "execSyncQ", function() { return execSyncQ; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "grpSt", function() { return grpSt; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "grpEnd", function() { return grpEnd; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "log", function() { return log; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getInput", function() { return getInput; });


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

const { performance } = __webpack_require__(630)

const yel = '\x1b[33m'
const blu = '\x1b[94m' // eslint-disable-line no-unused-vars
const colors = {
'yel': '\x1b[33m',
'blu': '\x1b[94m'
}
const rst = '\x1b[0m'

const download = async (uri, dest) => {
const download = async (uri, dest, log = true) => {
// make sure the folder exists
if (!fs.existsSync(path.dirname(dest))) {
fs.mkdirSync(path.dirname(dest), { recursive: true })
}

console.log(`[command]Downloading:\n ${uri}`)
if (log) { console.log(`[command]Downloading:\n ${uri}`) }

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

const grpSt = (desc) => {
console.log(`##[group]${yel}${desc}${rst}`)
console.log(`##[group]${colors['yel']}${desc}${rst}`)
return performance.now()
}

const grpEnd = (msSt) => {
const timeStr = ((performance.now() - msSt)/1000).toFixed(2).padStart(6)
console.log(`::[endgroup]\n time: ${timeStr} s`)
console.log(`::[endgroup]\n took ${timeStr} s`)
}

const log = (logText, color = 'yel') => {
console.log(`${colors[color]}${logText}${rst}`)
}

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

const { performance } = __webpack_require__(630)

const common = __webpack_require__(498)

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

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

let runner
Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
(async () => {
const core = require('@actions/core')

const { performance } = require('perf_hooks')

const common = require('./common')

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

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

let runner
Expand Down

0 comments on commit 33a3f87

Please sign in to comment.