Skip to content

Commit c95dfdc

Browse files
committed
Use os.userInfo() to obtain the getpwent()-based home directory
1 parent 60ca2a5 commit c95dfdc

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

dist/index.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ const fs = __webpack_require__(747);
121121
const os = __webpack_require__(87);
122122

123123
try {
124-
125-
const home = os.homedir();
126-
const homeSsh = home + '/.ssh';
127124
const privateKey = core.getInput('ssh-private-key');
128125

129126
if (!privateKey) {
@@ -132,11 +129,21 @@ try {
132129
return;
133130
}
134131

132+
var home;
133+
135134
if (process.env['OS'] == 'Windows_NT') {
136135
console.log('Preparing ssh-agent service on Windows');
137136
child_process.execSync('sc config ssh-agent start=demand', { stdio: 'inherit' });
137+
138+
home = os.homedir();
139+
} else {
140+
// Use getent() system call, since this is what ssh does; makes a difference in Docker-based
141+
// Action runs, where $HOME is different from the pwent
142+
var { homedir: home } = os.userInfo();
138143
}
139144

145+
const homeSsh = home + '/.ssh';
146+
140147
console.log(`Adding GitHub.com keys to ${homeSsh}/known_hosts`);
141148
fs.mkdirSync(homeSsh, { recursive: true });
142149
fs.appendFileSync(`${homeSsh}/known_hosts`, '\ngithub.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==\n');

index.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ const fs = require('fs');
44
const os = require('os');
55

66
try {
7-
8-
const home = os.homedir();
9-
const homeSsh = home + '/.ssh';
107
const privateKey = core.getInput('ssh-private-key');
118

129
if (!privateKey) {
@@ -15,11 +12,21 @@ try {
1512
return;
1613
}
1714

15+
var home;
16+
1817
if (process.env['OS'] == 'Windows_NT') {
1918
console.log('Preparing ssh-agent service on Windows');
2019
child_process.execSync('sc config ssh-agent start=demand', { stdio: 'inherit' });
20+
21+
home = os.homedir();
22+
} else {
23+
// Use getent() system call, since this is what ssh does; makes a difference in Docker-based
24+
// Action runs, where $HOME is different from the pwent
25+
var { homedir: home } = os.userInfo();
2126
}
2227

28+
const homeSsh = home + '/.ssh';
29+
2330
console.log(`Adding GitHub.com keys to ${homeSsh}/known_hosts`);
2431
fs.mkdirSync(homeSsh, { recursive: true });
2532
fs.appendFileSync(`${homeSsh}/known_hosts`, '\ngithub.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==\n');

0 commit comments

Comments
 (0)