Skip to content

Commit 275df98

Browse files
authored
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)
1 parent 9d0bc62 commit 275df98

File tree

8 files changed

+1258
-1174
lines changed

8 files changed

+1258
-1174
lines changed

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ inputs:
3636
required: false
3737
default: ''
3838
description: 'SSH Agent path to forward to the container.'
39+
sshPublicKeysDirectoryPath:
40+
required: false
41+
default: ''
42+
description: 'Path to a directory containing SSH public keys to forward to the container.'
3943
gitPrivateToken:
4044
required: false
4145
default: ''

dist/entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ mkdir -p "$ACTIVATE_LICENSE_PATH"
1212
#
1313

1414
source /steps/activate.sh
15+
source /steps/set_extra_git_configs.sh
1516
source /steps/set_gitcredential.sh
1617
source /steps/run_tests.sh
1718
source /steps/return_license.sh

dist/index.js

Lines changed: 1192 additions & 1172 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.
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/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export async function run() {
1616
artifactsPath,
1717
useHostNetwork,
1818
sshAgent,
19+
sshPublicKeysDirectoryPath,
1920
gitPrivateToken,
2021
githubToken,
2122
checkName,
@@ -39,6 +40,7 @@ export async function run() {
3940
artifactsPath,
4041
useHostNetwork,
4142
sshAgent,
43+
sshPublicKeysDirectoryPath,
4244
packageMode,
4345
packageName,
4446
gitPrivateToken,

src/model/docker.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const Docker = {
6262
artifactsPath,
6363
useHostNetwork,
6464
sshAgent,
65+
sshPublicKeysDirectoryPath,
6566
packageMode,
6667
packageName,
6768
gitPrivateToken,
@@ -116,6 +117,7 @@ const Docker = {
116117
--env RUNNER_WORKSPACE \
117118
--env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \
118119
--env CHOWN_FILES_TO="${chownFilesTo}" \
120+
--env GIT_CONFIG_EXTENSIONS \
119121
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
120122
--volume "${githubHome}:/root:z" \
121123
--volume "${githubWorkflow}:/github/workflow:z" \
@@ -126,7 +128,14 @@ const Docker = {
126128
--volume "${actionFolder}/unity-config:/usr/share/unity3d/config/:z" \
127129
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
128130
${
129-
sshAgent ? `--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro` : ''
131+
sshAgent && !sshPublicKeysDirectoryPath
132+
? `--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro`
133+
: ''
134+
} \
135+
${
136+
sshPublicKeysDirectoryPath
137+
? `--volume ${sshPublicKeysDirectoryPath}:/root/.ssh:ro`
138+
: ''
130139
} \
131140
${useHostNetwork ? '--net=host' : ''} \
132141
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \

src/model/input.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ const Input = {
1313
return validFolderName.test(folderName);
1414
},
1515

16+
isValidGlobalFolderName(folderName) {
17+
const validFolderName = new RegExp(/^(\.|\.\/|\/)?(\.?[\w~]+([ _-]?[\w~]+)*\/?)*$/);
18+
19+
return validFolderName.test(folderName);
20+
},
21+
1622
/**
1723
* When in package mode, we need to scrape the package's name from its package.json file
1824
*/
@@ -72,6 +78,7 @@ const Input = {
7278
const rawArtifactsPath = getInput('artifactsPath') || 'artifacts';
7379
const rawUseHostNetwork = getInput('useHostNetwork') || 'false';
7480
const sshAgent = getInput('sshAgent') || '';
81+
const rawSshPublicKeysDirectoryPath = getInput('sshPublicKeysDirectoryPath') || '';
7582
const gitPrivateToken = getInput('gitPrivateToken') || '';
7683
const githubToken = getInput('githubToken') || '';
7784
const checkName = getInput('checkName') || 'Test Results';
@@ -92,6 +99,10 @@ const Input = {
9299
throw new Error(`Invalid artifactsPath "${rawArtifactsPath}"`);
93100
}
94101

102+
if (!this.isValidGlobalFolderName(rawSshPublicKeysDirectoryPath)) {
103+
throw new Error(`Invalid sshPublicKeysDirectoryPath "${rawSshPublicKeysDirectoryPath}"`);
104+
}
105+
95106
if (rawUseHostNetwork !== 'true' && rawUseHostNetwork !== 'false') {
96107
throw new Error(`Invalid useHostNetwork "${rawUseHostNetwork}"`);
97108
}
@@ -100,6 +111,12 @@ const Input = {
100111
throw new Error(`Invalid packageMode "${rawPackageMode}"`);
101112
}
102113

114+
if (rawSshPublicKeysDirectoryPath !== '' && sshAgent === '') {
115+
throw new Error(
116+
'sshPublicKeysDirectoryPath is set, but sshAgent is not set. sshPublicKeysDirectoryPath is useful only when using sshAgent.',
117+
);
118+
}
119+
103120
// sanitize packageMode input and projectPath input since they are needed
104121
// for input validation
105122
const packageMode = rawPackageMode === 'true';
@@ -119,6 +136,7 @@ const Input = {
119136

120137
// Sanitise other input
121138
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
139+
const sshPublicKeysDirectoryPath = rawSshPublicKeysDirectoryPath.replace(/\/$/, '');
122140
const useHostNetwork = rawUseHostNetwork === 'true';
123141
const editorVersion =
124142
unityVersion === 'auto' ? UnityVersionParser.read(projectPath) : unityVersion;
@@ -134,6 +152,7 @@ const Input = {
134152
artifactsPath,
135153
useHostNetwork,
136154
sshAgent,
155+
sshPublicKeysDirectoryPath,
137156
gitPrivateToken,
138157
githubToken,
139158
checkName,

0 commit comments

Comments
 (0)