-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
76 lines (61 loc) · 2.27 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const fs = require('fs');
const core = require('@actions/core');
async function run() {
try {
const accessToken = core.getInput('accessToken');
core.setSecret(accessToken);
const server = core.getInput('server');
const organization = core.getInput('organization');
const feed = core.getInput('feed');
core.setSecret(feed);
let username = core.getInput('username');
const email = core.getInput('email');
let filePath = core.getInput('npmrcPath');
if (username === undefined || username === '') {
username = organization;
}
if (filePath === undefined || filePath === '') {
filePath = `${process.env.HOME}/.npmrc`;
}
if (core.isDebug()) {
core.debug(`AccessToken: ${accessToken}`);
}
core.info(`Organization: ${organization}`);
if (core.isDebug()) {
core.debug(`Organization: ${feed}`);
}
core.info(`Username: ${username}`);
core.info(`Email: ${email}`);
core.info(`Write to: ${filePath}`);
const authTokenConfiguration = `
; begin auth token
//${server}/${organization}/_packaging/${feed}/npm/registry/:username=${username}
//${server}/${organization}/_packaging/${feed}/npm/registry/:_password=${accessToken}
//${server}/${organization}/_packaging/${feed}/npm/registry/:email=${email}
//${server}/${organization}/_packaging/${feed}/npm/:username=${username}
//${server}/${organization}/_packaging/${feed}/npm/:_password=${accessToken}
//${server}/${organization}/_packaging/${feed}/npm/:email=${email}
; end auth token
`;
fs.open(filePath, 'a', (error, fd) => {
if (error) {
core.setFailed(error.message);
return;
}
fs.appendFile(fd, authTokenConfiguration, error => {
if (error) {
core.setFailed(error.message);
return;
}
core.info('.npmrc configured');
if (core.isDebug()) {
core.debug(`.nmprc content: ${authTokenConfiguration}`);
}
});
});
} catch (error) {
core.setFailed(error.message);
}
}
run();
export default run;