add sshPublicKeysDirectoryPath and GIT_CONFIG_EXTENSIONS parameters that adds git configs and mounts .ssh/config and public keys to the container, in order to allow multiple sh deploy key trick by webplatform@ssh-agent (#240)

This commit is contained in:
Ely Ronnen
2023-09-07 00:35:36 +03:00
committed by GitHub
parent 9d0bc623a7
commit 275df9854c
8 changed files with 1258 additions and 1174 deletions

View File

@@ -16,6 +16,7 @@ export async function run() {
artifactsPath,
useHostNetwork,
sshAgent,
sshPublicKeysDirectoryPath,
gitPrivateToken,
githubToken,
checkName,
@@ -39,6 +40,7 @@ export async function run() {
artifactsPath,
useHostNetwork,
sshAgent,
sshPublicKeysDirectoryPath,
packageMode,
packageName,
gitPrivateToken,

View File

@@ -62,6 +62,7 @@ const Docker = {
artifactsPath,
useHostNetwork,
sshAgent,
sshPublicKeysDirectoryPath,
packageMode,
packageName,
gitPrivateToken,
@@ -116,6 +117,7 @@ const Docker = {
--env RUNNER_WORKSPACE \
--env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \
--env CHOWN_FILES_TO="${chownFilesTo}" \
--env GIT_CONFIG_EXTENSIONS \
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
--volume "${githubHome}:/root:z" \
--volume "${githubWorkflow}:/github/workflow:z" \
@@ -126,7 +128,14 @@ const Docker = {
--volume "${actionFolder}/unity-config:/usr/share/unity3d/config/:z" \
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
${
sshAgent ? `--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro` : ''
sshAgent && !sshPublicKeysDirectoryPath
? `--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro`
: ''
} \
${
sshPublicKeysDirectoryPath
? `--volume ${sshPublicKeysDirectoryPath}:/root/.ssh:ro`
: ''
} \
${useHostNetwork ? '--net=host' : ''} \
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \

View File

@@ -13,6 +13,12 @@ const Input = {
return validFolderName.test(folderName);
},
isValidGlobalFolderName(folderName) {
const validFolderName = new RegExp(/^(\.|\.\/|\/)?(\.?[\w~]+([ _-]?[\w~]+)*\/?)*$/);
return validFolderName.test(folderName);
},
/**
* When in package mode, we need to scrape the package's name from its package.json file
*/
@@ -72,6 +78,7 @@ const Input = {
const rawArtifactsPath = getInput('artifactsPath') || 'artifacts';
const rawUseHostNetwork = getInput('useHostNetwork') || 'false';
const sshAgent = getInput('sshAgent') || '';
const rawSshPublicKeysDirectoryPath = getInput('sshPublicKeysDirectoryPath') || '';
const gitPrivateToken = getInput('gitPrivateToken') || '';
const githubToken = getInput('githubToken') || '';
const checkName = getInput('checkName') || 'Test Results';
@@ -92,6 +99,10 @@ const Input = {
throw new Error(`Invalid artifactsPath "${rawArtifactsPath}"`);
}
if (!this.isValidGlobalFolderName(rawSshPublicKeysDirectoryPath)) {
throw new Error(`Invalid sshPublicKeysDirectoryPath "${rawSshPublicKeysDirectoryPath}"`);
}
if (rawUseHostNetwork !== 'true' && rawUseHostNetwork !== 'false') {
throw new Error(`Invalid useHostNetwork "${rawUseHostNetwork}"`);
}
@@ -100,6 +111,12 @@ const Input = {
throw new Error(`Invalid packageMode "${rawPackageMode}"`);
}
if (rawSshPublicKeysDirectoryPath !== '' && sshAgent === '') {
throw new Error(
'sshPublicKeysDirectoryPath is set, but sshAgent is not set. sshPublicKeysDirectoryPath is useful only when using sshAgent.',
);
}
// sanitize packageMode input and projectPath input since they are needed
// for input validation
const packageMode = rawPackageMode === 'true';
@@ -119,6 +136,7 @@ const Input = {
// Sanitise other input
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
const sshPublicKeysDirectoryPath = rawSshPublicKeysDirectoryPath.replace(/\/$/, '');
const useHostNetwork = rawUseHostNetwork === 'true';
const editorVersion =
unityVersion === 'auto' ? UnityVersionParser.read(projectPath) : unityVersion;
@@ -134,6 +152,7 @@ const Input = {
artifactsPath,
useHostNetwork,
sshAgent,
sshPublicKeysDirectoryPath,
gitPrivateToken,
githubToken,
checkName,