mirror of
https://github.com/actions/runner-container-hooks.git
synced 2026-01-09 19:43:24 +08:00
Compare commits
7 Commits
copilot/su
...
55d6468aad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55d6468aad | ||
|
|
8ffe11eaac | ||
|
|
170b03ac01 | ||
|
|
bed5615e7b | ||
|
|
fdf0659b76 | ||
|
|
9da01d74f1 | ||
|
|
4b388a89bb |
@@ -23,25 +23,52 @@ export async function runScriptStep(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const workdir = dirname(process.env.RUNNER_WORKSPACE as string)
|
const workdir = dirname(process.env.RUNNER_WORKSPACE as string)
|
||||||
const containerTemp = '/__w/_temp'
|
|
||||||
const runnerTemp = `${workdir}/_temp`
|
const runnerTemp = `${workdir}/_temp`
|
||||||
await execCpToPod(state.jobPod, runnerTemp, containerTemp)
|
const containerTemp = '/__w/_temp'
|
||||||
|
const containerTempSrc = '/__w/_temp_pre'
|
||||||
// Copy GitHub directories from temp to /github
|
// Ensure base and staging dirs exist before copying
|
||||||
const setupCommands = [
|
|
||||||
'mkdir -p /github',
|
|
||||||
'cp -r /__w/_temp/_github_home /github/home',
|
|
||||||
'cp -r /__w/_temp/_github_workflow /github/workflow'
|
|
||||||
]
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await execPodStep(
|
await execPodStep(
|
||||||
['sh', '-c', shlex.quote(setupCommands.join(' && '))],
|
[
|
||||||
|
'sh',
|
||||||
|
'-c',
|
||||||
|
'mkdir -p /__w && mkdir -p /__w/_temp && mkdir -p /__w/_temp_pre'
|
||||||
|
],
|
||||||
state.jobPod,
|
state.jobPod,
|
||||||
JOB_CONTAINER_NAME
|
JOB_CONTAINER_NAME
|
||||||
)
|
)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
core.debug(`Failed to copy GitHub directories: ${JSON.stringify(err)}`)
|
core.debug(
|
||||||
|
`Failed to create temp dirs in container: ${JSON.stringify(err)}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
await execCpToPod(state.jobPod, runnerTemp, containerTempSrc)
|
||||||
|
|
||||||
|
// Copy GitHub directories from temp to /github
|
||||||
|
// Merge strategy:
|
||||||
|
// - Overwrite files in _runner_file_commands
|
||||||
|
// - Append files not already present elsewhere
|
||||||
|
const mergeCommands = [
|
||||||
|
'set -e',
|
||||||
|
'mkdir -p /__w/_temp /__w/_temp_pre',
|
||||||
|
'SRC=/__w/_temp_pre',
|
||||||
|
'DST=/__w/_temp',
|
||||||
|
// Overwrite _runner_file_commands
|
||||||
|
'[ -d "$SRC/_runner_file_commands" ] && mkdir -p "$DST/_runner_file_commands" && cp -a "$SRC/_runner_file_commands/." "$DST/_runner_file_commands/" || true',
|
||||||
|
// Append other files if missing
|
||||||
|
'find "$SRC" -type f ! -path "*/_runner_file_commands/*" | while read -r f; do rel=${f#"$SRC/"}; target="$DST/$rel"; dir=$(dirname "$target"); if [ ! -e "$target" ]; then mkdir -p "$dir"; cp -a "$f" "$target"; fi; done'
|
||||||
|
]
|
||||||
|
|
||||||
|
try {
|
||||||
|
await execPodStep(
|
||||||
|
['sh', '-c', mergeCommands.join(' && ')],
|
||||||
|
state.jobPod,
|
||||||
|
JOB_CONTAINER_NAME
|
||||||
|
)
|
||||||
|
} catch (err) {
|
||||||
|
core.debug(`Failed to merge temp directories: ${JSON.stringify(err)}`)
|
||||||
|
const message = (err as any)?.response?.body?.message || err
|
||||||
|
throw new Error(`failed to merge temp dirs: ${message}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the entrypoint script
|
// Execute the entrypoint script
|
||||||
@@ -69,7 +96,11 @@ export async function runScriptStep(
|
|||||||
core.debug(
|
core.debug(
|
||||||
`Copying from job pod '${state.jobPod}' ${containerTemp} to ${runnerTemp}`
|
`Copying from job pod '${state.jobPod}' ${containerTemp} to ${runnerTemp}`
|
||||||
)
|
)
|
||||||
await execCpFromPod(state.jobPod, containerTemp, workdir)
|
await execCpFromPod(
|
||||||
|
state.jobPod,
|
||||||
|
`${containerTemp}/_runner_file_commands`,
|
||||||
|
`${workdir}/_temp`
|
||||||
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.warning('Failed to copy _temp from pod')
|
core.warning('Failed to copy _temp from pod')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -831,7 +831,7 @@ export async function isPodContainerAlpine(
|
|||||||
[
|
[
|
||||||
'sh',
|
'sh',
|
||||||
'-c',
|
'-c',
|
||||||
`'[ $(cat /etc/*release* | grep -i -e "^ID=*alpine*" -c) != 0 ] || exit 1'`
|
`[ $(cat /etc/*release* | grep -i -e "^ID=*alpine*" -c) != 0 ] || exit 1`
|
||||||
],
|
],
|
||||||
podName,
|
podName,
|
||||||
containerName
|
containerName
|
||||||
|
|||||||
@@ -288,6 +288,11 @@ function mergeLists<T>(base?: T[], from?: T[]): T[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function fixArgs(args: string[]): string[] {
|
export function fixArgs(args: string[]): string[] {
|
||||||
|
// Preserve shell command strings passed via `sh -c` without re-tokenizing.
|
||||||
|
// Retokenizing would split the script into multiple args, breaking `sh -c`.
|
||||||
|
if (args.length >= 2 && args[0] === 'sh' && args[1] === '-c') {
|
||||||
|
return args
|
||||||
|
}
|
||||||
return shlex.split(args.join(' '))
|
return shlex.split(args.join(' '))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ describe('Prepare job', () => {
|
|||||||
process.env.GITHUB_WORKSPACE as string,
|
process.env.GITHUB_WORKSPACE as string,
|
||||||
'myvolume'
|
'myvolume'
|
||||||
)
|
)
|
||||||
fs.mkdirSync(userVolumeMount)
|
fs.mkdirSync(userVolumeMount, { recursive: true })
|
||||||
fs.writeFileSync(path.join(userVolumeMount, 'file.txt'), 'hello')
|
fs.writeFileSync(path.join(userVolumeMount, 'file.txt'), 'hello')
|
||||||
prepareJobData.args.container.userMountVolumes = [
|
prepareJobData.args.container.userMountVolumes = [
|
||||||
{
|
{
|
||||||
@@ -63,11 +63,7 @@ describe('Prepare job', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
await execPodStep(
|
await execPodStep(
|
||||||
[
|
['sh', '-c', '[ "$(cat /__w/myvolume/file.txt)" = "hello" ] || exit 5'],
|
||||||
'sh',
|
|
||||||
'-c',
|
|
||||||
'\'[ "$(cat /__w/myvolume/file.txt)" = "hello" ] || exit 5\''
|
|
||||||
],
|
|
||||||
content!.state!.jobPod,
|
content!.state!.jobPod,
|
||||||
JOB_CONTAINER_NAME
|
JOB_CONTAINER_NAME
|
||||||
).then(output => {
|
).then(output => {
|
||||||
|
|||||||
Reference in New Issue
Block a user