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

ACTIONS_RUNTIME_URL / ACTIONS_RUNTIME_TOKEN and friends aren't documented #28

Open
jsoref opened this issue Sep 10, 2024 · 5 comments · May be fixed by #37
Open

ACTIONS_RUNTIME_URL / ACTIONS_RUNTIME_TOKEN and friends aren't documented #28

jsoref opened this issue Sep 10, 2024 · 5 comments · May be fixed by #37

Comments

@jsoref
Copy link

jsoref commented Sep 10, 2024

I'd love to at least know how to pass the GitHub hosted variables to act so that I can perform passthrough action stuffs.

I tried that here:
https://github.com/check-spelling-sandbox/act-use-spell-check-this/actions/runs/10801275723/workflow#L95-L96

But that clearly didn't work as seen in:
https://github.com/check-spelling-sandbox/act-use-spell-check-this/actions/runs/10801275723/job/29961096172#step:11:9536

[Test/Standalone                     ]   ❗  ::error::Unable to get the ACTIONS_RUNTIME_TOKEN env variable
@ChristopherHX
Copy link
Contributor

You didn't know about actions/runner ACTIONS_RUNTIME_URL and ACTIONS_RUNTIME_TOKEN are not set in steps with run key and only have a value in nodejs&docker actions?

Now, why is act different here?, that's a different topic.

@jsoref
Copy link
Author

jsoref commented Sep 11, 2024

Err. So, do I need to do something like:

act --env MY_ACTIONS_RUNTIME_URL="$ACTIONS_RUNTIME_URL" --env MY_ACTIONS_RUNTIME_TOKEN="$ACTIONS_RUNTIME_TOKEN"

and then:

steps:
 ...
 - name: use actions runtime stuff
   env:
     ACTIONS_RUNTIME_URL: ${{ env.MY_ACTIONS_RUNTIME_URL }}
     ACTIONS_RUNTIME_TOKEN: ${{ env.MY_ACTIONS_RUNTIME_TOKEN }}
   ...

@jsoref
Copy link
Author

jsoref commented Sep 11, 2024

Note: All I want is docs explaining how I, an "end user", can make this work. That's why this is in the docs repo and not in the act repo with a subject of "act is doing this wrong".

@ChristopherHX
Copy link
Contributor

I'm probably too far away from an "end user", here a technical instruction to do it.
Someone need to write a "end user" friendly alternative

  1. ACTIONS_RUNTIME_URL and ACTIONS_RUNTIME_TOKEN are not available in run steps like inline scripts for GitHub Hosted Runners
  2. To expose them use an action like actions/github-script
    • where I usually set input github-token to none when I don't need octokit
    • the script parameter can export the value via core.setOutput('ACTIONS_RUNTIME_URL', process.env.ACTIONS_RUNTIME_URL); and do the same for the other env as well
  3. assign the output to the --env flag of act in the run script
  4. I don't like overrides of step 3
    • because that's a behavior defect compared to GitHub Actions, where it is impossible to override them via env within workflow
    • a new cli flag to override protected env variables (yes I made GITHUB_OUTPUT protected in act like on GitHub Hosted runners, because my github-act-runner should be somewhat trustworthy) is more prefered in my opinon

Err. So, do I need to do something like:

act --env MY_ACTIONS_RUNTIME_URL="$ACTIONS_RUNTIME_URL" --env MY_ACTIONS_RUNTIME_TOKEN="$ACTIONS_RUNTIME_TOKEN"

and then:

steps:
 ...
 - name: use actions runtime stuff
   env:
     ACTIONS_RUNTIME_URL: ${{ env.MY_ACTIONS_RUNTIME_URL }}
     ACTIONS_RUNTIME_TOKEN: ${{ env.MY_ACTIONS_RUNTIME_TOKEN }}
   ...

Err 500, did you try to diagnose this with act in act?

act in Runner.Server is a possible combo to diagnose the missing var, because act and actions/runner do have a lot of different behavior.

@jsoref
Copy link
Author

jsoref commented Sep 11, 2024

I guess I'm running act in Runner.Server.

With your suggestion, it works!
https://github.com/check-spelling-sandbox/act-use-spell-check-this/actions/runs/10819571929

Running nektos/act inside GitHub runners (Runner.Server) and allowing access to the GitHub Artifact APIs:

Two steps are recommended, one to get the variables (which must not be a run: step) and one to use them.

For example:

    steps:
      # ... any steps necessary to set up act ...
      - name: get actions environment variables
        uses: actions/github-script@v7
        id: action-variables
        with:
          script: |
            core.setOutput('ACTIONS_RESULTS_URL', process.env.ACTIONS_RESULTS_URL);
            core.setOutput('ACTIONS_RUNTIME_URL', process.env.ACTIONS_RUNTIME_URL);
            core.setOutput('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN);
      - name: run act
        env:
          GH_TOKEN: ${{ github.token }}
          MY_ACTIONS_RESULTS_URL: ${{ steps.action-variables.outputs.ACTIONS_RESULTS_URL }}
          MY_ACTIONS_RUNTIME_URL: ${{ steps.action-variables.outputs.ACTIONS_RUNTIME_URL }}
          MY_ACTIONS_RUNTIME_TOKEN: ${{ steps.action-variables.outputs.ACTIONS_RUNTIME_TOKEN }}
        run: |
            act \
            -s GH_TOKEN="$GH_TOKEN" \
            --env ACTIONS_RESULTS_URL="$MY_ACTIONS_RESULTS_URL" \
            --env ACTIONS_RUNTIME_URL="$MY_ACTIONS_RUNTIME_URL" \
            --env ACTIONS_RUNTIME_TOKEN="$MY_ACTIONS_RUNTIME_TOKEN" \

@ChristopherHX ChristopherHX linked a pull request Nov 30, 2024 that will close this issue
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 a pull request may close this issue.

2 participants