Skip to content

Commit 2190fd5

Browse files
authored
Support multiple GitHub SSH deploy keys (#568)
* 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 * remove sshPublicKeysDirectoryPath and GIT_CONFIG_EXTENSIONS from windows runner for now
1 parent a073719 commit 2190fd5

File tree

8 files changed

+67
-5
lines changed

8 files changed

+67
-5
lines changed

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ inputs:
8585
required: false
8686
default: ''
8787
description: 'SSH Agent path to forward to the container'
88+
sshPublicKeysDirectoryPath:
89+
required: false
90+
default: ''
91+
description: 'Path to a directory containing SSH public keys to forward to the container.'
8892
gitPrivateToken:
8993
required: false
9094
default: ''

dist/index.js

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/platforms/ubuntu/entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mkdir -p "$ACTIVATE_LICENSE_PATH"
1010
#
1111
# Run steps
1212
#
13+
source /steps/set_extra_git_configs.sh
1314
source /steps/set_gitcredential.sh
1415
source /steps/activate.sh
1516
source /steps/build.sh
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
if [ -z "${GIT_CONFIG_EXTENSIONS}" ]
4+
then
5+
echo "GIT_CONFIG_EXTENSIONS unset skipping"
6+
else
7+
echo "GIT_CONFIG_EXTENSIONS is set configuring extra git configs"
8+
9+
IFS=$'\n'
10+
for config in $(echo "${GIT_CONFIG_EXTENSIONS}" | sed 's/\(.*\)=\(.*\)/"\1" "\2"/g'); do
11+
if [[ $config =~ \"([^\"]+)\"\ \"([^\"]+)\" ]]; then
12+
key="${BASH_REMATCH[1]}"
13+
value="${BASH_REMATCH[2]}"
14+
else
15+
echo "Error parsing config: $config"
16+
exit 1
17+
fi
18+
echo "Adding extra git config: \"$key\" = \"$value\""
19+
git config --global --add "$key" "$value"
20+
done
21+
unset IFS
22+
23+
fi
24+
25+
echo "---------- git config --list -------------"
26+
git config --list
27+
28+
echo "---------- git config --list --show-origin -------------"
29+
git config --list --show-origin

src/model/build-parameters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class BuildParameters {
4242

4343
public customParameters!: string;
4444
public sshAgent!: string;
45+
public sshPublicKeysDirectoryPath!: string;
4546
public providerStrategy!: string;
4647
public gitPrivateToken!: string;
4748
public awsStackName!: string;
@@ -150,6 +151,7 @@ class BuildParameters {
150151
androidSymbolType: androidSymbolExportType,
151152
customParameters: Input.customParameters,
152153
sshAgent: Input.sshAgent,
154+
sshPublicKeysDirectoryPath: Input.sshPublicKeysDirectoryPath,
153155
gitPrivateToken: Input.gitPrivateToken || (await GithubCliReader.GetGitHubAuthToken()),
154156
chownFilesTo: Input.chownFilesTo,
155157
providerStrategy: CloudRunnerOptions.providerStrategy,

src/model/docker.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,15 @@ class Docker {
4040
additionalVariables: StringKeyValuePair[] = [],
4141
entrypointBash: boolean = false,
4242
): string {
43-
const { workspace, actionFolder, runnerTempPath, sshAgent, gitPrivateToken, dockerWorkspacePath } = parameters;
43+
const {
44+
workspace,
45+
actionFolder,
46+
runnerTempPath,
47+
sshAgent,
48+
sshPublicKeysDirectoryPath,
49+
gitPrivateToken,
50+
dockerWorkspacePath,
51+
} = parameters;
4452

4553
const githubHome = path.join(runnerTempPath, '_github_home');
4654
if (!existsSync(githubHome)) mkdirSync(githubHome);
@@ -54,6 +62,7 @@ class Docker {
5462
${ImageEnvironmentFactory.getEnvVarString(parameters, additionalVariables)} \
5563
--env UNITY_SERIAL \
5664
--env GITHUB_WORKSPACE=${dockerWorkspacePath} \
65+
--env GIT_CONFIG_EXTENSIONS \
5766
${gitPrivateToken ? `--env GIT_PRIVATE_TOKEN="${gitPrivateToken}"` : ''} \
5867
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
5968
--volume "${githubHome}":"/root:z" \
@@ -64,7 +73,12 @@ class Docker {
6473
--volume "${actionFolder}/platforms/ubuntu/entrypoint.sh:/entrypoint.sh:z" \
6574
--volume "${actionFolder}/unity-config:/usr/share/unity3d/config/:z" \
6675
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
67-
${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''} \
76+
${
77+
sshAgent && !sshPublicKeysDirectoryPath
78+
? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro'
79+
: ''
80+
} \
81+
${sshPublicKeysDirectoryPath ? `--volume ${sshPublicKeysDirectoryPath}:/root/.ssh:ro` : ''} \
6882
${entrypointBash ? `--entrypoint ${commandPrefix}` : ``} \
6983
${image} \
7084
${entrypointBash ? `-c` : `${commandPrefix} -c`} \

src/model/input.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ class Input {
178178
return Input.getInput('sshAgent') || '';
179179
}
180180

181+
static get sshPublicKeysDirectoryPath(): string {
182+
return Input.getInput('sshPublicKeysDirectoryPath') || '';
183+
}
184+
181185
static get gitPrivateToken(): string | undefined {
182186
return Input.getInput('gitPrivateToken');
183187
}

0 commit comments

Comments
 (0)