Read out HOME instead of the os query info

As when using the gitea-actions-runner on NixOS
it is using systemd dynamic user
This commit is contained in:
Kaare Hoff Skovgaard 2025-06-30 21:05:36 +02:00
parent a6f90b1f12
commit 8df636d8b2
Signed by: khs
GPG key ID: C7D890804F01E9F0
2 changed files with 27 additions and 25 deletions

View file

@ -2,6 +2,7 @@ const core = require('@actions/core');
const child_process = require('child_process'); const child_process = require('child_process');
const fs = require('fs'); const fs = require('fs');
const crypto = require('crypto'); const crypto = require('crypto');
const path = require('path');
const { homePath, sshAgentCmd, sshAddCmd, gitCmd } = require('./paths.js'); const { homePath, sshAgentCmd, sshAddCmd, gitCmd } = require('./paths.js');
try { try {
@ -14,7 +15,7 @@ try {
return; return;
} }
const homeSsh = homePath + '/.ssh'; const homeSsh = path.join(homePath, '.ssh');
fs.mkdirSync(homeSsh, { recursive: true }); fs.mkdirSync(homeSsh, { recursive: true });
console.log("Starting ssh-agent"); console.log("Starting ssh-agent");

View file

@ -1,29 +1,30 @@
const os = require('os'); const os = require("os");
const core = require('@actions/core'); const core = require("@actions/core");
const defaults = (process.env['OS'] != 'Windows_NT') ? { const defaults =
// We use os.userInfo() rather than os.homedir(), since it uses the getpwuid() system call to get the user's home directory (see https://nodejs.org/api/os.html#osuserinfooptions). process.env["OS"] != "Windows_NT"
// This mimics the way openssh derives the home directory for locating config files (see https://github.com/openssh/openssh-portable/blob/826483d51a9fee60703298bbf839d9ce37943474/ssh.c#L710); ? {
// Makes a difference in Docker-based Action runs, when $HOME is different from what getpwuid() returns (which is based on the entry in /etc/passwd) homePath: os.homedir(),
homePath: os.userInfo().homedir, sshAgentCmdDefault: "ssh-agent",
sshAgentCmdDefault: 'ssh-agent', sshAddCmdDefault: "ssh-add",
sshAddCmdDefault: 'ssh-add', gitCmdDefault: "git",
gitCmdDefault: 'git' }
} : { : {
// Assuming GitHub hosted `windows-*` runners for now // Assuming GitHub hosted `windows-*` runners for now
homePath: os.homedir(), homePath: os.homedir(),
sshAgentCmdDefault: 'c://progra~1//git//usr//bin//ssh-agent.exe', sshAgentCmdDefault: "c://progra~1//git//usr//bin//ssh-agent.exe",
sshAddCmdDefault: 'c://progra~1//git//usr//bin//ssh-add.exe', sshAddCmdDefault: "c://progra~1//git//usr//bin//ssh-add.exe",
gitCmdDefault: 'c://progra~1//git//bin//git.exe' gitCmdDefault: "c://progra~1//git//bin//git.exe",
}; };
const sshAgentCmdInput = core.getInput('ssh-agent-cmd'); const sshAgentCmdInput = core.getInput("ssh-agent-cmd");
const sshAddCmdInput = core.getInput('ssh-add-cmd'); const sshAddCmdInput = core.getInput("ssh-add-cmd");
const gitCmdInput = core.getInput('git-cmd'); const gitCmdInput = core.getInput("git-cmd");
module.exports = { module.exports = {
homePath: defaults.homePath, homePath: defaults.homePath,
sshAgentCmd: sshAgentCmdInput !== '' ? sshAgentCmdInput : defaults.sshAgentCmdDefault, sshAgentCmd:
sshAddCmd: sshAddCmdInput !== '' ? sshAddCmdInput : defaults.sshAddCmdDefault, sshAgentCmdInput !== "" ? sshAgentCmdInput : defaults.sshAgentCmdDefault,
gitCmd: gitCmdInput !== '' ? gitCmdInput : defaults.gitCmdDefault, sshAddCmd: sshAddCmdInput !== "" ? sshAddCmdInput : defaults.sshAddCmdDefault,
gitCmd: gitCmdInput !== "" ? gitCmdInput : defaults.gitCmdDefault,
}; };