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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion languageservice/src/complete.expressions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ jobs:
"on: push\njobs:\n build:\n runs-on: ubuntu-latest\n environment:\n url: ${{ runner.| }}\n steps:\n - run: echo";
const result = await complete(...getPositionFromCursor(input), {contextProviderConfig});

expect(result.map(x => x.label)).toEqual(["arch", "name", "os", "temp", "tool_cache"]);
expect(result.map(x => x.label)).toEqual(["arch", "debug", "environment", "name", "os", "temp", "tool_cache"]);
});

describe("job if", () => {
Expand Down
4 changes: 3 additions & 1 deletion languageservice/src/context-providers/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. 🙇‍♂️

environment: "github-hosted"
});

case "secrets":
Expand Down
36 changes: 36 additions & 0 deletions languageservice/src/validate.expressions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1505,4 +1505,40 @@ jobs:
expect(result).toEqual([]);
});
});

describe("runner context", () => {
it("includes only expected keys", async () => {
const input = `
on: push

jobs:
test:
runs-on: ubuntu-latest
steps:
- run: echo \${{ runner.tool_cache }}
- run: echo \${{ runner.debug }}
- run: echo \${{ runner.environment }}
- run: echo \${{ runner.does-not-exist }}
`;

const result = await validate(createDocument("wf.yaml", input));

expect(result).toEqual([
{
message: "Context access might be invalid: does-not-exist",
range: {
end: {
character: 46,
line: 10
},
start: {
character: 18,
line: 10
}
},
severity: DiagnosticSeverity.Warning
}
]);
});
});
});
Loading