forked from michcio1234/heroku-run
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (31 loc) · 927 Bytes
/
index.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
const core = require('@actions/core')
const { execSync } = require('child_process')
// Support Functions
const createCatFile = ({ email, api_key }) => `cat >~/.netrc <<EOF
machine api.heroku.com
login ${email}
password ${api_key}
machine git.heroku.com
login ${email}
password ${api_key}
EOF`
// Input Variables
let heroku = {}
heroku.api_key = core.getInput('heroku_api_key')
heroku.email = core.getInput('heroku_email')
heroku.app_name = core.getInput('heroku_app_name')
let command = core.getInput('command')
// Program logic
try {
execSync(createCatFile(heroku))
console.log('Created and wrote to ~./netrc')
execSync('heroku login')
console.log('Successfully logged into heroku')
execSync(`heroku run -a ${heroku.app_name} -- ${command}`)
core.setOutput(
'status',
`Successfully ran command ${command} in ${heroku.app_name}`,
)
} catch (err) {
core.setFailed(err.toString())
}