-
Notifications
You must be signed in to change notification settings - Fork 6
/
brew.js
44 lines (36 loc) · 1.09 KB
/
brew.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
const core = require('@actions/core')
const { execSync, grpSt, grpEnd } = require('./common')
// group start time
let msSt
export const run = async () => {
try {
// clean input
// use different regex than getInput in common.js. Some packages contain @ character
let brew = core.getInput('brew').replace(/[^a-z_ \d.+@-]+/gi, '').trim().toLowerCase()
if (brew !== '') {
let needUpdate = true
if (/\b_update_\b/.test(brew)) {
msSt = grpSt('brew update')
execSync('brew update')
grpEnd(msSt)
needUpdate = false
brew = brew.replace(/\b_update_\b/gi, '').trim()
}
if (/\b_upgrade_\b/.test(brew)) {
msSt = grpSt('brew upgrade')
if (needUpdate) { execSync('brew update') }
execSync('brew upgrade')
grpEnd(msSt)
brew = brew.replace(/\b_upgrade_\b/gi, '').trim()
}
if (brew !== '') {
msSt = grpSt(`brew install ${brew}`)
execSync(`brew install ${brew}`)
grpEnd(msSt)
}
}
} catch (error) {
core.setFailed(error.message)
}
}