how does generation of environment variables, event payloads and various contexts work? #2642
Replies: 2 comments
|
act combines static defaults, local repository data, CLI inputs, and the event JSON; it does not attempt to synthesize a byte-for-byte GitHub webhook for every event. At a high level:
The GitHub context is assembled in pkg/model/github_context.go, while the runner reads the supplied event file and copies it into the job as workflow/event.json. For testing an action, do not recreate all possible contexts yourself. Create minimal webhook fixtures for the events your action supports, inject secrets/vars explicitly, and assert only fields in GitHub's documented event schema. When your code calls the live REST API, either use a real test repository/token or mock that boundary—an event fixture cannot create the referenced issue/PR/release in GitHub. Yes, act must evolve when GitHub adds semantics that affect emulation, but most new event fields need no act code change: they pass through transparently from event.json. Code changes are needed for derived context values, runner behavior, expressions, commands, services, and other execution semantics. |
|
Roughly, yes — it's assembled from scratch. In my reading the flow is:
For your test you could just reuse act: — |
Uh oh!
There was an error while loading. Please reload this page.
I want to write a test for my GitHub action, which I want to be able to run locally, for that I need make env vars, payloads and context available. That reminded me of act, because you must have solved this problem in order to run arbitrary workflows. I looked into the code and found https://github.com/nektos/act/blob/master/pkg/model/github_context.go.
Does it mean you just generate from scratch and have to update every time GitHub adds new things to it?
All reactions