Pass github action environmental variables to python

Viewed 160

On my CircleCI's config.yml file, someone wrote a shell post (ie):

curl -X POST -H 'Header: header' \
  --url https://website/${{secrets.SECRET_TOKEN}} \
  --data '{"text": "Hello ${{ github.actor }}"}'

I have to replicate the same behavior using python and requests (this file will be executed by CI). I don't understand how to handle those variables--because they are not CI's env vars, instead they are github action environmental variables.

url = "https://website/${secrets.ROBBY_SLACK_ALERT_TOKEN_CODE_REVIEWS}"
data = {"text": Hello ${github_actor}
f = requests.post(url, headers=headers, json=data)

note: I left the header out in the example above.

I could pass the github var to a ci var, and then retrieve it with python--but not sure the proper syntax to use in the config.yml (ie):

 - env: ENVIRONMENT_VARIABLE_NAME: ${{ secrets.SECRET_TOKEN }}

Any help would be welcome.

Thx

1 Answers

The last option would be fine, some are defined for every workflow run, see here for the list.

These are automatically populated by GitHub during every run.

After that you can read them in a standard python way:

import os

actor = os.environ[”GITHUB_ACTOR”]
Related