Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 2622589

Browse files
Peter-Shnpalm
andauthored
fix: Disable interpolation of HEREDOC strings containing runner hook scripts (#4333)
Interpolation was applied within the user-data.sh context, causing unexpected empty values for variables and other unintended 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) ``` This PR disables interpolation of the hook script contents when they are being written to the file. Also the link in user-data.sh to GitHub start/completed docs has been updated. Co-authored-by: Niek Palm <[email protected]>
1 parent bb7346b commit 2622589

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

examples/multi-runner/templates/user-data.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ ${post_install}
8282
cd /opt/actions-runner
8383

8484
%{ if hook_job_started != "" }
85-
cat > /opt/actions-runner/hook_job_started.sh << EOF
85+
cat > /opt/actions-runner/hook_job_started.sh <<'EOF'
8686
${hook_job_started}
8787
EOF
8888
echo ACTIONS_RUNNER_HOOK_JOB_STARTED=/opt/actions-runner/hook_job_started.sh | tee -a /opt/actions-runner/.env
8989
%{ endif }
9090

9191
%{ if hook_job_completed != "" }
92-
cat > /opt/actions-runner/hook_job_completed.sh << EOF
92+
cat > /opt/actions-runner/hook_job_completed.sh <<'EOF'
9393
${hook_job_completed}
9494
EOF
9595
echo ACTIONS_RUNNER_HOOK_JOB_COMPLETED=/opt/actions-runner/hook_job_completed.sh | tee -a /opt/actions-runner/.env

modules/runners/templates/user-data.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ ${install_runner}
6363
${post_install}
6464

6565
# Register runner job hooks
66-
# Ref: https://github.com/actions/runner/blob/main/docs/adrs/1751-runner-job-hooks.md
66+
# Ref: https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/running-scripts-before-or-after-a-job
6767
%{ if hook_job_started != "" }
68-
cat > /opt/actions-runner/hook_job_started.sh << EOF
68+
cat > /opt/actions-runner/hook_job_started.sh <<'EOF'
6969
${hook_job_started}
7070
EOF
7171
echo ACTIONS_RUNNER_HOOK_JOB_STARTED=/opt/actions-runner/hook_job_started.sh | tee -a /opt/actions-runner/.env
7272
%{ endif }
7373

7474
%{ if hook_job_completed != "" }
75-
cat > /opt/actions-runner/hook_job_completed.sh << EOF
75+
cat > /opt/actions-runner/hook_job_completed.sh <<'EOF'
7676
${hook_job_completed}
7777
EOF
7878
echo ACTIONS_RUNNER_HOOK_JOB_COMPLETED=/opt/actions-runner/hook_job_completed.sh | tee -a /opt/actions-runner/.env

0 commit comments

Comments
 (0)