-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
56 lines (49 loc) · 1.26 KB
/
index.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { exit } from 'node:process';
import {
debug,
error,
exportVariable,
getBooleanInput,
getInput,
info,
setOutput,
} from '@actions/core';
import { Octokit, RestEndpointMethodTypes } from '@octokit/rest';
import fetch from 'node-fetch';
const getInputRequired = (name: string) =>
getInput(name, {
required: true,
});
(async () => {
const environment = getInputRequired('environment');
const repositoryId = getInputRequired('repository_id');
const token = getInputRequired('token');
const doExport = getBooleanInput('export');
const octokit = new Octokit({
auth: token,
request: {
fetch,
},
});
let page = 1;
let env: RestEndpointMethodTypes['actions']['listEnvironmentVariables']['response'];
do {
env = await octokit.actions.listEnvironmentVariables({
repository_id: parseInt(repositoryId),
environment_name: environment,
page: page++,
per_page: 100,
});
for (const v of env.data.variables) {
setOutput(v.name, v.value);
doExport && exportVariable(v.name, v.value);
info(`Successfully set ${v.name}=${v.value}`);
}
} while (env.data.total_count > env.data.variables.length);
debug('Done');
})()
.then()
.catch((e) => {
error(e);
exit(1);
});