Use the PR author's name as an environment in github workflow

Viewed 862

There are several people working on the same repository and all of them have AWS accounts. For each person our repo has github environment created with person's AWS SECRETS. Is there way to dynamically get PR's author name and use it as environments name for the workflow ?Given that each github environment has the same name as the contributors.

jobs:
  job_name:
    environment: PR_AUTHORS_NAME_HERE
2 Answers

I got the needed solution by using github expressions:

jobs:
  build:
    environment: ${{ github.actor }}_environment
    runs-on: ubuntu-latest

You can get the pull request author with {{ github.event.pull_request.user.login }}.

You can use it like the following:

jobs:
  test:
    runs-on: ubuntu-latest
    env:
      PR_AUTHOR: ${{ github.event.pull_request.user.login }}
    steps:
      - name: script
        run: |
          echo "PR author: $PR_AUTHOR"
        shell: bash
Related