Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing "debug" and "environment" keys in runner context #79

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kachick
Copy link

@kachick kachick commented Jun 3, 2024

Fixes #78

  • Add validation test
  • Update completions test
  • Fix them with adding default context

* Add validation test
* Update completions test
* Fix them with adding default context
@@ -78,7 +78,9 @@ function getDefaultContext(name: string, workflowContext: WorkflowContext, mode:
arch: "X64",
name: "GitHub Actions 2",
tool_cache: "/opt/hostedtoolcache",
temp: "/home/runner/work/_temp"
temp: "/home/runner/work/_temp",
debug: "1",
Copy link

@CRC-Mismatch CRC-Mismatch Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Sorry for the false-approval, I misclicked 🥴 )

Shouldn't this be "0" by default? 🤔
My reasoning is that it will only be "1" if a workflow is run with a secret/variable ACTIONS_RUNNER_DEBUG set to true in context1 (or when ticking the "Enable debug logging" checkbox when re-running jobs)...

Footnotes

  1. https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/troubleshooting-workflows/enabling-debug-logging#enabling-runner-diagnostic-logging

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reviewing. 🙏 I referred https://github.com/github/docs/blob/0208d54f08a79b92ba27a010722c87eb327e1c61/data/reusables/actions/runner-debug-description.md?plain=1#L1 for this value, and I understood the debug will be 1 or empty / undefined instead of 0.

I have checked the current ubuntu-24.04 runner behavior in https://github.com/kachick/example-actions-languageservices-78

In normal run

https://github.com/kachick/example-actions-languageservices-78/actions/runs/11745248730/job/32722225773

Run echo "$RUNNER_CONTEXT"
  echo "$RUNNER_CONTEXT"
  shell: /usr/bin/bash -e {0}
  env:
    RUNNER_CONTEXT: {
    "os": "Linux",
    "arch": "X64",
    "name": "GitHub Actions 14",
    "environment": "github-hosted",
    "tool_cache": "/opt/hostedtoolcache",
    "temp": "/home/runner/work/_temp",
    "workspace": "/home/runner/work/example-actions-languageservices-78"
  }
{
  "os": "Linux",
  "arch": "X64",
  "name": "GitHub Actions 14",
  "environment": "github-hosted",
  "tool_cache": "/opt/hostedtoolcache",
  "temp": "/home/runner/work/_temp",
  "workspace": "/home/runner/work/example-actions-languageservices-78"
}

In debug mode

https://github.com/kachick/example-actions-languageservices-78/actions/runs/11745575165/job/32723371875#step:2:6

##[debug]Evaluating: toJson(runner)
##[debug]Evaluating toJson:
##[debug]..Evaluating runner:
##[debug]..=> Object
##[debug]=> '{
##[debug]  "debug": "1",
##[debug]  "os": "Linux",
##[debug]  "arch": "X64",
##[debug]  "name": "GitHub Actions 12",
##[debug]  "environment": "github-hosted",
##[debug]  "tool_cache": "/opt/hostedtoolcache",
##[debug]  "temp": "/home/runner/work/_temp",
##[debug]  "workspace": "/home/runner/work/example-actions-languageservices-78"
##[debug]}'
##[debug]Result: '{
##[debug]  "debug": "1",
##[debug]  "os": "Linux",
##[debug]  "arch": "X64",
##[debug]  "name": "GitHub Actions 12",
##[debug]  "environment": "github-hosted",
##[debug]  "tool_cache": "/opt/hostedtoolcache",
##[debug]  "temp": "/home/runner/work/_temp",
##[debug]  "workspace": "/home/runner/work/example-actions-languageservices-78"
##[debug]}'
##[debug]Evaluating condition for step: 'Dump runner context'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Dump runner context
##[debug]Loading inputs
##[debug]Loading env
Run echo "$RUNNER_CONTEXT"
##[debug]/usr/bin/bash -e /home/runner/work/_temp/9a6f6001-cd7b-41dd-a27f-ebee9cffece7.sh
{
  "debug": "1",
  "os": "Linux",
  "arch": "X64",
  "name": "GitHub Actions 12",
  "environment": "github-hosted",
  "tool_cache": "/opt/hostedtoolcache",
  "temp": "/home/runner/work/_temp",
  "workspace": "/home/runner/work/example-actions-languageservices-78"
}
##[debug]Finishing: Dump runner context

So I still guessing debug should never become 0.

However in this test, ACTIONS_RUNNER_DEBUG in repository secrets/variables setting does not change the injected ENV.
It looks only depend on the run is debug mode or not.

And I'm guessing actual source of truth is written in https://github.com/actions/runner/blob/6ef5803f24724b77a8d3599a478d06018da5d7c6/src/Runner.Worker/JobRunner.cs#L155-L158.

                if (jobContext.Global.WriteDebug)
                {
                    jobContext.SetRunnerContext("debug", "1");
                }

Whichever the default value, In my understanding, these values are not actually used in this extension; only the keys are used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 👍 If on section is not including pull_request, accessing github.event.pull_request.assignee alerts Context access might be invalid: pull_request.
  • 🤔 On the other hand, this runner.debug does not consider whether the runner is actually in debug mode or not.

I have no idea how to realize the polite behavior. 🙇‍♂️

@kachick
Copy link
Author

kachick commented Nov 8, 2024

@elbrenn thank you for updating this PR by merging the main branch. Should I take any further action regarding this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing and raising incorrect error for runner.debug and runner.environment
3 participants