[GH-ISSUE #134] Context unavailable? #91

Closed
opened 2026-03-01 21:40:01 +03:00 by kerem · 13 comments
Owner

Originally created by @jacob-israel-turner on GitHub (Mar 6, 2020).
Original GitHub issue: https://github.com/nektos/act/issues/134

First - wonderful project! I'm tired of pushing hundreds of commits while debugging actions. This will simplify my workflow quite a bit.

One issue I've run into is that the Github context appears to be unavailable within act. Which actually kind of makes sense, given that the actions are not running on Github - but it seems like portions should be easy to shim. Specifically, github.head_ref seems easy to shim in.

Even if this isn't possible, is there a way for me to manually provide the context when calling the action? As a temporary workaround, I moved all references to the github context into the env variables, so it's easy to override when testing locally.

Originally created by @jacob-israel-turner on GitHub (Mar 6, 2020). Original GitHub issue: https://github.com/nektos/act/issues/134 First - wonderful project! I'm tired of pushing hundreds of commits while debugging actions. This will simplify my workflow quite a bit. One issue I've run into is that the [Github context](https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context) appears to be unavailable within act. Which actually kind of makes sense, given that the actions are not running on Github - but it seems like portions should be easy to shim. Specifically, `github.head_ref` seems easy to shim in. Even if this isn't possible, is there a way for me to manually provide the context when calling the action? As a temporary workaround, I moved all references to the github context into the env variables, so it's easy to override when testing locally.
kerem 2026-03-01 21:40:01 +03:00
Author
Owner

@cplee commented on GitHub (Mar 6, 2020):

Much of the GitHub context is implemented, however head_ref and base_ref were skipped because I wasn't sure how to implement it...where would i pull those from?

github.com/nektos/act@4fde7d8865/pkg/runner/run_context.go (L327)

<!-- gh-comment-id:595960747 --> @cplee commented on GitHub (Mar 6, 2020): Much of the GitHub context is implemented, however `head_ref` and `base_ref` were skipped because I wasn't sure how to implement it...where would i pull those from? https://github.com/nektos/act/blob/4fde7d88658ba5755add6926c6d5d1bec0e80db8/pkg/runner/run_context.go#L327
Author
Owner

@jacob-israel-turner commented on GitHub (Mar 6, 2020):

Actually - it appears ALL context is unavailable - trying to pull ${{ env.BRANCH }} after setting the env at the top of the file returns undefined. Am I consuming it incorrectly?

<!-- gh-comment-id:595961018 --> @jacob-israel-turner commented on GitHub (Mar 6, 2020): Actually - it appears ALL context is unavailable - trying to pull `${{ env.BRANCH }}` after setting the env at the top of the file returns undefined. Am I consuming it incorrectly?
Author
Owner

@cplee commented on GitHub (Mar 6, 2020):

env should definitely work...do you have a sample repo you can share?

<!-- gh-comment-id:595961288 --> @cplee commented on GitHub (Mar 6, 2020): env should definitely work...do you have a sample repo you can share?
Author
Owner

@cplee commented on GitHub (Mar 6, 2020):

Actually, i think i should pull those head_ref and base_ref from the event JSON...then you'd just have to provide that file to act

<!-- gh-comment-id:595962677 --> @cplee commented on GitHub (Mar 6, 2020): Actually, i think i should pull those `head_ref` and `base_ref` from the event JSON...then you'd just have to provide that file to act
Author
Owner

@jacob-israel-turner commented on GitHub (Mar 6, 2020):

env should definitely work...do you have a sample repo you can share?

Thanks for the quick response @cplee! I can't share a full repo, but here is essentially what I'm running: https://gist.github.com/jacob-israel-turner/5b90ba7a4aaa6d98044581249e957f69

The Log command prints undefined, and from the behavior of other steps later in the job, it appears that the branch provided to Checkout Branch is undefined as well.

I ran this same file on Github and the branch logs and checks out correctly.

<!-- gh-comment-id:595963032 --> @jacob-israel-turner commented on GitHub (Mar 6, 2020): > env should definitely work...do you have a sample repo you can share? Thanks for the quick response @cplee! I can't share a full repo, but here is essentially what I'm running: https://gist.github.com/jacob-israel-turner/5b90ba7a4aaa6d98044581249e957f69 The Log command prints `undefined`, and from the behavior of other steps later in the job, it appears that the branch provided to Checkout Branch is `undefined` as well. I ran this same file on Github and the branch logs and checks out correctly.
Author
Owner

@jacob-israel-turner commented on GitHub (Mar 6, 2020):

Actually, i think i should pull those head_ref and base_ref from the event JSON...then you'd just have to provide that file to act

That would be awesome - I could provide a JSON event when running act pull_request, for example? If there's documentation around this, I think it's a great solution.

<!-- gh-comment-id:595963422 --> @jacob-israel-turner commented on GitHub (Mar 6, 2020): > Actually, i think i should pull those `head_ref` and `base_ref` from the event JSON...then you'd just have to provide that file to act That would be awesome - I could provide a JSON event when running `act pull_request`, for example? If there's documentation around this, I think it's a great solution.
Author
Owner

@cplee commented on GitHub (Mar 6, 2020):

dang. you're right, env context has a bug. i was able to reproduce locally

<!-- gh-comment-id:595964971 --> @cplee commented on GitHub (Mar 6, 2020): dang. you're right, env context has a bug. i was able to reproduce locally
Author
Owner

@jacob-israel-turner commented on GitHub (Mar 6, 2020):

Cool. Thanks for the quick turnaround - let me know if there's anything I can do to help debug!

Would you prefer me to open a new issue re: github.head_ref and github.base_ref?

<!-- gh-comment-id:595965623 --> @jacob-israel-turner commented on GitHub (Mar 6, 2020): Cool. Thanks for the quick turnaround - let me know if there's anything I can do to help debug! Would you prefer me to open a new issue re: `github.head_ref` and `github.base_ref`?
Author
Owner

@cplee commented on GitHub (Mar 6, 2020):

nah, will squash both 🐛

<!-- gh-comment-id:595970470 --> @cplee commented on GitHub (Mar 6, 2020): nah, will squash both 🐛
Author
Owner

@cplee commented on GitHub (Mar 6, 2020):

fixed on master. will include in next release.

<!-- gh-comment-id:595988914 --> @cplee commented on GitHub (Mar 6, 2020): fixed on master. will include in next release.
Author
Owner

@jacob-israel-turner commented on GitHub (Mar 6, 2020):

Thanks a ton man! Will there be documentation around how to provide an event.json to act? From reading the code, it looks like just having an event.json file in the working directory might do it. If that's the case, I'm happy to add to the README.

<!-- gh-comment-id:595990361 --> @jacob-israel-turner commented on GitHub (Mar 6, 2020): Thanks a ton man! Will there be documentation around how to provide an `event.json` to `act`? From reading the code, it looks like just having an `event.json` file in the working directory might do it. If that's the case, I'm happy to add to the README.
Author
Owner

@cplee commented on GitHub (Mar 6, 2020):

act -h shows the options...to specify an event file use:

act -e my-event.json

would love help with README 🙏

<!-- gh-comment-id:595990930 --> @cplee commented on GitHub (Mar 6, 2020): `act -h` shows the options...to specify an event file use: `act -e my-event.json` would love help with README 🙏
Author
Owner

@jacob-israel-turner commented on GitHub (Mar 7, 2020):

Just opened two PR's - let me know if you want any changes!

https://github.com/nektos/act/pulls/jacob-israel-turner

<!-- gh-comment-id:596021897 --> @jacob-israel-turner commented on GitHub (Mar 7, 2020): Just opened two PR's - let me know if you want any changes! https://github.com/nektos/act/pulls/jacob-israel-turner
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/act#91
No description provided.