-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathsetup.ts
37 lines (35 loc) · 986 Bytes
/
setup.ts
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
import fs from 'fs'
import path from 'path'
import jsYaml from 'js-yaml'
/**
* Helper that reads the `action.yml` and includes the default values
* for each input as an environment variable, like the Actions runtime does.
*/
function getDefaultValues() {
const yaml = fs.readFileSync(path.join(__dirname, '../action.yml'), 'utf8')
const { inputs } = jsYaml.safeLoad(yaml) as any
return Object.keys(inputs).reduce(
(sum, key) => ({
...sum,
[key]: inputs[key].default
}),
{}
)
}
Object.assign(
process.env,
{
GITHUB_ACTION: 'my-action',
GITHUB_ACTOR: 'JasonEtco',
GITHUB_EVENT_NAME: 'release',
GITHUB_EVENT_PATH: path.join(__dirname, 'fixtures', 'release.json'),
GITHUB_REF: 'master',
GITHUB_REPOSITORY: 'JasonEtco/test',
GITHUB_SHA: '123abc',
GITHUB_TOKEN: '456def',
GITHUB_WORKFLOW: 'my-workflow',
GITHUB_WORKSPACE: path.join(__dirname, 'fixtures', 'workspace'),
HOME: '?'
},
getDefaultValues()
)