Skip to content

Commit

Permalink
Disable interpolation of HEREDOC strings containing hook scripts
Browse files Browse the repository at this point in the history
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)
```
  • Loading branch information
Peter-Sh committed Jan 2, 2025
1 parent fbac69a commit d72ac8f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/multi-runner/templates/user-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions modules/runners/templates/user-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d72ac8f

Please sign in to comment.