GitHub actions var in repo (script python)

Hi,

I request your collaboration, I have a python script which consumes the GitHub API to give access to people in the organization, repositories, create organizations etc … I would like to automate this with Github actions. I have been reading docuemtanción about workflow_dispatch, but I don’t know how to make my python code receive the variables that I enter in github actions, I don’t know if this is possible.

I remain attentive and thank you very much.

There’s an example in the documentation on how to use inputs in a workflow. The workflow then needs to provide those when calling the script, either on the command line or as environment variables.

Modified version of the linked example, using an environment variable:

name: Manually triggered workflow
on:
  workflow_dispatch:
    inputs:
      name:
        description: 'Person to greet'
        required: true
        default: 'Mona the Octocat'

jobs:
  run_script:
    runs-on: ubuntu-latest
    steps:
      - run: script.py
        env:
          NAME: '${{ github.event.inputs.name }}'

The Python script can then access os.environ['NAME'].