From 951c10435b204734275a43c607addd3e949f43b6 Mon Sep 17 00:00:00 2001 From: Petar Shtuchkin Date: Thu, 2 Jan 2025 17:23:12 +0200 Subject: [PATCH] fix: Disable interpolation of HEREDOC strings containing hook scripts Interpolation was applied within the user-data.sh context, causing unexpected empty values for variables and other unintentend effects. While this behavior might be useful in certain cases, it requires consistently escaping everything in hook scripts. This approach feels error-prone and unintuitive. For example, the following configuration will echo an empty string and the date of string interpolation, but not the date of the job's start: ``` runner_hook_job_started: | echo $GITHUB_WORKSPACE echo $(date) ``` --- examples/multi-runner/templates/user-data.sh | 4 ++-- modules/runners/templates/user-data.sh | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/multi-runner/templates/user-data.sh b/examples/multi-runner/templates/user-data.sh index 2d9a605362..793d72dfd2 100644 --- a/examples/multi-runner/templates/user-data.sh +++ b/examples/multi-runner/templates/user-data.sh @@ -82,14 +82,14 @@ ${post_install} cd /opt/actions-runner %{ if hook_job_started != "" } -cat > /opt/actions-runner/hook_job_started.sh << EOF +cat > /opt/actions-runner/hook_job_started.sh <<'EOF' ${hook_job_started} EOF echo ACTIONS_RUNNER_HOOK_JOB_STARTED=/opt/actions-runner/hook_job_started.sh | tee -a /opt/actions-runner/.env %{ endif } %{ if hook_job_completed != "" } -cat > /opt/actions-runner/hook_job_completed.sh << EOF +cat > /opt/actions-runner/hook_job_completed.sh <<'EOF' ${hook_job_completed} EOF echo ACTIONS_RUNNER_HOOK_JOB_COMPLETED=/opt/actions-runner/hook_job_completed.sh | tee -a /opt/actions-runner/.env diff --git a/modules/runners/templates/user-data.sh b/modules/runners/templates/user-data.sh index 321cbc4e02..ca69f26d34 100644 --- a/modules/runners/templates/user-data.sh +++ b/modules/runners/templates/user-data.sh @@ -63,16 +63,16 @@ ${install_runner} ${post_install} # Register runner job hooks -# Ref: https://github.com/actions/runner/blob/main/docs/adrs/1751-runner-job-hooks.md +# Ref: https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/running-scripts-before-or-after-a-job %{ if hook_job_started != "" } -cat > /opt/actions-runner/hook_job_started.sh << EOF +cat > /opt/actions-runner/hook_job_started.sh <<'EOF' ${hook_job_started} EOF echo ACTIONS_RUNNER_HOOK_JOB_STARTED=/opt/actions-runner/hook_job_started.sh | tee -a /opt/actions-runner/.env %{ endif } %{ if hook_job_completed != "" } -cat > /opt/actions-runner/hook_job_completed.sh << EOF +cat > /opt/actions-runner/hook_job_completed.sh <<'EOF' ${hook_job_completed} EOF echo ACTIONS_RUNNER_HOOK_JOB_COMPLETED=/opt/actions-runner/hook_job_completed.sh | tee -a /opt/actions-runner/.env